Image Processing Toolbox    
imcrop

Crop an image

Syntax

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.

To specify the rectangle:

If you hold down the Shift key while dragging, or if you press the right mouse button on a 2- or 3-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

The input image A can be of class logical, uint8, uint16, or double. The output image B is of the same class as A. rect is always of class double.

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

zoom


  imcontour imdilate