webnat0
webnat0

Reputation: 2716

Detecting horizontal round edges in color images

I'm trying to detect areas that contain a top portion of an oval shape in a color image.

Here are some examples I drew:

https://i.sstatic.net/I8MUh.jpg

https://i.sstatic.net/eNqN2.jpg

How would you accomplish this? I'm inexperienced in image processing, but I'm willing to read and learn. I'm mainly using OpenCV with C++ but I can use other libraries as well.

Upvotes: 1

Views: 1023

Answers (4)

Zaphod
Zaphod

Reputation: 1927

For ellipse detection, you can refer to this post. The two methods are based on the hough transform, and can be tuned easily if required.

Upvotes: 0

Leeor
Leeor

Reputation: 637

I would suggest a simpler approach than the Hough transform for circles. From the images above, I see that the oval has a uniform color while the rest of the image does not.

  1. Choose a proper color space (possibly HSV)
  2. Take the gray-scale as the hue or saturation - these will describe the colors in the image (not the intensity of the pixels)
  3. Calculate the gradient of (2)
  4. Pixels with gradient = 0 belong to the oval

Upvotes: 0

baci
baci

Reputation: 2588

There is actually a function to detect circles at opencv.

Use hough transform with low parameter2 -cause you should detect the circle with given only its top.

Another way should be as such;

1- low pass filter (gaussian blur, search inside opencv doc)

2- color filter -optional (use your object's color if you know it, otherwise try to obtain the color from pixel(image.width/2 , 0)

3- canny edge detection (again, refer to the doc)

4- find contours (again, refer to the doc)

5- if you have a contour having preferably big area and including pixel(image.width/2 , 0) -you will use pointPolygonTest here- then you have a blob at the bottom.

6- to detect if this blob is "oval" is a big issue; but you can do some filtering using properties of "ovality";

  • oval curves have 1 and only 1 peak point. There should be only 1 contour pixel having maximum height.
  • any 3 point of an oval curve cannot represent a line. This is not hard to implement, but complex for an algorithm.

Upvotes: 0

Semih Korkmaz
Semih Korkmaz

Reputation: 1145

In general the thing you ask is a kind of big problem. In the real world images, you will need to find every oval shape, distinguish which has top (till what angle you tolerate and consider up ?). Then you need to segment those shapes very well so you can find areas with top portion oval shaped objects.

However, if you need to find simpler images like in the example, but still a more general approach, you may first get edges by using any edge detection (for example Canny). Then, use Hough Transform for curves and ellipses. But I don't think there is function or library for that. So you may need implement your own Hough Transform. For that you must decide what exactly you mean by oval top. For your two images, if you successfully find oval top, just get the area under it. But to get more general you may want to segment shape under it with more sophisticated approach.

For Hough Transform; http://en.wikipedia.org/wiki/Hough_transform#Circle_Detection_Process and for using it with ellipses http://en.wikipedia.org/wiki/Randomized_Hough_transform

Upvotes: 1

Related Questions