![seg.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247213/seg.png)
How can I remove or blank labeled pixels in an image with K-means Clustering to create a new image?
1 回表示 (過去 30 日間)
古いコメントを表示
Gabriel Hernandez
2019 年 11 月 3 日
コメント済み: Gabriel Hernandez
2019 年 11 月 10 日
I followed the example of labelling with imsegkmeans given here: https://www.mathworks.com/help/images/ref/imsegkmeans.html#mw_67d07395-31d1-45bf-8913-7ce58bfb6e38.
Given an image named I, I used the imsegkmeans function to separate pixels into two labels:
[L,Centers] = imsegkmeans(I,2);
B = labeloverlay(I,L);
figure;
imshow(B)
title('Labeled Image')
The input is this image of a strawberry:
![Selection_089.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/246302/Selection_089.png)
Which gave me this output:
![Selection_088.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/246303/Selection_088.png)
What the function does is, create a matrix of the same size of I and label pixels with numbers from 1 to N according to the N labels requested. Then, assign and colour regions according to their label.
My question is, how can I blank or delete all the pixels that were labeled 1 and leave a new image with the ones labeled 2? In other words, I want everthing coloured in light blue to get eliminated and become white, and produce another image with only the contents that were labeled in dark blue.
Thank you in advance.
0 件のコメント
採用された回答
Subhadeep Koley
2019 年 11 月 7 日
Hi, use rescale() and imbinarize() to segment out your Region Of Interest (ROI) except the background.
% Read your image here
I = imread(yourImage.png');
% K-means Clustering
[L,Centers] = imsegkmeans(I,2);
% Rescale the image to bring it in the range of [0, 1]
L = rescale(L);
% Binarize L to create the segmentation mask
L = imbinarize(L);
% Overlay L over I
B = labeloverlay(I,L);
figure; imshow(B); title('Labeled Image');
![seg.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247213/seg.png)
Hope this helps!
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Computer Vision with Simulink についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!