Create binary image using label matrix for corresponding cluster
3 次查看(过去 30 天)
显示 更早的评论
I am doing a project to segment a cell image into a few region using k-means. I have found a useful example using adaptive k-means without the need to specify the cluster number and the link is as below.
However i face some problem to display the clustered image as the segmented image from original image. I was advice to use label matrix as a mask to create a binary image for corresponding label(clustered image) and then multiply the mask to original image in order to obtain the segmented image.
Any suggestion or advice how to do this? Thanks
1 个评论
Walter Roberson
2016-1-30
The user referenced http://www.mathworks.com/matlabcentral/answers/uploaded_files/40/freehand_masking_demo.m in their Tags, but it is not obvious what the connection is to their question.
回答(2 个)
Walter Roberson
2016-1-30
Presuming that the results of calling that function are in the variable LB
num_blob = max(LB(:));
for K = 1 : numblob
ax = subplot(1, num_blob, K);
mask = repmat(LB == K, 1, 1, 3);
masked_image = YourRGBImage .* mask;
image(ax, masked_image);
axis(ax, 'image');
title(ax, sprintf('blob %#d', K));
end
0 个评论
Image Analyst
2016-1-30
编辑:Image Analyst
2016-1-30
Assuming you have a labeled image where every color that you care about has a label of an integer 1 or more, and everything that you don't care about has a value of 0, you can mask the image like this:
mask = labeledImage > 0; % Get stuff we care about.
% Mask the image using bsxfun() function
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!