I want to display RGB channels separately and I wrote below code and executed it. Why it shows an error like "Index exceeds matrix dimensions. Error in clusteredit (line 21) green = imIDX(:,:,2); % Green channel" . Please tell me how to tackle this
1 次查看(过去 30 天)
显示 更早的评论
clear all;
newImageRGB = imread('p2_left_norm_1.bmp');
figure;
imshow(newImageRGB);
title('Original image');
grayImage = rgb2gray(newImageRGB);
figure;
imshow(grayImage);
title('grayscale image');
afterWiener = wiener2(grayImage,[6 6]);
figure;
imshow(afterWiener);
title('Wiener filter');
imData=reshape(afterWiener,[],1);
imData=im2double(imData);
[IDX mn]=kmeans(imData,3);
imIDX=reshape(IDX,size(afterWiener));
red = imIDX(:,:,1); % Red channel
green = imIDX(:,:,2); % Green channel
blue = imIDX(:,:,3); % Blue channel
a = zeros(size(imIDX, 1), size(imIDX, 2));
just_red = cat(3, red, a, a);
just_green = cat(3, a, green, a);
just_blue = cat(3, a, a, blue);
back_to_original_img = cat(3, red, green, blue);
figure, imshow(just_red), title('Red channel')
figure, imshow(just_green), title('Green channel')
figure, imshow(just_blue), title('Blue channel')
1 个评论
KSSV
2017-3-7
Your imIDX is a 2D matrix, and you are treating it as 3D, that's why error popping out.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!