質問

Consider that I have a colored image like this in which the outline is not complete (There are gaps between lines). I want to be able to fill the area between the lines with one color or another. This actually is a binary image which I got after applying canny edge detector on a corresponding gray scale image.

I tried first dilating the image and then eroding it, but the result is not good enough. I want to be able to preserve the thickness of the root

Any help would be greatly appreciated

Original Image Original Image

Image after edge detection and some manual removal of pixels Image after edge detection and some manual removal of pixels

Using the information in the edge image, I thought I would try to extract pixels from the original image of a certain color. For every white pixel in the edited image, I used a search space in the original image along the same horizontal line. I used different thresholds for R, G and B and I ended up with this

Using pixel info from original and edited image

役に立ちましたか?

解決 2

I'll add a third approach now that I have seen the image. It looks like most of the information is in the green channel.

Green channel image green channel image

This image gives you a decent result if you simply apply a threshold. Thresholded image with a somewhat arbitrary threshold thresholded image

You can then either clean this image up by itself or use your edge image. To clean it up with the edge image you produced remove any white pixels that are more than a certain distance from one of your detected edges (create a Euclidean distance map from your edge image and use that to set any white pixels greater than a certain distance from an edge to black).

If you are still collecting images you may want to try to position the camera in a way to avoid the bottom of the jar (or whatever this is).

他のヒント

I'm not sure what your original image looks like. It would be helpful to see.

You have gaps between the lines because a line in your original image has two edges, one on each side. The canny algorithm is detecting them both. The Canny edge detection algorithm has at its heart the application of two Sobel kernels to calculate the gradient, one for detecting horizontal edges and one for detection vertical edges.

-1 0 +1
-2 0 +2
-1 0 +1

and

+1 +2 +1
 0  0  0
-1 -2 -1

These kernels will present peaks for both sides of the line. One peak positive and one negative. You can exclude one side of the line by excluding the corresponding peak. After taking the gradient of each direction truncate any values below zero (set the values to zero) to remove the second peak. Then continue with the Canny edge detection as usual. This will result in the detection of only a single edge for each line instead of the two that you are seeing now.

You could attempt to use a line scanning methodology. Start at the side and scan horizontally. When you hit an edge you assume you are in a root and you start setting the voxels to white. When you hit another edge you assume you are leaving a root and you start. There will be some fringe cases and you may want to add additional checks, such as limiting the allowed thickness of a root.

You could also do a flood fill style algorithm where you take a seed point in a root and travel up the root filling it in.

Not sure how well these would work as it depends on the image and I did not test it.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top