0% found this document useful (0 votes)
103 views7 pages

Crop 3-D Images with MATLAB imcrop3

The imcrop3 function crops a 3D image volume according to a cuboid region specified by its size and spatial coordinates. It loads a 3D MRI image, displays the original volume, then crops the volume using imcrop3 with a cuboid region defined by its dimensions. The cropped volume is then displayed. Examples are provided to demonstrate cropping a volume using fixed offsets, and centrally cropping an image to a target size.

Uploaded by

Suresh Chandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views7 pages

Crop 3-D Images with MATLAB imcrop3

The imcrop3 function crops a 3D image volume according to a cuboid region specified by its size and spatial coordinates. It loads a 3D MRI image, displays the original volume, then crops the volume using imcrop3 with a cuboid region defined by its dimensions. The cropped volume is then displayed. Examples are provided to demonstrate cropping a volume using fixed offsets, and centrally cropping an image to a target size.

Uploaded by

Suresh Chandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

9/13/2021 Crop 3-D image - MATLAB imcrop3 - MathWorks India

imcrop3
Crop 3-D image

Syntax

Vout = imcrop3(V,cuboid)

Description
Vout = imcrop3(V,cuboid)
crops the image volume V according to cuboid,
which specifies the size example
and position of the cropping window in spatial coordinates.

Examples collapse all

 Crop 3-D Volume

Load a 3-D volume into the workspace.


Try This Example

View MATLAB Command

D = load('mristack');

V = D.mristack;

Display the image.

fullViewPnl = uipanel(figure,'Title','Original Volume');

volshow(V,'Parent',fullViewPnl);

Crop the volume using imcrop3, specifying the size and position of the cuboidal crop region.

https://in.mathworks.com/help/images/ref/imcrop3.html 1/7
9/13/2021 Crop 3-D image - MATLAB imcrop3 - MathWorks India

Vout = imcrop3(V,[30 40 10 100 100 10]);

Display the cropped image.

fullViewPnl = uipanel(figure,'Title','Cropped Volume');

volshow(Vout,'Parent',fullViewPnl);

 Crop 3-D Image Volume Using Fixed Off-Center Spatial Extent

Load a 3-D MRI image. Use the squeeze function to remove any singleton
dimensions. Try This Example

View MATLAB Command

S = load('mri.mat','D');

volumeData = squeeze(S.D);

Display the image.

fullViewPnl = uipanel(figure,'Title','Original Volume');

volshow(volumeData,'Parent',fullViewPnl);

https://in.mathworks.com/help/images/ref/imcrop3.html 2/7
9/13/2021 Crop 3-D image - MATLAB imcrop3 - MathWorks India

Create a Cuboid object and specify the cropping window size in all three dimensions.

c = images.spatialref.Cuboid([30,90],[30,90],[1,20]);

Crop the image based on the Cuboid dimensions.

croppedVolume = imcrop3(volumeData,c);

Display the cropped image.

fullViewPnl = uipanel(figure,'Title','Cropped Volume');

volshow(croppedVolume,'Parent',fullViewPnl);

https://in.mathworks.com/help/images/ref/imcrop3.html 3/7
9/13/2021 Crop 3-D image - MATLAB imcrop3 - MathWorks India

 Center Crop 3-D Image to Target Size

Load a 3-D MRI image. Use the squeeze function to remove any singleton
dimensions. Try This Example

View MATLAB Command

load mri;

D = squeeze(D);

Display the image.

fullViewPnl = uipanel(figure,'Title','Original Volume');

volshow(D,'Parent',fullViewPnl);

https://in.mathworks.com/help/images/ref/imcrop3.html 4/7
9/13/2021 Crop 3-D image - MATLAB imcrop3 - MathWorks India

Specify the target size of the cropping window.

targetSize = [64 64 10];

Create a center cropping window that crops the specified image from its center.

win = centerCropWindow3d(size(D),targetSize);

Crop the image using the center cropping window.

Dcrop = imcrop3(D,win);

Display the cropped image in a display panel.

fullViewPnl = uipanel(figure,'Title','Cropped Volume');

volshow(Dcrop,'Parent',fullViewPnl);

https://in.mathworks.com/help/images/ref/imcrop3.html 5/7
9/13/2021 Crop 3-D image - MATLAB imcrop3 - MathWorks India

Input Arguments collapse all

V — Volume to be cropped

 numeric array | logical array | categorical array

Volume to be cropped, specified as a numeric, logical, or categorical array.


V can be a 3-D array that represents a
single channel 3-D volume
or a 4-D array that represents a multichannel 3-D volume. If V
represents a
multichannel 3-D volume, then imcrop3 crops the first
three dimensions only.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical |
categorical

cuboid — Size and position of crop volume

 6-element numeric vector | Cuboid object

Size and position of the crop volume in spatial coordinates, specified as a


6-element vector of the form [xmin
ymin zmin width height depth] or a
images.spatialref.Cuboid object.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments collapse all

Vout — Cropped volume

 logical, numeric, or categorical array

Cropped volume, returned as a logical, numeric, or categorical array of the same


class as the input volume V.

https://in.mathworks.com/help/images/ref/imcrop3.html 6/7
9/13/2021 Crop 3-D image - MATLAB imcrop3 - MathWorks India

See Also
images.spatialref.Cuboid | imcrop

Introduced in R2019b

https://in.mathworks.com/help/images/ref/imcrop3.html 7/7

You might also like