imerase
删除感兴趣的矩形区域内的图像像素
Description
Examples
Erase Pixels from Random Window
Read and display an image.
I = imread(“ Peppers.png”); imshow(I)
Select a rectangular region of size 50-by-100 pixels from a random location in the image.
矩形= randomWindow2d(size(I),[50 100]);
Erase the pixels from within the rectangular region.
J = imerase(I,rect);
显示擦除的图像。删除的像素具有值0
.
imshow(J)
Erase Pixels from Specified Window
Read and display an image.
I = imread("car1.jpg"); imshow(I)
Specify the size and position of the erase rectangle as a 4-element vector of the form [xminyminwidthheight].
矩形= [1040 1525 250 200];
Erase the pixels from within the rectangular region, and fill the erased pixels with the color green.
J = imerase(I,rect,"FillValues",[0 255 0]);
显示擦除的图像。
imshow(J)
Fill Erased Region with Random Colors
Read and display a color image.
I = imread('flamingos.jpg'); imshow(I)
Select a random square window from the image. The area of the window is between 2% and 13% of the area of the entire image.
win = randomWindow2d(size(I),"Scale",[0.02 0.13],"DimensionRatio",[1 1;1 1]);
Determine the height and width of the erase region.
hwin = diff(win.ylimits)+1;wwin = diff(win.xlimits)+1;
Erase the pixels within the erase region. Fill each pixel with a random color.
J = imerase(I,win,"FillValues",randi([1 255],[hwin wwin 3]));
显示擦除的图像。
imshow(J)
Input Arguments
I
—Image with region to be erased
numeric matrix|numeric array
Image with a region to be erased, specified as a numeric matrix representing a grayscale image or a numeric array with three channels representing a color image.
矩形
—Size and position of erase rectangle
4-element numeric vector|Rectangle
object
Size and position of the erase rectangle, specified as a 4-element numeric vector of the form [xminyminwidthheight]或aRectangle
目的。
fillValues
—Fill value
0
(default) |数字标量|3-element numeric vector|numeric matrix|numeric array
Fill value to apply to erased pixels, specified as one of these values.
Fill Value | Result |
---|---|
数字标量 | 用指定的灰色值填充灰度或RGB图像的擦除像素。 |
3-element numeric vector | Fill erased pixels of an RGB image with the specified color. |
numeric matrix | Fill each erased pixel of a grayscale or RGB image with the corresponding gray value infillValue . The matrix specified byfillValue 必须具有与擦除矩形相同的高度和宽度,矩形 . |
numeric array with 3 planes | Fill each erased pixel of an RGB image with the color in the corresponding pixel offillValue . The array specified byfillValue 必须具有与擦除矩形相同的高度和宽度,矩形 . |
Output Arguments
Ierased
— Image with erased region
numeric matrix | numeric array
Image with erased region, returned as a numeric matrix or numeric array of the same size as the input image,I
.
Version History
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.
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éricaLatina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- 丹麦(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- 法国(Français)
- 爱尔兰(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- 挪威(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)