- find the outline/boundary of each segmented blob, then enlarge it and draw the enlarged outline over the image, or
- crop out a blob and enlarge it and paste it on top of the image.
Magnify Surface Blobs and Paint Them
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I am working on a image processing issue where I obtained certain amount of surface features. After I found surface features as blobs, I want to magnify them at the same center they are by a certain ratio. In the end, I will paint the original blob to a color and the area difference between the magnified version and the original to another. For certain ones they may collide when magnified but I will keep the original blob on the surface of the final image.
Is there a way to do this? Probably it should be related to boundaries but I couldn't manage to do it with bwboundaries. I am attaching an example surface for this purpose.
Thanks in advance.
2 个评论
Image Analyst
2023-9-15
So you want the original blob to be one color, and the enlarged annular region around it to be a different color?
I'm not sure if you want to
Which is it? 1 or 2 or something else? In the meantime I'm attaching copy and paste demos. If it's 2 the final image will of course depend on the order that you do the pasting.
回答(1 个)
Image Analyst
2023-9-15
Well there are two ways to draw outlines of the original and enlarged region.
- Use bwboundaries to get the outline of the segmented blobs, then use regionprops to get the centers, then multiply the distances from the boundaries to the centroid by some scaling factor, or (easier)
- Get original boundaries, then call bwmorph with the 'thicken' option, then get enlarged boundaries with bwboundaries
Which do you prefer?
Either provide the original image and your segmentation code, or upload your segmented binary image.
Boundary finding and drawing code snippet:
% 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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!