In GUI functions of the MATLAB Image Processing Toolkit (image processing Toolbox), there are some functions used to select rectangles or elliptical regions on an image or an axis, using the following example:
[plain] view plain copy print? Figure, Imshow (' cameraman.tif '); h = imrect (GCA, [10 10 100 100]); API = Iptgetapi (h); Api.addnewpositioncallback (@ (P) title (MAT2STR (p,3)); FCN = MAKECONSTRAINTORECTFCN (' Imrect ', Get (GCA, ' Xlim '), Get (GCA, ' Ylim ')); API.SETPOSITIONCONSTRAINTFCN (FCN); The following explains the program features,
First line of code: display a built-in image of Matlab
The first line of code: Draws a rectangular area at the top left corner of the image, returns the handle value of the axes object in the rectangular area H,matlab help is interpreted as:
h = imrect (hparent, position) Createsa draggable rectangle on the object specified by Hparent. Position Isa Four-element Vector that specifies the initial size and locationof the rectangle.position has the form [xminy Min width height].
The third line of code: Get handle H API interface for subsequent program calls.
Four lines of code: Add a callback function, when the position of the rectangle is updated, this callback function is invoked to react to this, the way to react here is to display the position and size information of the rectangular box in the image's caption. MAT2STR is used to convert the rectangular box position data of the handle function p to a string.
Line five: Define a rectangular box area limit function that allows the rectangle frame to be confined to the interior of the image and not be moved to the outside of the image.
Line six: The function of calling the SETPOSITIONCONSTRAINTFCN function after the fifth line of code.