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')

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Filter Design 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by