| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Image Processing Toolbox |
| Contents | Index |
| Learn more about Image Processing Toolbox |
I = imcrop
I2 = imcrop(I)
X2 = imcrop(X, map)
I = imcrop(h)
I2 = imcrop(I, rect)
X2 = imcrop(X, map, rect)
[...] = imcrop(x, y,...)
[I2 rect] = imcrop(…)
[X,Y,I2,rect] = imcrop(…)
I = imcrop creates an interactive Crop
Image tool associated with the image displayed in the current figure,
called the target image. The Crop Image tool is a moveable, resizable
rectangle that you can position interactively using the mouse. When
the Crop Image tool is active, the pointer changes to cross hairs
when you move it over
the target image. Using the mouse, you specify the crop rectangle
by clicking and dragging the mouse. You can move or resize the crop
rectangle using the mouse. When you are finished sizing and positioning
the crop rectangle, create the cropped image by double-clicking the
left mouse button or by choosing Crop Image from
the context menu. imcrop returns the cropped image, I.
The following figure illustrates the Crop Image tool with the context
menu displayed. For more information about the interactive capabilities
of the tool, see the table that follows.

| Interactive Behavior | Description |
|---|---|
| Deleting the Crop Image tool. | Press Backspace, Escape or Delete, or right-click inside the crop rectangle and select Cancel from the context menu. Note: If you delete the ROI, the function returns empty values. |
| Resizing the Crop Image tool. | Select any of the resize handles on the crop rectangle. The
pointer changes to a double-headed arrow
|
| Moving the Crop Image tool. | Move the pointer inside the boundary of the crop rectangle.
The pointer changes to a fleur shape
|
| Changing the color used to display the crop rectangle. | Right-click inside the boundary of the crop rectangle and select Set Color from the context menu. |
| Cropping the image. | Double-click the left mouse button or right-click inside the boundary of the crop rectangle and select Crop Image from the context menu. |
| Retrieving the coordinates of the crop rectangle. | Right-click inside the boundary of the crop rectangle and select Copy Position from the context menu. imcrop copies a four-element position vector ([xmin ymin width height]) to the clipboard. |
I2 = imcrop(I) displays the image I in a figure window and creates a cropping tool associated with that image. I can be a grayscale image, a truecolor image, or a logical array. The cropped image returned, I2, is of the same type as I.
X2 = imcrop(X, map) displays the indexed image X in a figure using the colormap map, and creates a cropping tool associated with that image.
I = imcrop(h) creates a cropping tool associated with the image specified by handle h. h may be an image, axes, uipanel, or figure handle. If h is an axes, uipanel, or figure handle, the cropping tool acts on the first image found in the container object.
Note With these interactive syntaxes, the cropping tool blocks the MATLAB command line until you complete the operation. |
I2 = imcrop(I, rect) crops the image I. rect is a four-element position vector[xmin ymin width height] that specifies the size and position of the crop rectangle.
X2 = imcrop(X, map, rect) crops the indexed image X. map specifies the colormap used with X. rect is a four-element position vector [xmin ymin width height] that specifies the size and position of the cropping rectangle.
[...] = imcrop(x, y,...) specifies a non-default spatial coordinate system for the target image. x and y are two-element vectors specifying XData and YData.
[I2 rect] = imcrop(…) returns the cropping rectangle in rect, a four-element position vector.
[X,Y,I2,rect] = imcrop(…) returns x and y, two-element vectors that specify the XData and YData of the target image.
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. A truecolor image 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 or a handle, the output image has the same class as the input image except for int16 or single. If the input image is int16 or single, the output image is double.
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.
I = imread('circuit.tif');
I2 = imcrop(I,[75 68 130 112]);
imshow(I), figure, imshow(I2)

![]() | imcontrast | imdilate | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |