In following code instead of using rgb2lab i have to use srgb2lab, i am getting error?

3 Ansichten (letzte 30 Tage)
e = imread('peppers.png'); lab_he = rgb2lab(he);
ab = lab_he(:,:,2:3); nrows = size(ab,1); ncols = size(ab,2); ab = reshape(ab,nrows*ncols,2);
nColors = 3; % repeat the clustering 3 times to avoid local minima [cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean','Replicates',3);
pixel_labels = reshape(cluster_idx,nrows,ncols); figure,imshow(pixel_labels,[]), title('image labeled by cluster index');

Antworten (1)

Image Analyst
Image Analyst am 14 Mai 2018
You read the image into "e" instead of "he". This works for me:
Try this improved code:
% Read in original color image.
rgbImage = imread('peppers.png');
subplot(1, 2, 1);
imshow(rgbImage);
title('Original RGB Image', 'FontSize', 18);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Convert to LAB color space.
labImage = rgb2lab(rgbImage);
ab = labImage(:,:,2:3);
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
numberOfClasses = 3; % Tell it we want only 3 color classes.
% Set Replicates = 3 to repeat the clustering 3 times to avoid local minima.
[cluster_indexes, cluster_centers] = kmeans(ab, numberOfClasses, 'distance','sqEuclidean','Replicates',3);
% Reshape back into 2-D image.
pixel_labels = reshape(cluster_indexes,nrows,ncols);
subplot(1, 2, 2);
imshow(pixel_labels,[])
title('Classified Image as labeled by kmeans()', 'FontSize', 18);

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by