Crop Image - MATLAB Imcrop - MathWorks India
Crop Image - MATLAB Imcrop - MathWorks India
Crop Image - MATLAB Imcrop - MathWorks India
imcrop
Crop image
Syntax
Icropped = imcrop
Icropped = imcrop(I)
Xcropped = imcrop(X,cmap)
___ = imcrop(h)
Icropped = imcrop(I,rect)
Xcropped = imcrop(X,cmap,rect)
___ = imcrop(xref,yref, ___ )
Description
Note
The interactive syntaxes do not support categorical images. For categorical images,
you must specify the crop
region, rect.
Xcropped = imcrop(X,cmap)
displays the indexed image X in a figure using the color map
cmap, and
creates an interactive Crop Image tool associated with
that image. imcrop returns the cropped indexed
image,
Xcropped, which also has the color map
cmap.
[xrefout,yrefout, ___ ]
= imcrop( ___ )
also returns the image limits of the input image in xrefout
and
yrefout.
I = imread('cameraman.tif');
[J,rect] = imcrop(I);
When you move the cursor over the image, it changes to a cross-hairs
. The Crop Image tool blocks the
MATLAB command line until you complete the operation.
https://in.mathworks.com/help/images/ref/imcrop.html 2/11
9/13/2021 Crop image - MATLAB imcrop - MathWorks India
The Crop Image tool returns the cropped area in the return variable,
J. The variable rect is the four-element
position vector describing the crop rectangle you specified.
whos
https://in.mathworks.com/help/images/ref/imcrop.html 3/11
9/13/2021 Crop image - MATLAB imcrop - MathWorks India
I = imread('circuit.tif');
subplot(1,2,1)
imshow(I)
title('Original Image')
subplot(1,2,2)
imshow(I2)
title('Cropped Image')
https://in.mathworks.com/help/images/ref/imcrop.html 4/11
9/13/2021 Crop image - MATLAB imcrop - MathWorks India
I = imread('parkavenue.jpg');
imshow(I)
Specify a target window size as a two-element vector of the form [width, height].
Create a Rectangle object that specifies the spatial extent of the crop window.
r = centerCropWindow2d(size(I),targetSize);
Crop the image to the spatial extents. Display the cropped region.
J = imcrop(I,r);
imshow(J)
https://in.mathworks.com/help/images/ref/imcrop.html 5/11
9/13/2021 Crop image - MATLAB imcrop - MathWorks India
Load indexed image with its associated map into the workspace.
Try This Example
load trees
X2 = imcrop(X,map,[30 30 50 75]);
subplot(1,2,1)
imshow(X,map)
title('Original Image')
subplot(1,2,2)
imshow(X2,map)
title('Cropped Image')
https://in.mathworks.com/help/images/ref/imcrop.html 6/11
9/13/2021 Crop image - MATLAB imcrop - MathWorks India
I — Image to be cropped
Note
For categorical input, you must specify a crop rectangle,
rect. The interactive syntaxes do not
support categorical
input.
Data Types: single | double | int8 | int16 | uint8 | uint16 | logical | categorical
matrix of integers
https://in.mathworks.com/help/images/ref/imcrop.html 7/11
9/13/2021 Crop image - MATLAB imcrop - MathWorks India
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
h — Input image
handle
numeric matrix
Size and position of the crop rectangle, returned as a 4-element numeric vector of
the form [xmin ymin width
height].
Interactive Behavior
The Crop Image tool is a moveable, resizeable rectangle that you can
position over the image and perform the
crop operation interactively using the mouse.
When the Crop Image tool is active in a figure, 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. You can also
choose Crop Image from the
context menu. The figure illustrates
the Crop Image tool with the context menu displayed.
https://in.mathworks.com/help/images/ref/imcrop.html 9/11
9/13/2021 Crop image - MATLAB imcrop - MathWorks India
Resize the Crop Image tool. Select any of the resize handles on the crop rectangle. The pointer changes to a
double-headed arrow . Click and drag the mouse to resize the crop
rectangle.
Move the Crop Image tool. Move the pointer inside the boundary of the crop rectangle. The pointer changes
to a fleur
shape . Click and drag the mouse to move the rectangle
over the
image.
Change the color used to display the Right-click inside the boundary of the crop rectangle and select Set
Color from
crop rectangle. the context menu.
Crop 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.
Retrieve the coordinates of the crop Right-click inside the boundary of the crop rectangle and select Copy
Position
rectangle. from the context menu. imcrop copies a
4-element position vector ([xmin ymin
width height]) to the
clipboard.
Extended Capabilities
https://in.mathworks.com/help/images/ref/imcrop.html 10/11
9/13/2021 Crop image - MATLAB imcrop - MathWorks India
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
See Also
drawrectangle | images.spatialref.Rectangle | imcrop3 | zoom
Topics
Image Types in the Toolbox
Define World Coordinate System of Image
https://in.mathworks.com/help/images/ref/imcrop.html 11/11