Main Content

crop

Create cropped version of blocked image

Since R2021a

Description

cbim = crop(bim,cstart,cend) crops the blocked image bim to the crop window specified by the starting and ending pixel subscripts cstart and cend, inclusive. Returns cbim, a blockedImage which references the same Source as bim, but represents image data in the crop window, across all levels.

example

Examples

collapse all

Create a blocked image from a sample image included with the toolbox.

bim = blockedImage("tumor_091R.tif");
bigimageshow(bim);

Figure contains an axes object. The axes object contains an object of type bigimageshow.

Inspect the image size and spatial extent in world coordinates.

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]);

Figure contains an axes object. The axes object contains 2 objects of type bigimageshow, images.roi.rectangle.

Obtain the world coordinates of the region.

wstartxy = hrect.Position(1:2);
wendxy = wstartxy + hrect.Position(3:4);

Convert from x-y to row-column order.

wstart = [wstartxy(2) wstartxy(1)];
wend   = [wendxy(2) wendxy(1)];

Convert to image subscripts. This is an optional step useful when using non-default world coordinates.

subs = world2sub(bim,[wstart;wend]);

Crop the blocked image to the image subscripts.

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

Display the cropped image. The axes limits match the extent of the cropped region in world coordinates.

bigimageshow(cbim);

Figure contains an axes object. The axes object contains an object of type bigimageshow.

Input Arguments

collapse all

Blocked image, specified as a blockedImage object.

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.

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

collapse all

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