Image Processing Toolbox User's Guide |
Compute absolute difference of two images
Syntax
Description
Z = imabsdiff(X,Y)
subtracts each element in array Y
from the corresponding element in array X
and returns the absolute difference in the corresponding element of the output array Z
. X
and Y
are real, nonsparse numeric arrays with the same class and size. Z
has the same class and size as X
and Y
. If X
and Y
are integer arrays, elements in the output that exceed the range of the integer type are truncated.
If X
and Y
are double arrays, you can use the expression abs(X-Y)
instead of this function.
Examples
This example calculates the absolute difference between two uint8
arrays. Note that the absolute value prevents negative values from being rounded to zero in the result, as they are with imsubtract
.
X = uint8([ 255 10 75; 44 225 100]); Y = uint8([ 50 50 50; 50 50 50 ]); Z = imabsdiff(X,Y) Z = 205 40 25 6 175 50
Display the absolute difference between a filtered image and the original.
I = imread('cameraman.tif'); J = uint8(filter2(fspecial('gaussian'), I)); K = imabsdiff(I,J); imshow(K,[]) % [] = scale data automatically
See Also
imadd
, imcomplement
, imdivide
, imlincomb
, immultiply
, imsubtract
, ippl
im2uint8 | imadd |
© 1994-2005 The MathWorks, Inc.