Main Content

imsubtract

Subtract one image from another or subtract constant from image

Description

example

Z= imsubtract(X,Y)subtracts each element in arrayYfrom the corresponding element in arrayXand returns the difference in the corresponding element of the output arrayZ.

Examples

艾尔崩溃l

This example shows how to subtract twouint8arrays. Note that negative results are rounded to 0.

X = uint8([ 255 0 75; 44 225 100]); Y = uint8([ 50 50 50; 50 50 50 ]); Z = imsubtract(X,Y)
Z =2x3 uint8 matrix205 0 25 0 175 50

Read a grayscale image into the workspace.

I = imread('rice.png');

估计背景。

background = imopen(I,strel('disk',15));

Subtract the background from the image.

J = imsubtract(I,background);

Display the original image and the processed image.

imshow(I)

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

figure imshow(J)

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

Read an image into the workspace.

I = imread('rice.png');

Subtract a constant value from the image.

J = imsubtract(I,50);

Display the original image and the result.

imshow(I)

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

figure imshow(J)

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

Input Arguments

艾尔崩溃l

First array (minuend), specified as a numeric array or logical array of any dimension.

Second array (subtrahend) to be subtracted fromX, specified as a numeric array or logical array of the same size and class asX, or a numeric scalar of typedouble.

Output Arguments

艾尔崩溃l

Difference, returned as a numeric array of the same size asX.Zis the same class asXunlessXis logical, in which caseZis data typedouble. IfXis an integer array, then elements of the output that exceed the range of the integer type are truncated, and fractional values are rounded.

Version History

Introduced before R2006a