crop
Description
Examples
Crop Multiresolution Image
Create a blocked image from a sample image included with the toolbox.
bim = blockedImage('tumor_091R.tif');
figure
bigimageshow(bim);
Inspect image size and world coordinate properties
bim.Size
ans = 3×3
5000 5358 3
1250 1340 3
625 670 3
bim.WorldStart
ans = 3×3
0.5000 0.5000 0.5000
0.5000 0.5000 0.5000
0.5000 0.5000 0.5000
bim.WorldEnd
ans = 3×3
103 ×
5.0005 5.3585 0.0035
5.0005 5.3585 0.0035
5.0005 5.3585 0.0035
Define a region of interest on the image that will be the crop area.
hrect = drawrectangle('Position', [2280 1300 1024 800]);
Obtain the world coordinates of the region.
wstartxy = hrect.Position(1:2); wendxy = wstartxy + hrect.Position(3:4);
Convert to row-col order, include world coordinates of the last dimension.
wstart = [wstartxy(2), wstartxy(1), bim.WorldStart(1,3)]; wend = [wendxy(2), wendxy(1), bim.WorldEnd(1,3)];
Convert to image subscripts, this is an optional step useful when using non-default world coordinates.
subs = world2sub(bim, [wstart; wend]); cbim = crop(bim, subs(1,:), subs(2,:));
Inspect properties of the cropped image.
cbim.Size
ans = 3×3
801 1025 3
201 258 3
101 130 3
cbim.WorldStart
ans = 3×3
103 ×
1.2995 2.2795 0.0005
1.2965 2.2757 0.0005
1.2965 2.2717 0.0005
figure
% Axes limits reflect cropped coordinates
bigimageshow(cbim);
Input Arguments
bim
— Blocked image
blockedImage
object
Blocked image, specified as a blockedImage
object.
cstart
— First pixel in crop window
1-by-N integer-valued vector
First pixel in the crop window, in pixel subscripts, specified as a
1-by-N integer-valued vector for an
N-dimensional blockedImage
. If
cstart
has fewer than N elements,
blockedImage
extends it with 1s.
cend
— Last pixel in crop window
1-by-N integer-valued vector
Last pixel in the crop window, in pixel subscripts, specified as a
1-by-N integer-valued vector. If cend
has fewer
than N elements, blockedImage
extends the image
with the corresponding elements from Size
at the finest level.
Output Arguments
cbim
— Cropped blocked image
blockedImage
object
Cropped blocked image, returned as a blockedImage
object that contains image data in the crop window across all resolution levels.
Version History
Introduced in R2021a
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)