setConstrainedPosition
Set ROI object to new position
setConstrainedPosition
is not recommended. For information about
setting position constraints, see Version History.
Description
setConstrainedPosition(
sets the ROI object h
,pos
)h
to a new position. The candidate
position, pos
, is subject to the position constraint function
specified by setPositionConstraintFcn
.
Input Arguments
pos
— Candidate position of ROI object
numeric array
Candidate position of the ROI object, specified as a numeric array. The
shape of the array depends on the type of ROI object, and is consistent with
the form returned by the setPosition
function.
ROI Object | Position |
---|---|
imellipse | 4-element vector of the form [xmin ymin width
height] , representing the new size and
position of a bounding box around the ellipse. The new size
of the bounding box is
width -by-height
pixels. The upper-left corner of the box is at the new (x,y)
coordinate
(xmin ,ymin ). |
imline | 2-by-2 matrix of the form [x1 y1; x2
y2] , representing the new position of the two
endpoints of the line. |
impoint | 1-by-2 vector of the form [x
y] . |
impoly | n-by-2 matrix. The two columns define the new x- and y-coordinates, respectively, of each of the n vertices. |
imrect | 4-element vector of the form [xmin ymin width
height] . The new size of the rectangle is
width -by-height
pixels. The upper-left corner of the rectangle is at the new
(x,y) coordinate
(xmin ,ymin ). |
Version History
Introduced in R2008aR2018b: setConstrainedPosition
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 existing ROIs, you use makeConstrainToRectFcn
to
create a function to specify the limits of the area in which you can draw or move an
ROI. You then register this function with the ROI. When you use the
setPosition
object function, the ROI moves to wherever you
specify, even if it is outside of the constrained limits. If you use
setConstrainedPosition
, the ROI honors the limits set by the
constrained position function.
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. When you set the location
using the Position
property, it does not honor limits set by the
DrawingArea
property.
Update all instances of setConstrainedPosition
.
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); % Try to specify a Position value outside the limits. setConstrainedPosition(h,[1 51]); % Note how ROI does not honor value outside of limits. | With the new ROIs, use the
I = imread('cell.tif'); imshow(I) h = drawpoint(gca,'Position',[20 60]) [height width] = size(I); %Get image dimensions h.DrawingArea = [20,20,(width-40),(height-40)]; |
See Also
imroi
| getPositionConstraintFcn
| setPositionConstraintFcn
| setPosition
| getPosition
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
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)