MATLAB Answers

Recognizing a Specific Figure in an Image

4 views (last 30 days)
Gabrielle Kang
Gabrielle Kang on 5 Dec 2020
Answered: Image Analyst on 23 Dec 2020
I'm using roipoly to select a specific section of a graph. Afterwards, I subtract the two images to find contrast giving me something like this:
How might I write code that can recognize the black circle (within the roipoly region)?/Is it impossible and/or greatly inefficient to do this without modifying the image further (like removing the axes)?
As a side note, the region select may not be a perfect polygon (ie it can be any random polygon)

Answers (2)

Shraddha Jain
Shraddha Jain on 23 Dec 2020
Hi Gabrielle,
There is a function imfindcircles in Image Processing Toolbox which can find circles in an image using Hough transform. Further, you can also investigate the function regionprops and the example given in its documentation on spotting circular objects in an image.
Hope this helps!

Image Analyst
Image Analyst on 23 Dec 2020
Gabrielle, exactly what does "recognize" mean to you? You call regionprops() to get the centroid, area, or other measurements;
mask = yourImage == 0; % Find black
mask = imclearborder(mask); % Get rid of surround.
mask = imfill(mask, 'holes'); % Fill holes.
mask = bwareafilt(mask, 1); % Take largest ellipse only.
props = regionprops(mask, 'Centroid', 'Area');
area = props.Area
xCenter = props.Centroid(1)
yCenter = props.Centroid(2)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!