error : Index in position 3 exceeds array bounds (must not exceed 1).
Show older comments
please help
I=imread('AFTER.tif');
[R C] = find(I(:,:,1)<100 & I(:,:,2)>0.2 & I(:,:,3)>10); error
imagesc(I)% a is the image
% rows and columns of area found by thresholding
n=randi([50 length(R)],1,300);%randomly generated indexes
r=R(n);c=C(n);% extraction of entries corresponding to randomly generated values in row and column vectors
for ii=1:length(n)
subpatch=I(r(ii)-75:r(ii)+75,c(ii)-75:c(ii)+75);%for patches of size 151 by 151
imwrite(subpatch,strcat('C:\Users\user\Documents\MATLAB\before\p',num2str(ii),'.tif') );
end
10 Comments
Bob Thompson
on 2 Jul 2019
Edited: Bob Thompson
on 2 Jul 2019
What is l?
To the best of my knowledge, find doesn't have any problem looking to different sheets of a matrix, especially when only a single sheet is called at a time, so it must mean that something is up with l.
You might also try removing [R, C], and just replace it with a single variable.
Akash Kuber
on 2 Jul 2019
Akash Kuber
on 2 Jul 2019
Torsten
on 2 Jul 2019
How did you alter the code ?
You can't access l(:,:,2) and l(:,:,3) in the find-command.
@Akash Kuber: If you change the code, of course you have to post the changed code also if you want us to identify, what the error is.
If I is a [1450 x 1733] matrix, you cann check I(:,:,3)>100, because there is no I(:, :, 3), exactly as the error message tells you.
Akash Kuber
on 2 Jul 2019
Edited: Akash Kuber
on 2 Jul 2019
Akash Kuber
on 2 Jul 2019
Edited: Stephen23
on 2 Jul 2019
Jan
on 2 Jul 2019
Does this mean, that the problem is solved?
"i have jus added find(I >100);" - but we do not know where you have added this.
Answers (1)
Rajani Mishra
on 18 Jul 2019
Edited: Rajani Mishra
on 18 Jul 2019
Hi,
I understand that you are facing the error – ‘Index in position 3 exceeds array bounds (must not exceed 1)’ while trying to access matrix ‘I’ used to store an image file.
Error exceeding array bounds is caused when you try to access an element out of matrix dimensions.
So before trying to access indices of matrix ‘I’ check whether it’s a RGB image or a grayscale image
as in case of grayscale image you should not have – ‘ I(:,:,3) or I(:,:2) ’.
To check whether it’s a RGB or grayscale image try :
st = imfinfo(filename);
st.ColorType
4 Comments
Anu Sebastian
on 17 Feb 2021
Edited: Anu Sebastian
on 24 Feb 2021
Request :- Would you solve the error
img=imread('C:\Users\Bipin\Desktop\BRAINTUMOUR\1.jpg');
im=imresize(img,[256 256],'bilinear');
imwrite(im,'C:\Users\Bipin\Desktop\BRAINTUMOUR\result\inpimg.png');
imshow(im);
global he
B = strel('disk',10);
he=imclose(im,B);
imshow(he);
title('Preprocessed Image');
global nimg
global he
g=he(:,:,2);
ne=g>150;
binaryImage=ne;
binaryImage = imclearborder(binaryImage);
cup=imfill(binaryImage,'holes');
se1=strel('disk',1);
di=imdilate(cup,se1);
BW = bwareafilt(di, 1);
R=he(:,:,1);
G=he(:,:,2);
B=he(:,:,3);
R(BW)=0;
G(BW)=0;
B(BW)=0;
nimg=cat(3,R,G,B);
imshow(nimg);
imwrite(nimg,'C:\Users\Bipin\Desktop\BRAINTUMOUR\result\segimg.png');
ERROR :->> brain1
Index in position 3 exceeds array bounds (must not exceed 1).
Error in brain1 (line 14)
g=he(:,:,2)
Walter Roberson
on 17 Feb 2021
D3 = size(I,3);
if ndims(I) > 3
fprintf('image is probably multispectral or a time series\n');
elseif D3 == 1
fprintf('image is very likely grayscale\n')
elseif D3 == 2
fprintf('Strange image. Might be grayscale + alpha. They exist, but pretty uncommon\n');
elseif D3 == 3
fprintf('image is most likely RGB\n');
elseif D3 == 4
fprintf('if this is a PNG image it is most likely RGBA. If it is a TIFF image it is more likely RGBA but might be CMYK or GeoTIFF\n');
else
fprintf('This must surely be a TIFF image. It might be multispectral or R+G+B+A+Ir or something more odd\n');
end
Walter Roberson
on 24 Feb 2021
Your image 1.jpg is not an rgb image.
Anu Sebastian
on 9 Mar 2021
Thank you for your reply sir
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!