Documentation

imsubtract

Subtract one image from another or subtract constant from image

Syntax

Z = imsubtract(X,Y)

Description

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.XandYare real, nonsparse numeric arrays of the same size and class, orYis a double scalar. The array returned,Z, has the same size and class asXunlessXis logical, in which caseZis double.

If X is an integer array, elements of the output that exceed the range of the integer type are truncated, and fractional values are rounded.

Examples

collapse all

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 =2×3 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 imshow(J)

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 imshow(J)

Introduced before R2006a

Was this topic helpful?