error : Index in position 3 exceeds array bounds (must not exceed 1).

142 ビュー (過去 30 日間)
Akash Kuber
Akash Kuber 2019 年 7 月 2 日
コメント済み: Anu Sebastian 2021 年 3 月 9 日
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 件のコメント
Akash Kuber
Akash Kuber 2019 年 7 月 2 日
編集済み: Stephen23 2019 年 7 月 2 日
this is the code it works not giving out rgb image but greyscale image
clc;clear all;close all
%samle 3D matrix, e.g. can be an RGB image
a=imread('BEFORE.tif') ;
size(i);
[R, C] = find(I(:,:,1)<1450);
imagesc(I)% a is the image
% rows and columns of area found by thresholding
n=randi([1 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
Jan
Jan 2019 年 7 月 2 日
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.

サインインしてコメントする。

回答 (1 件)

Rajani Mishra
Rajani Mishra 2019 年 7 月 18 日
編集済み: Rajani Mishra 2019 年 7 月 18 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 2 月 24 日
Your image 1.jpg is not an rgb image.
Anu Sebastian
Anu Sebastian 2021 年 3 月 9 日
Thank you for your reply sir

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImages についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by