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

조회 수: 2 (최근 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일
편집: 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