Main Content

imerase

删除感兴趣的矩形区域内的图像像素

Description

example

Ierased= imerase(I,矩形)remove pixels of imageIwithin the rectangular region defined by矩形and returns the image with the erased region,Ierased.

example

Ierased= imerase(I,矩形,'FillValues',fillValues)also specifies the fill value to apply to the erased pixels.

Examples

collapse all

Read and display an image.

I = imread(“ Peppers.png”); imshow(I)

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

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)

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

Read and display an image.

I = imread("car1.jpg"); imshow(I)

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

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)

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

Read and display a color image.

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

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

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)

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

Input Arguments

collapse all

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 the erase rectangle, specified as a 4-element numeric vector of the form [xminyminwidthheight]或aRectangle目的。

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

collapse all

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

See Also

|