Image Processing Toolbox User's Guide |
Syntax
I2 = imcrop(I) X2 = imcrop(X,map) RGB2 = imcrop(RGB) I2 = imcrop(I,rect) X2 = imcrop(X,map,rect) RGB2 = imcrop(RGB,rect) [...] = imcrop(x,y,...) [A,rect] = imcrop(...) [x,y,A,rect] = imcrop(...)
Description
imcrop
crops an image to a specified rectangle. In the syntaxes below, imcrop
displays the input image and waits for you to specify the crop rectangle with the mouse.
If you omit the input arguments, imcrop
operates on the image in the current axes.
If you hold down the Shift key while dragging, or if you press the right mouse button on a two- or three-button mouse, imcrop
constrains the bounding rectangle to be a square.
When you release the mouse button, imcrop
returns the cropped image in the supplied output argument. If you do not supply an output argument, imcrop
displays the output image in a new figure.
You can also specify the cropping rectangle noninteractively, using these syntaxes
rect
is a four-element vector with the form [xmin ymin width height]
; these values are specified in spatial coordinates.
To specify a nondefault spatial coordinate system for the input image, precede the other input arguments with two, two-element vectors specifying the XData
and YData
. For example:
If you supply additional output arguments, imcrop
returns information about the selected rectangle and the coordinate system of the input image. For example:
A
is the output image. x
and y
are the XData
and YData
of the input image.
Class Support
If you specify RECT
as an input argument, the input image can be logical or numeric, and must be real and nonsparse. RECT
is of class double.
If you do not specify RECT
as an input argument, imcrop
calls imshow
. imshow
expects I
to be logical
, uint8
, uint16
, int16
, single
, or double
. RGB
can be uint8
, int16
, uint16
, single
, or double
. X
can be logical
, uint8
, uint16
, single
, or double
. The input image must be real and nonsparse.
If you specify an image as an input argument, the output image has the same class as the input image.
If you don't specify an image as an input argument, i.e., you call imcrop
with no input arguments, the output image has the same class as the input image except for the int16
or single
. The output image is double
if the input image is int16
or single
.
Remarks
Because rect
is specified in terms of spatial coordinates, the width
and height
elements of rect
do not always correspond exactly with the size of the output image. For example, suppose rect
is [20 20 40 30], using the default spatial coordinate system. The upper-left corner of the specified rectangle is the center of the pixel (20,20) and the lower-right corner is the center of the pixel (50,60). The resulting output image is 31-by-41, not 30-by-40, because the output image includes all pixels in the input image that are completely or partially enclosed by the rectangle.
Example
See Also
imcontrast | imdilate |
© 1994-2005 The MathWorks, Inc.