How to get the edges of this mask?
26 ビュー (過去 30 日間)
古いコメントを表示
Rhandrey Maestri
2022 年 11 月 22 日
コメント済み: Rhandrey Maestri
2022 年 11 月 23 日
Hi, I would like to get the coordinates of the edge of the following image:
I tried with
Eb = edge(mask,'Canny');
but it results in:
Also, the following code did not give me good results too.
[xb, yb] = find(Eb);
plot(xb,yb)
Any suggestions are really appreciated.
Thanks
0 件のコメント
採用された回答
Image Analyst
2022 年 11 月 22 日
bwboundaries will give you a cell array of all boundaries in the image. Each boundary is a N-by-2 list of (x,y) coordinates. Here is a full demo where originalImage is your optional gray scale image and mask is your binary image:
% 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(mask);
% 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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Computer Vision with Simulink についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!