Index exceeds matrix dimensions. Error i (line 39) I(:,:,2) = input_img(:,:,2);

2 vues (au cours des 30 derniers jours)
sam  CP
sam CP le 31 Mar 2017
Modifié(e) : sam CP le 3 Avr 2017
I got the above error while using the attached untitled2.m file
How can i correct the error
  1 commentaire
KSSV
KSSV le 31 Mar 2017
You are converting RGB image into gray...and then trying to extract it as RGB...I have removed rgb2gray conversion...and considering RGB image .

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 31 Mar 2017
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);

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by