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

조회 수: 3 (최근 30일)
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');
  댓글 수: 1
Stephen23
Stephen23 2018년 5월 14일
@jayamala pakhare: please show us the complete error message. This means all of the red text.

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

답변 (1개)

Image Analyst
Image Analyst 2018년 5월 14일
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);

태그

Community Treasure Hunt

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

Start Hunting!

Translated by