Create binary image using label matrix for corresponding cluster

6 ビュー (過去 30 日間)
tan yuki
tan yuki 2016 年 1 月 30 日
編集済み: Image Analyst 2016 年 1 月 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
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
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

Image Analyst
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));

Community Treasure Hunt

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

Start Hunting!

Translated by