3
votes

Hi i have a image of a red ball and if i do Canny edge detection it will find nice edge but if i use my image of a bowl it finds lot of bad edges. I did tried to use this code to calculate optimal threshold but id doesn't help. How can i get rid of lines on bowl and shadow on the ball?

 MatOfDouble mu = new MatOfDouble();
         MatOfDouble sigma = new MatOfDouble();
         Core.meanStdDev(imageInMat, mu, sigma);
         Mat canny = new Mat();
         Imgproc.Canny(imageInMat, canny, mu.get(0,0)[0] - sigma.get(0,0)[0], mu.get(0,0)[0]+ sigma.get(0,0)[0]);

BallBowl

2
The gradient is much steeper on the bowl, especially with the specular highlights. You would have to find a way to remove or ignore the specular effects.JDong
Can I use some other edge detector?Brunts
You could try preprocessing your images. Specular reflection reduction is a thing. However, this requires multiple photos with different lighting.JDong

2 Answers

1
votes

Your objects have a very specific color so using color information may be the right way in this specific case.

Converting your image to HSV color space:

Hue channel:

enter image description here

Saturation channel:

enter image description here

Value channel:

enter image description here

Notice that in this case the Hue channel will not help because the shadow and the ball look the same. However, we can use the Saturation channel to find canny edges:

Canny edge detector on Saturation channel:

enter image description here

Finally, we can filter the obtained contours, accepting only the one with the largest area or an area greater than a certain threshold. This way we just get the ball:

enter image description here

I have not tested the other image you have posted but I think a similar approach will do the trick.

Hope it helps!

0
votes

The issue is the specular reflections. If you had more images, with different lightings, you could try applying Specular reflection reduction. Otherwise, you will probably have to tailor your code to this specific photo.

I don't specialize in CG, but have some other ideas for you. Notice that the highlights are a different white color than the off-white/gray background. You can use this to your advantage and maybe apply some filters or smoothing. In addition, you could try noise reduction on the final edges to remove the small edges.