I have a image and code
HSV = rgb2hsv(I);
H = HSV(:,:,1); H = H(:);
S = HSV(:,:,2); S = S(:);
V = HSV(:,:,3); V = V(:);
idx = kmeans([H S V], 3);
cluster_idx=idx;
pixel_labels = reshape(cluster_idx,size(I,1),size(I,2));
figure,imshow(pixel_labels,[]), title('image labeled by cluster index');
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:3
color = I;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
figure,imshow(segmented_images{1}), title('objects in cluster 1');
figure,imshow(segmented_images{2}), title('objects in cluster 2');
figure,imshow(segmented_images{3}), title('objects in cluster 2');
for each segmented image i want to compute mean colur
plz assist

2 Kommentare

Jan
Jan am 21 Mär. 2013
What is your question? What exactly is the "application of a color"?
kash
kash am 21 Mär. 2013
My question is I have 3 segmented images ,for each segmented image,
segmented_images{1}),segmented_images{2}),segmented_images{3}),for these 3 images i have to apply different colours,i tried using
X=segmented_images{1});
X(:,:,1)=1
X(:,:,2)=0
X(:,:,3)=0,
but could not get colour on that segmented image,plz assist

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 22 Mär. 2013

0 Stimmen

Z = zeros(size(pixel_labels));
T = double(pixel_labels == 1);
segmented_image{1} = cat(3, T, Z, Z);
T = double(pixel_labels == 2);
segmented_image{2} = cat(3, Z, T, Z);
T = double(pixel_labels == 3);
segmented_image{3} = cat(3, Z, Z, T);

7 Kommentare

kash
kash am 22 Mär. 2013
but walter i ger same result
kash
kash am 22 Mär. 2013
say for 1st segmented image red,for 2nd magenta like on
Walter Roberson
Walter Roberson am 22 Mär. 2013
Are you trying to create a single image with the three clusters colored differently? Or are you trying to create three different images, each showing only the full-color pixels belonging to one of the clusters (in turn)?
kash
kash am 22 Mär. 2013
i want to create single image from three clusters,by assingning different colours to different clustered image and combine them
colmat = [1 0 0; 1 1 0; 0 0 1]; %RGB colors
segmented_image = reshape( colmat(pixel_labels(:),:), size(I,1), size(I,2), 3);
kash
kash am 22 Mär. 2013
thanks walter
Doug Hull
Doug Hull am 27 Mär. 2013
Thank him by accepting the answer. :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by