makeConstrainToRectFcn
Create rectangularly bounded drag constraint function
makeConstrainToRectFcn
is not recommended. With the new ROIs, use the
DrawingArea
property instead. For more information, see Version History.
Description
Examples
Constrain Drag of impoint to Image Limits
Display an image.
imshow('cell.tif')
Create an impoint
object at the (x,y) coordinate (20,60). In an image, the positive y direction is downwards.
h = impoint(gca,20,60);
Make a function that constrains the impoint
to the image limits.
x = get(gca,'XLim'); y = get(gca,'YLim'); fcn = makeConstrainToRectFcn('impoint',x,y);
Apply the constraint function to the impoint
. Try dragging the point past the boundary of the image. The constraint function prevents the point from crossing the image boundary.
setPositionConstraintFcn(h,fcn);
Input Arguments
roi
— ROI type
'imellipse'
| 'imfreehand'
| 'imline'
| 'impoint'
| 'impoly'
| 'imrect'
ROI type, specified as 'imellipse'
,
'imfreehand'
, 'imline'
,
'impoint'
, 'impoly'
, or
'imrect'
.
Data Types: char
| string
x
— Rectangular boundaries in the x direction
2-element numeric vector
Rectangular boundaries in the x direction, specified as a
2-element numeric vector of the form [xmin xmax]
.
y
— Rectangular boundaries in the y direction
2-element numeric vector
Rectangular boundaries in the y direction, specified as a
2-element numeric vector of the form [ymin ymax]
.
Output Arguments
fcn
— Function handle
handle
Function handle, returned as a handle. For more information, see Create Function Handle.
Version History
Introduced in R2006aR2018b: makeConstrainToRectFcn
is not recommended
Starting in R2018b, a new set of ROI objects replaces the existing set of ROI objects. The new objects provide more functional capabilities, such as face color transparency. The new classes also support events that you can use to respond to changes in your ROI such as moving or being clicked. Although there are no plans to remove the old ROI objects at this time, switch to the new ROIs to take advantage of the additional capabilities and flexibility. For more information on creating ROIs using the new ROI functions, see Create ROI Shapes.
With the new ROIs, you use the DrawingArea
property of the ROI to
specify the area in which you can draw or move an ROI.
Update all instances of makeConstrainToRectFcn
.
Discouraged Usage | Recommended Replacement |
---|---|
This example uses the imshow('cell.tif') h = impoint(gca,20,60); % Make a function that constrains movement of the point x = get(gca,'XLim'); y = get(gca,'YLim'); fcn = makeConstrainToRectFcn('impoint',x,y);; % Apply the constraint function to the ROI. setPositionConstraintFcn(h,fcn); | Here is equivalent code, replacing use of
I = imread('cell.tif'); imshow(I) h = drawpoint(gca,'Position',[20 60]) [height width] = size(I); %Get image dimensions h.DrawingArea = [10,10,(width-20),(height-20)]; |
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)