Create binary image using label matrix for corresponding cluster
6 views (last 30 days)
Show older comments
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 Comment
Walter Roberson
on 30 Jan 2016
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.
Answers (2)
Walter Roberson
on 30 Jan 2016
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 Comments
Image Analyst
on 30 Jan 2016
Edited: Image Analyst
on 30 Jan 2016
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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!