Combine or average multiple lines/edges into single line in image

I have extracted from a series of images their edges using magick in R. Individual results look as follows:

individual edges

What I am trying to do, is combine similar lines, into a single line. For example, the first two lines are fairly similar in the region that they encompase, and one could take something like 'the average' between both. There are also some clear similarities between the third and fourth image. I have hundreds of these.

If I just add all images together (simply summing the matrices that represent them), I get a lot of clutter:

combined edges

But I can still make out some regions.

Ideally, I am looking for a solution with R.

Edit:

Goal. So, what I have here are the results from some spatial models based on the lat and lon of some populations. I have hundreds of binary features for some 90 places. I fitted a 2 dimensional GP for each feature, and the calculated the predictions for a grid of points covering a square area encompassing all points. The goal is to find general dividing lines that separate groups of points. This is what the original predictions look like:

enter image description here

Edit 2:

Here are some matrices in rds format:

Original GP predictions: https://drive.google.com/file/d/1785BBcGKZ2TMLBKbcXKLlcrLue_VJl0O/view?usp=sharing

Extracted edges: https://drive.google.com/file/d/1OUQy6rsP5Mxmf18TXwvoZ8O7MS7Hom3t/view?usp=sharing

Upvotes: 2

Views: 284

Answers (1)

Merijn van Tilborg
Merijn van Tilborg

Reputation: 5897

It is I think all on how you define clutter and what you expect to see.

Lets make some very small example of "image" matrixes having 2 "colors"

m1 <- matrix(c(1, 1, 1, 0, 0, 0, 1, 0, 1), 3, 3)
m2 <- t(apply(m1, 2, rev))
m3 <- t(apply(m2, 2, rev))

Let us see how they look like

image(m1)

enter image description here

image(m2)

enter image description here

image(m3)

enter image description here

Then it is the call you have to make on what you define clutter or not, but let us add up the values in the matrices

all <- m1+m2+m3

image(all)

enter image description here

We see now 3 colors, darkest was present in all images (most images) and lightest color in none of the images (least images).

To remove noise it would be a matter of setting matrix values below a certain threshold to zero to remove the clutter and if you prefer you could convert it (based on thresholds) back to a binary matrix

Upvotes: 0

Related Questions