I need to contour a round object in a image.

조회 수: 2 (최근 30일)
Sebastian-Marian Lupu
Sebastian-Marian Lupu 2022년 1월 9일
댓글: Sebastian-Marian Lupu 2022년 1월 9일
I have a picture with 8 moon phases, but I need to outline the phase when the moon is full, regardless of its position. Please help me :)
  댓글 수: 2
KSSV
KSSV 2022년 1월 9일
Attach your original image.

댓글을 달려면 로그인하십시오.

채택된 답변

Simon Chan
Simon Chan 2022년 1월 9일
One possible way:
rawdata = imread('Moon.jpeg');
BW1 = imbinarize(rawdata);
BW2 = bwareafilt(BW1,1);
BW3 = imfill(BW2,'holes');
BW4 = bwperim(BW3);
figure(1);
subplot(2,2,1);
imshow(rawdata);
title('Original Image');
subplot(2,2,2);
imshow(BW2);
title('Region with Largest Area');
subplot(2,2,3);
imshow(BW3);
title('Holes filling');
subplot(2,2,4);
imshow(BW4);
title('Perimeter of object');

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 1월 9일
Once you've gotten the largest blob, if you want to outline the region in red over the original image (in the overlay), you can use bwboundaries:
% Plot the borders of all the blobs in the overlay above the original grayscale image
% using the coordinates returned by bwboundaries().
% bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
imshow(originalImage); % Optional : show the original image again. Or you can leave the binary image showing if you want.
% Here is where we actually get the boundaries for each blob.
boundaries = bwboundaries(binaryImage);
% boundaries is a cell array - one cell for each blob.
% In each cell is an N-by-2 list of coordinates in a (row, column) format. Note: NOT (x,y).
% Column 1 is rows, or y. Column 2 is columns, or x.
numberOfBoundaries = size(boundaries, 1); % Count the boundaries so we can use it in our for loop
% Here is where we actually plot the boundaries of each blob in the overlay.
hold on; % Don't let boundaries blow away the displayed image.
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k}; % Get boundary for this specific blob.
x = thisBoundary(:,2); % Column 2 is the columns, which is x.
y = thisBoundary(:,1); % Column 1 is the rows, which is y.
plot(x, y, 'r-', 'LineWidth', 2); % Plot boundary in red.
end
hold off;
caption = sprintf('%d Outlines, from bwboundaries()', numberOfBoundaries);
fontSize = 15;
title(caption, 'FontSize', fontSize);
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.

카테고리

Help CenterFile Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by