Index exceeds matrix dimensions.

조회 수: 1 (최근 30일)
pushk dfd
pushk dfd 2014년 1월 21일
댓글: pushk dfd 2014년 2월 5일
Dear All,
Good Day to you.I am trying to crop an image using the following method.I want to subdivide an image into components.My code is as follows.| |
a=imread('E:\a1.jpg'); [col row]=size(a); col
col =
119
row
row =
345
croped=a(1:119,1:116,:);
  • _??? Index exceeds matrix dimensions.
I get an error message shown above, when try to crop using the above values.And error message is not there for certain values. Please help me to solve this.
Thanks in advance.
  댓글 수: 1
Mischa Kim
Mischa Kim 2014년 1월 21일
Good one. Could you attach the jpg?

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

채택된 답변

Image Analyst
Image Analyst 2014년 1월 22일
Rows is the first index, columns is the second. You had them swapped when you did this:
croped=a(1:119,1:116,:); % col, row instead of row, col like it should be
In addition, you can read about the size function in Steve's blog http://blogs.mathworks.com/steve/2011/03/22/too-much-information-about-the-size-function/, which essentially say what Jan said.

추가 답변 (2개)

pushk dfd
pushk dfd 2014년 2월 5일
Dear All, Thank you very much.It worked really well.
thanks once again.

Jan
Jan 2014년 1월 21일
편집: Jan 2014년 1월 21일
What do you get for:
[col, row, channel] = size(a)
If you specify less outputs than the array has, the last one is the product of the remaining dimensions. If a is an RGB image, its dimensions are:
[119 x 115 x 3]
Therefore [s1,s2] = size(a) replies s1=119, s2=115*3.
See doc size -> "Specify Different Number of Outputs than ndims(X)"
  댓글 수: 2
Koteswar Rao  Jerripothula
Koteswar Rao Jerripothula 2014년 1월 22일
good observation, thanks
pushk dfd
pushk dfd 2014년 2월 5일
Thank you very much.It also helped a lot for me to gain a good understanding.

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

카테고리

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