Main Content

Rectangle

Spatial extents of 2-D rectangular region

Since R2019b

Description

ARectangleobject stores the spatial extents of a 2-D rectangular region.

Creation

You can create aRectangleobject in these ways.

  • centerCropWindow2d— Create aRectangleof a specified size whose position is centered on an image of different size.

  • randomWindow2d— Create aRectanglewhose position is selected randomly from within an image of different size. You can specify the size of the rectangle or a range of valid aspect ratios and relative areas of the rectangle.

  • Running the command

    r = images.spatialref。Rectangle(XLimits,YLimits)
    creates aRectangleobject and sets theXLimitsandYLimitsproperties.

Properties

expand all

Minimum and maximum limits of thex-axis, specified as a 2-element numeric vector of the form[min max], wheremaxis greater thanmin.

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

Minimum and maximum limits of they-axis, specified as a 2-element numeric vector of the form[min max], wheremaxis greater thanmin.

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

Examples

collapse all

Read and display an image.

I = imread('parkavenue.jpg'); imshow(I)

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

Specify a target window size as a two-element vector of the form [width,height].

targetSize = [300 600];

Create aRectangleobject 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)

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

Read and display an image.

I = imread('board.tif'); imshow(I)

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

Create aRectangleobject by specifying the horizontal and vertical spatial extents of the cropping window.

r = images.spatialref。矩形(300 [200],[200])
r = Rectangle with properties: XLimits: [200 300] YLimits: [50 200]

Crop the image to the spatial extents. Display the cropped region.

J = imcrop(I,r); imshow(J)

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

Version History

Introduced in R2019b