Extracting edges from a shape
Mostra commenti meno recenti
Hello all.
I have an irregular form shape like in the image(s) below (created using inpolygon).

I only want to extract the outer edges of this shape, so that I can only have an idea of what the shape is (rather than the complete internal points).
I used contours (imcontour) module which highlights the regions I desire to attain (as shown in the image below).

So I only want to attain these yellow regions.
Help will be much appreciated. Thanks in advance :)
1 Commento
Risposta accettata
Più risposte (1)
Image Analyst
il 19 Dic 2022
Snippet for you to modify:
% 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.
6 Commenti
Usama Hussain
il 20 Dic 2022
Image Analyst
il 20 Dic 2022
mask is the digital image you create. What did you start with? An image, or an N-by-2 list of (x,y) coordinates? If the latter, where did they come from? Even if you have such a list you can create a binary image and set those points to true, thus creating a mask image.
mask = false(rows, columns);
for k = 1 : length(x)
mask(y(k), x(k)) = true;
end
Usama Hussain
il 20 Dic 2022
Image Analyst
il 20 Dic 2022
Then attach the image, not a screenshot, not a graph with a bunch of red crosshair markers on it, and not a whole figure with tick marks and tick labels, etc. Attach just the bare image alone. Or else attach the (x,y) data you used to create the image and the code to do it.
Usama Hussain
il 20 Dic 2022
Image Analyst
il 20 Dic 2022
And you forgot to attach that code or image. Alright, I guess I'll have to create an image from the screenshots you supplied and then continue on with a demo after that. I'll need several minutes to do that.
Categorie
Scopri di più su Object Analysis in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


