Main Content

crop

Create cropped version of blocked image

    Description

    example

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

    Examples

    collapse all

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

    Figure contains an axes. The axes 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 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);

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

    Input Arguments

    collapse all

    Blocked image, specified as a blockedImage object.

    Start of cropped area, specified as a 1-by-N, integer-valued pixel subscript vector for an N-dimensional blockedImage. If cstart has fewer than N elements, blockedImage extends it with 1s.

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

    End of crop area, specified as a 1-by-N, integer-valued pixel subscript vector of the last pixel in the crop window. If cend has fewer than N elements, blockedImage extends the image with the corresponding elements from Size at the finest level.

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

    Output Arguments

    collapse all

    Cropped blocked image, returned as blockedImage object which represents image data in the crop window across all resolution levels.

    See Also

    Introduced in R2021a