Error using sub2ind and error in imline/createMask ?

Hi, while working with the below script I keep getting error message: Error using sub2ind (line 52) Out of range subscript. Error in imline/createMask (line 171) ind = sub2ind([m n], y, x); please can anyone help me with these error messages

 채택된 답변

Image Analyst
Image Analyst 2015년 7월 21일

0 개 추천

sub2ind() does not appear in your attached code. So all I can suggest is that either m (the row) is greater than y (the number of rows), or n (the column) is greater than x (the total number of columns).
Another common problem is mixing up row,column with x,y.

댓글 수: 4

thanks
sub2ind appears in the matlab function imline.createMask that is called by the OP code.
The base cause of the error is that the end points of the line are not within the image but I'd say it's a bug of createMask that it does not check for that or even better simply only use the part of the line that covers the image.
The code seems to have vanished. When an improper condition appears, it's always a judgment call by the Mathworks to try to fix the problem and try to recover, or to throw an error. I wonder what he did to get line endpoints outside the image. The function plot() will take points outside the image, but I guess they decided that createMask() should throw an error to let you know something's wrong. I bet they'd disagree about calling that behavior a bug.
I consider it a bug in the sense that: a) the documentation never states that the endpoints should be within the image, and b) the error you get does not hint at all at what the problem may be.
I have actually reported it to mathworks and they "will consider changing it in a future release".
Note that it's fairly trivial to get endpoints outside the image, simply using the interactive tool.

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

추가 답변 (1개)

Guillaume
Guillaume 2015년 7월 21일

0 개 추천

The error message is indeed not very helpful, but the error is simply due to the fact that one or both endpoints of your line generated by imline are outside the boundaries of the image.
I would suggest you use the debugger to step through your code and find out why.
But first, fix the indenting of your file (right-click in the editor and select smart indent or just press CTRL+I). Once you've done that it'll be fairly obvious that your hline = imline(... and subsequent lines should be inside the for nn = ... loop. (or you've got a major conceptual failure in your code as, as it is, only the x1, x2, index1, etc. of the last iteration of the three loop will be used).

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

질문:

2015년 7월 21일

댓글:

2015년 7월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by