Index exceeds matrix dimensions. Error i (line 39) I(:,:,2) = input_img(:,:,2);
조회 수: 2 (최근 30일)
이전 댓글 표시
I got the above error while using the attached untitled2.m file
How can i correct the error
댓글 수: 1
KSSV
2017년 3월 31일
You are converting RGB image into gray...and then trying to extract it as RGB...I have removed rgb2gray conversion...and considering RGB image .
채택된 답변
KSSV
2017년 3월 31일
clc; clear all ;
clear all;
close all;
clc;
% -- Getting input file -- %
[filename pathname] = uigetfile({'*.jpg';'*.bmp'},'Select MRI');
inputimage=strcat(pathname, filename);
input=imread(inputimage);
% input=rgb2gray(imread(inputimage));
[m,n,p] = size(input) ;
if p==1
disp('Select RGB image')
break
end
% axes(handles.axes1)
figure,
imshow(input,[]);
axis off;
title('Input Image','fontsize',12,'fontname','Times New Roman','color','Black');
[row,col,cha] = size(input);
input_img = input;
if cha ==3
input = rgb2gray(input);
end
preim = medfilt2(input);
% axes(handles.axes2)
figure,
imshow(preim,[]);
axis off;
title('Preprocessed Image','fontsize',12,'fontname','Times New Roman','color','Black');
% ----------------------------------------------------------------
I(:,:,1) = input_img(:,:,1);
I(:,:,2) = input_img(:,:,2);
I(:,:,3) = input_img(:,:,3);
% Hematoxylin and eosin
text(size(I,2),size(I,1)+15,...
'Clustering process is done', ...
'FontSize',7,'HorizontalAlignment','right');
% cform = makecform('srgb2lab');
% lab_I = applycform(I,cform);
ab = double(I(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 3;
[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
'Replicates',2);
pixel_labels = reshape(cluster_idx,nrows,ncols);
figure,
imshow(pixel_labels,[]), title('Kmeans clustering');
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:nColors
color = I;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
Fig1 = segmented_images{1};
Fig2 = segmented_images{2};
Fig3 = segmented_images{3};
figure,
subplot(2,2,1),
imshow(Fig1);
subplot(2,2,2),
imshow(Fig2);
subplot(2,2,3),
imshow(Fig3);
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!