When using the getrect function, is there any way to restrict the selected rectangle so that it cannot be dragged outside the borders of the image?
Normally it is draggable outside the image frame:
In most situations, being even slightly outside the image frame leads to errors. To fix this I used several if statements to ensure we enclose the appropriate pixels:
rect = getrect;
x2 = x1 + rect(3);
y2 = y1 + rect(4);
if ((x1 > size(X,2)) || (x2 < 0) || (y1 > size(X,1)) || (y2 < 0))
error('No pixels selected.');
rect = ;
if (x1 < 1)
x1 = 1;
if (x2 > size(X,2))
if y1 < 1
y1 = 1;
if y2 > size(X,1)
y2 = size(X,1);
But I think there must be a simpler way to do this.
Any suggestions would be greatly appreciated.