How to fix Index position 1 exceeds array bounds (must not exceed 227)
조회 수: 2(최근 30일)
I've ask similar question before and solved the issue. However, I'm facing another error after running the codes. Can anyone tell me what does it mean by How to fix Index position 1 exceeds array bounds (must not exceed 227)? Btw, 227 is the size of image that I want after resizing for futher use in deep learning classification. Is there anything that I can change on the codes? Please help me.
%% Bounding box
% Bounding box
imbwlabel=bwlabel(I8); %bwlabel works only in binary (b&w,double) image
% % imshow(label2rgb(imbwlabel)); %this is important bcs it helps to create the bounding box
% %in colored (uint8,unit16 etc) image and not in binary (b&w) image
% figure;imshow(I10);%title('Image with Bounding box');
axis image off
for k=1 : length(bboxes)
rectangle('Position', [CurrBB(1),CurrBB(2),CurrBB(3),CurrBB(4)], 'EdgeColor','m','LineWidth',2)
%%crop and zero padding
obj = imcrop(I10,CurrBB);
[m, n, l]=size(obj);
if (m > 227 || n > 227)
Simon Chan 2022년 6월 10일
After image resize, the size of the image is always 227x227 in terms of number of rows and columns.
However, the original image may be larger, so that variable m or n can be larger than 227.
I think in your case, the value of m is larger than 227 so that the value of index i can be larger than 227. However, it is not possible to extract value from variable obj for i>227 anymore and gives you an error.
I12(i,j,k)=obj(i,j,k); % i can be 228 if m=300, for example.
Since the image size is always 227x227, you may just hardcode the index from 1 to 226 as follows: