imcrop
Crop image
Syntax
Description
Crop Image Interactively
Note
The interactive syntaxes do not support categorical images. For categorical images, you must specify the crop region,rect
.
creates an interactive Crop Image tool associated with the grayscale, truecolor, or binary image displayed in the current figure.Icropped
= imcropimcrop
returns the cropped image,Icropped
.
With this syntax and the other interactive syntaxes, the Crop Image tool blocks the MATLAB®command line until you complete the operation. For more information about using the Crop Image tool, seeInteractive Behavior.
___= imcrop(
creates an interactive Crop Image tool associated with the image specified by the handleh
)h
.
Crop Image by Specifying Crop Region
crops the imageIcropped
= imcrop(I
,rect
)I
according to the position and dimensions specified in the crop rectanglerect
. The cropped image includes all pixels in the input image that are completelyor partiallyenclosed by the rectangle.
The actual size of the output image does not always correspond exactly with the width and height specified byrect
. For example, supposerect
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 with spatial(x,y)coordinates (20,20). The lower right corner of the rectangle is the center of the pixel with spatial(x,y)coordinates (60,50). The resulting output image has size 31-by-41 pixels, not 30-by-40 pixels.
Specify Additional Output Options
[___,
also returns the position of the crop rectangle inrectout
] = imcrop(___)rectout
. You can use the input arguments of any other syntax.
imcrop(___)
without output arguments displays the cropped image in a new figure window. This syntax does not support categorical images.