How can I visually isolate and measure a round object within my MATLAB image?

4 次查看(过去 30 天)
How can I visually isolate and measure a round object within my MATLAB image?
Do you have an example that shows how to do the following in MATLAB:
1. Select a round object in the image
2. Fill the rest of image with a background color
3. Draw an outline around the object
4. Find the diameter and center of the object

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2023-5-4
Here is an example on how to visually isolate and measure a round object within an image in MATLAB:
I = imread('eight.tif');
imshow(I)
BW = roipoly(I);
% manually select region here
BW1 = not(BW);
J = roifill(I,BW1); imshow(J)
% using ipexsegcell demo
% type 'ipexsegcell' from the MATLAB command prompt
% to view documentation for this demo
BWs = edge(J, 'sobel', (graythresh(I) * .1));
figure, imshow(BWs), title('binary gradient mask');
se90 = strel('line', 3, 90);
se0 = strel('line', 3, 0);
BWsdil = imdilate(BWs, [se90 se0]);
figure, imshow(BWsdil), title('dilated gradient mask');
BWdfill = imfill(BWsdil, 'holes');
figure, imshow(BWdfill);
title('binary image with filled holes');
BWnobord = imclearborder(BWdfill, 4);
figure, imshow(BWnobord), title('cleared border image');
seD = strel('diamond',1);
BWfinal = imerode(BWnobord,seD);
BWfinal = imerode(BWfinal,seD);
figure, imshow(BWfinal), title('segmented image');
BWoutline = bwperim(BWfinal);
Segout = I;
Segout(BWoutline) = 255;
figure, imshow(Segout), title('outlined original image');
% find diameter and center of the selected coin
[i,j] = find(BWfinal);
i1 = unique(i);
j1 = unique(j);
diameter = max(i)-min(i)
center_i = floor(mean(i1))
center_j = floor(mean(j1))
Additionally, another demonstration you can look into is the following MathWorks FileExchange submission:
https://www.mathworks.com/matlabcentral/fileexchange/25157-image-segmentation-tutorial

更多回答(1 个)

Image Analyst
Image Analyst 2016-11-20
编辑:MathWorks Support Team 2023-4-27
I do not recommend the accepted answer. See my Image Processing Tutorial for a much better and simpler method. https://www.mathworks.com/matlabcentral/fileexchange/25157-image-segmentation-tutorial You can simply threshold and call regionprops. There is no need for all that unnecessary edge detection and morphology stuff.

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by