Clear Filters
Clear Filters

Hello, everyone, I would like to ask how to transform the image curve drawn with the original image corresponding to the curve coordinates. Thank you very much for your answers.

1 view (last 30 days)

Answers (1)

Image Analyst
Image Analyst on 23 May 2021
To get the boundaries from your binary mask image, try this:
% 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 x.
plot(x, y, 'r-', 'LineWidth', 2); % Plot boundary in red.
hold off;
caption = sprintf('%d Outlines, from bwboundaries()', numberOfBoundaries);
title(caption, 'FontSize', fontSize);
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.
Wesley on 23 May 2021
Thank you very much for your reply. I think the coordinates may be symmetrical along a certain axis, and the drawn image may be better. Because the coordinates of the actual picture and the curve image are always not corresponding.
The image drawn in your method is still like this
Image Analyst
Image Analyst on 23 May 2021
Not sure how you got that. I don't think the two methods I gave would give you such chunky borders, even if you did have a low quality image with bad JPEG compression artifacts. How did you get that?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!