imabsdiff

Absolute difference of two images

Syntax

Z = imabsdiff(X,Y)
gpuarrayZ = imabsdiff(gpuarrayX,gpuarrayY)

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.

  • 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.

  • If X and Y are logical arrays, you can use the expression XOR(A,B) instead of this function.

    Note   This syntax may take advantage of hardware optimization for data types uint8, int16, and single to run faster. Hardware optimization requires that arrays X and Y are of the same size and class.

gpuarrayZ = imabsdiff(gpuarrayX,gpuarrayY) performs the computation on a GPU, if at least one of the inputs is a gpuArray. The output image is a gpuArray. This syntax requires the Parallel Computing Toolbox™..

Class Support

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.

gpuarrayX and gpuarrayY are real, nonsparse numeric gpuArrays with the same class and size. gpuarrayZ has the same class and size as gpuarrayX and gpuarrayY.

Examples

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);
figure, imshow(K,[])

Display the absolute difference between a filtered image and the original on a GPU.

I = gpuArray(imread('cameraman.tif'));
J = imfilter(I,fspecial('gaussian'));
K = imabsdiff(I,J);
figure, imshow(K,[])
Was this topic helpful?