Set position constraint function of ROI object
setPositionConstraintFcn
is not recommended. With the new ROIs, use theDrawingArea
property instead. For more information, see兼容性有限公司nsiderations.
Display a rectangle ROI over an image. Display the position of the rectangle in the title. The title updates when you move the rectangle. Try dragging one side of the rectangle outside the boundary of the image.
imshow('cameraman.tif') h = imrect(gca,[10 10 100 100]); addNewPositionCallback(h,@(p) title(mat2str(p,3)));
Specify a position constraint function usingmakeConstrainToRectFcn
to keep the rectangle inside the originalXLim
andYLim
ranges.
fcn = makeConstrainToRectFcn('imrect'甘氨胆酸,(,'XLim'),get(gca,'YLim')); setPositionConstraintFcn(h,fcn);
Now drag the rectangle using the mouse. Observe that the rectangle can no longer extend past the image boundary.
imroi
|addNewPositionCallback
|makeConstrainToRectFcn
|getPositionConstraintFcn
|setConstrainedPosition
|getPosition