Ask Your Question
1

Join floating white pixels to the nearest island without closing morph?

asked 2020-07-25 19:34:35 -0600

sn4k3 gravatar image

updated 2020-07-25 19:38:56 -0600

Currently using Closing to gap closing and merging floating pixels to the nearest island, the problem is with tiny details which are required to stay immutable closing will alter the image and merge tiny details. The optimal solution is to detect the pixels that need to be joined and join pixels to the nearest island using a arm to merge both, no matter the distance or better giving a distance limit in pixels.

There are any easy solution to this problem?

As example the following picture (black and white) shows the problem, the red circles shows what i want to merge, currently i'm able to detect those isolated pixels and i have the ROI rectangle of them, so can i do any kind of ROI join or something that doesn't perform a closing on whole image?

sample

The result of image if i perform a closing with 2 iterations: (Note that image have a huge zoom, spacing is really low)

closing

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2020-07-26 05:30:23 -0600

kpachinger gravatar image

I had a specific use case like this. Creating functions which limit all potential options the desired outcome was my solution. In this case I restricted search area to inner circle mask. This was in order to restrict the search area. Then I computed contour distances and sorted ASC. Array is faster when you get it first, not last. Hope that helps!

edit flag offensive delete link more

Comments

I will try your way, seens the way to go

sn4k3 gravatar imagesn4k3 ( 2020-07-27 00:01:47 -0600 )edit
1

answered 2020-07-27 10:27:24 -0600

kbarni gravatar image

Run the ConnectedComponentsWithStats function on the image. Get the smallest surfaces, as zones to merge.

Then, for each black pixel: check its neighbors (on the connected components image); if it contains a component to merge AND another component, then set it to white.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-07-25 19:34:35 -0600

Seen: 784 times

Last updated: Jul 27 '20