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

 Réponse acceptée

Image Analyst
Image Analyst le 21 Juil 2015

0 votes

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 commentaires

peyush
peyush le 21 Juil 2015
thanks
Guillaume
Guillaume le 23 Juil 2015
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.
Guillaume
Guillaume le 24 Juil 2015
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.

Connectez-vous pour commenter.

Plus de réponses (1)

Guillaume
Guillaume le 21 Juil 2015

0 votes

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).

Catégories

En savoir plus sur Convert Image Type dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by