필터 지우기
필터 지우기

Hi i am getting Index out of bounds error pls help me solve it

조회 수: 4 (최근 30일)
Serena Woolridge
Serena Woolridge 2016년 3월 31일
댓글: Star Strider 2016년 4월 4일
I hv a 2d image of 93×58 pixels. Error im gettin is attempted to access b(1,59) because size(b)=(93,58).
How do i go about rectifying this error?? Pls help as im new to matlab and to image processing. Thanks in advance.
  댓글 수: 2
Serena Woolridge
Serena Woolridge 2016년 4월 1일
Hi i understand that i im attempting to get a 59th column but i would like to know how i can change my code to rectify it.Pls help.
my code goes like..
for ii=1:m2
for jj=1:n2
x=(b(ii,jj) /100)*(mapsize*mapsize);
end
end
Serena Woolridge
Serena Woolridge 2016년 4월 4일
To make it more clear, i am attempting to split pixels into subpixels of my image of size(93x58) and assign 1s and 0s to the subpixels in order to classify my image into its various classes. The error keeps appearing in the loc:
x=(b(ii,jj)/100)*(ms*ms);
The code i use is:
a=imread('image path');
imshow(a);
[m1,n1,o1]=size(a);
ms=input('enter map size');
m2=m1*ms;
n2=n1*ms;
for ii=1:m2
for jj=1:n2
x=(b(ii,jj)/100)*(ms*ms);
x=round(x);
if(x==(ms*ms))
for n=1:(ms*ms)
mat(n)=1;
end
else
r=randi(1,ms*ms,ms*ms);
d=magic(ms);
for n=1:x
mat(d(n))=1;
end
for n=x+1:(ms*ms)
mat(d(n))=0;
end
end
end
Please help me clear this error in order for me to do my project work. Thanks in advance.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2016년 3월 31일
편집: Star Strider 2016년 4월 1일
You’re asking for column 59 of a 58-column matrix.
Think about it ...
EDIT Seeing only the part of your code that you posted (about 8 hours ago), I would simply reverse the values of ‘m2’ and ‘n2’ in your loops.
  댓글 수: 2
Serena Woolridge
Serena Woolridge 2016년 4월 4일
Thanks, i have tried reversing the values but i get the same error. Is ther any other way to clear this?..
Star Strider
Star Strider 2016년 4월 4일
In these lines:
m2 = m1*ms;
n2 = n1*ms;
the ‘ms’ variable has to be greater than 0 and less than or equal to 1 for that to work correctly.
The only way I can come up with to avoid addressing outside the dimensions of your image is with something like this:
m2 = fix(max(1,m2));
m2 = fix(min(m1,m2));
n2 = fix(max(1,n2));
n2 = fix(min(n1,n2));
That limits the index variables to the limits of your image size.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

MHN
MHN 2016년 3월 31일
So, you should not attempt to get b(1,59) when the size of b is (93,58) !!!

Walter Roberson
Walter Roberson 2016년 4월 1일
Consider the possibility that you have m2 and n2 exchanged in your code.
Another possibility: did you use
[m2, n2] = size(YourMatrix)
and your image is a color image? If so then you have a bug because of the way that size() is defined when you have fewer outputs than the array has dimensions. Instead use
[m2, n2, ~] = size(YourMatrix)
  댓글 수: 2
Serena Woolridge
Serena Woolridge 2016년 4월 4일
Thanks, i have tried both the alternatives provided by you but the same error keeps appearing. Is there any other method that can be done to clear this error?? thanks in advance.
Walter Roberson
Walter Roberson 2016년 4월 4일
We need to see your code.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by