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.
rect = randomWindow2d(size(I),[50 100]);
Erase the pixels from within the rectangular region.
J = imerase(I,rect);
Display the erased image. The erased pixels have the value 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 [xmin ymin width height].
rect = [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]);
Display the erased image.
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]));
Display the erased image.
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.
rect
— 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 [xmin
ymin
width
height] or a Rectangle
object.
fillValues
— Fill value
0
(default) | numeric scalar | 3-element numeric vector | numeric matrix | numeric array
Fill value to apply to erased pixels, specified as one of these values.
Fill Value | Result |
---|---|
numeric scalar | Fill erased pixels of a grayscale or RGB image with the specified gray value. |
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 in fillValue . The matrix specified by
fillValue must have the same height and width as the
erase rectangle, rect . |
numeric array with 3 planes | Fill each erased pixel of an RGB image with the color in the corresponding
pixel of fillValue . The array specified by
fillValue must have the same height and width as the
erase rectangle, rect . |
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
Introduced in R2021a
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érica Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)