MATLAB: Index exceeds matrix dimensions. Error i (line 39) I(:,:,2) = input_img(:,:,2); errorkmeans I got the above error while using the attached untitled2.m file How can i correct the error Best Answer 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') breakend% 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);endpreim = 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 eosintext(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;endFig1 = 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); Related SolutionsMATLAB: Kmeans clustering on an image in hsv color space My understanding is that there are two parts to this: (1) use a different transform name on the makecform; and (2) use different weightings on the planes, as the sensitivities show up in different ratios in the different color spaces. MATLAB: In following code error is Error using + Integers can only be combined with integers of the same class, or scalar doubles. How to remove it Try:ab = double(reshape(ab,nrows*ncols,2));ab is of class uint8. Convert it to double. Related QuestionUsing post classification confusion matrixHow can i detect the ROI from the ImageHow to choose specific color to display when using kmean clustering color segmentation
Best Answer