randomWindow2d
Randomly select rectangular region in image
Syntax
Description
selects a rectangular region of size赢
= randomWindow2d(输入
,targetSize
)targetSize
from a random position in an image of size输入
.
selects a rectangular region, specifying the size of the region relative to the input image,赢
= randomWindow2d(输入
,'规模',规模
,'DimensionRatio',DimensionRatio
)规模
, and the aspect ratio of the region,DimensionRatio
.
Examples
Select Random Rectangular Region of Target Size
阅读并显示图像。
I = imread(“ flamingos.jpg”); imshow(I)
Specify the size of the input image and the target size of the rectangular region.
inputsize = size(i);靶标= [40 60];
Select a region of the target size from a random location in the image.
rect = randomWindow2d(inputSize,targetSize);
从一个区域转换Rectangle
object to a 4-element vector of the form [xmin ymin宽度高度]。
rectxywh = [rect.xlimits(1)rect.ylimits(1)...diff(rect.XLimits)+1 diff(rect.YLimits)+1];
显示在原始图像上覆盖的矩形区域的边界。
annotatedI = insertShape(I,"Rectangle",rectXYWH,“行宽”,3); imshow(annotatedI)
Select Rectangular Region Specifying Scale and Dimension Ratio
阅读并显示图像。
I = imread("strawberries.jpg"); imshow(I)
Specify the size of the input image.
inputsize = size(i);
Specify a fractional area of the region between 2% and 13% of the area of the input image. Specify a range of aspect ratios between 1:5 and 4:3.
规模= [0.02 0.13]; dimensionRatio = [1 5;4 3];
Specify a region with a randomly selected fractional area and aspect ratio from a random location in the image.
rect = randomWindow2d(inputSize,"Scale",scale,"DimensionRatio",DimensionRatio);
Crop the original image to the randomly selected region and display the result.
iCrop = imcrop(i,rect);imshow(ICROP)
Input Arguments
输入
—Input image size
正整数的2元素向量|3-element vector of positive integers
输入图像大小,指定为以下内容之一。
Type of Input Image | 格式输入 |
---|---|
2-D grayscale or binary image | 正整数的2元素向量of the form[height width] |
2-D RGB或多光谱图像 | 3-element vector of positive integers of the form[height width channels] |
targetSize
—Target image size
正整数的2元素向量|3-element vector of positive integers
Target image size, specified as one of the following.
Type of Target Image | 格式targetSize |
---|---|
2-D grayscale or binary image | 正整数的2元素向量of the form[height width] |
2-D RGB或多光谱图像 | 3-element vector of positive integers of the form[height width channels] |
规模
—Region area as fraction of input image area
2-element numeric vector|function handle
区域区域是输入图像区域的一部分,指定为这些值之一。
2-element nondecreasing numeric vector with values in the range [0, 1]. The elements define a minimum and maximum fractional area of the region, respectively.
randomWindow2d
选择在该范围内的随机值,以用作分数区域。要使用固定区域,请为两个元素指定相同的值。功能句柄。The function must take no input arguments and return one number in the range [0, 1] specifying a valid fractional region area. For more information about function handles, seeCreate Function Handle.
DimensionRatio
—Range of aspect ratios of rectangular region
2 by-2正数矩阵|function handle
Range of aspect ratios of the rectangular region, specified as one of these values.
2 by-2正数矩阵. The first row defines the defines the minimum aspect ratio and the second row defines the maximum aspect ratio.
randomWindow2d
selects a random value within the range to use as the aspect ratio. To use a fixed aspect ratio, specify identical values for the first and second rows.功能句柄。该函数必须不采用输入参数,并返回一个指定有效维度比率的正数。例如,一个值的值
1.2
指定5:4的纵横比。有关功能处理的更多信息,请参阅Create Function Handle.
例子:[1 8;1 4]
selects an aspect ratio in the range 1:8 to 1:4
Output Arguments
赢
— Rectangular window
Rectangle
object
Rectangular window, returned as aRectangle
目的。
See Also
centerCropWindow2d
|randomCropWindow3d
|imcrop
Topics
- 使用图像处理工具箱的深度学习工作流程的增强图像(Deep Learning Toolbox)
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
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.
选择一个网站
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:.
您还可以从以下列表中选择一个网站:
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éricaLatina(Español)
- Canada(English)
- United States(English)
欧洲
- Belgium(English)
- 丹麦(English)
- Deutschland(德意志)
- España(Español)
- Finland(English)
- 法国(Français)
- 爱尔兰(English)
- 意大利(Italiano)
- Luxembourg(English)
- Netherlands(English)
- 挪威(English)
- Österreich(德意志)
- Portugal(English)
- Sweden(English)
- 瑞士
- 英国(English)