- Make an interactive tool to adjust "gray" threshold (e.g. slider)
- Add an input control to ask for eccentricity threshold
- Allow the user to select the desired "circle" (add 'HitTest', 'on', and 'ButtonDownFcn' callback in the text call. See text and Text Properties)
- Automatically dismiss the perfect circle (the big one -your lenses) that will be the one with the minimum of your eccentricity values (closest to zero)
Need to find centre of the circle
5 次查看(过去 30 天)
显示 更早的评论
Need to find Centre of the black (approx) circle in the image. Please help.
0 个评论
回答(3 个)
Frank Macias-Escriva
2017-3-2
Try this code in order to find the center of your "circle"
% some constants for "circle" detection
GRAY_TH = 128; % gray threshold
ECCENTRICITY_TH = 0.5; % eccentricity threshold, from 0(=>circle) to 1(=>line)
% load and convert to a binary image
entropy_img = imread('entropyfilt_imgB.jpg');
bw_entropy_img = entropy_img < GRAY_TH;
imshow(bw_entropy_img); hold on;
% look for region properties
s = regionprops(bw_entropy_img, entropy_img, {'Eccentricity', 'Centroid'});
% keep and plot those close to be a "circle"
numRegions = numel(s);
for k = 1:numRegions
if s(k).Eccentricity < ECCENTRICITY_TH
px = s(k).Centroid(1);
py = s(k).Centroid(2);
ptxt = [' \leftarrow(' num2str(px) ', ' num2str(py) ')'];
text(px, py, ptxt, 'Background', [.5 .5 .5], 'Color', 'blue');
plot(px, py, 'wd', 'MarkerFaceColor', 'blue');
end
end
Of course, you can enhance this piece of code in many ways:
Hope this help.
0 个评论
Walter Roberson
2017-3-1
Invert your image so the circle is white. imclearborder (or whatever it is called) to clear the white pixels that would introduce at the outside edge. regionprops asking for area and centroid and take the one with the larger area
0 个评论
Image Analyst
2017-3-1
Invert the image, histogram it and find a good threshold, then threshold to find a binary image. Call imclearborder() and bwareafilt(). Then follow the steps in my Image Segmentation Tutorial http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 where I find the centroids of blobs - just what you want to do.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!