colour image segmentation using k means

I have a rgb image and have converted into hsv colour space,with k=2,now i want to segment the image as shown below,please tell what process to perform next

 채택된 답변

Thorsten
Thorsten 2013년 1월 16일

0 개 추천

I = imread('./../../Downloads/planes.png');
I = im2double(I(1:320, 1:478, :));
HSV = rgb2hsv(I);
H = HSV(:,:,1); H = H(:);
S = HSV(:,:,2); S = S(:);
V = HSV(:,:,3); V = V(:);
idx = kmeans([H S V], 2);
imshow(ind2rgb(reshape(idx, size(I,1), size(I, 2)), [0 0 1; 0 0.8 0]))

댓글 수: 3

FIR
FIR 2013년 1월 17일
Thanks thorsten what does [0 0 1; 0 0.8 0] specify
if i do
A=ind2rgb(reshape(idx,size(I,1),size(I,2),[0 0 1;0 0.8 0])); i get error Error using ==> reshape Size arguments must be integer scalars.
Error in ==> Untitled at 17 A=ind2rgb(reshape(idx,size(I,1),size(I,2),[0 0 1;0 0.8 0]));
can i change the background colour green to other colour say magneta or red
FIR
FIR 2013년 1월 17일
for the following Image i changed k=5,but why i get only two colours
Walter Roberson
Walter Roberson 2013년 1월 17일
편집: Walter Roberson 2013년 1월 17일
[0 0 1; 0 0.8 0] is a color table with two entries: bright blue, and medium green. If you can come up with the RGB shade you want, change the 0 0.8 0 to that RGB triple.
If you have 5 clusters you would want 5 entries in the color table.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Spandan Tiwari
Spandan Tiwari 2013년 10월 11일

1 개 추천

Another alternative could be to use multi-level Otsu's thresholding to get the segmentation. You can use the function multithresh in the Image Processing Toolbox to do that.
Otsu's method and k-means clustering have equivalent objective functions (minimize within-class variance). The following paper discusses this relation:
Dongju Liu, Jian Yu, " Otsu Method and K-means ," Vol. 1, pp.344-349, Ninth International Conference on Hybrid Intelligent Systems, 2009.
Image Analyst
Image Analyst 2013년 1월 16일

0 개 추천

Assuming you set k=2 and did the kmeans like you said and is shown in this example, I don't know what you want to do next. You haven't said. The most typical thing to do next is to call bwlabel() or bwconncomp() followed by regionprops to make various measurements (such as area) on the regions. I can be more specific if you get more specific.

댓글 수: 4

FIR
FIR 2013년 1월 17일
I need the output as Thorsten gave,i need to make only two colours for that plane image
Image Analyst
Image Analyst 2013년 1월 17일
I thought you had already done that part because you said " have converted into hsv colour space,with k=2" and you showed an image that you had created. Converted is past tense, meaning that it happened in the past. Was that wrong? Did you not convert (classify) the image yet and so you needed Thorsten's code to do it for you?
FIR
FIR 2013년 1월 17일
i actually meant last 2 lines
SAM
SAM 2013년 10월 11일
편집: SAM 2013년 10월 11일
Assuming you set k=2 and did the kmeans like you said and is shown in this example, I don't know what you want to do next. You haven't said. The most typical thing to do next is to call bwlabel() or bwconncomp() followed by regionprops to make various measurements (such as area) on the regions. I can be more specific if you get more specific.
can you please tell me how can i calculate the area...

댓글을 달려면 로그인하십시오.

질문:

FIR
2013년 1월 16일

답변:

2013년 10월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by