This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

imabsdiff

Absolute difference of two images

Syntax

Z = imabsdiff(X,Y)

Description

example

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.

You optionally can compute the absolute difference of X and Y using a GPU (requires Parallel Computing Toolbox™). For more information, see Image Processing on a GPU.

Examples

collapse all

Read image into workspace.

I = imread('cameraman.tif');

Filter the image.

J = uint8(filter2(fspecial('gaussian'), I));

Calculate the absolute difference of the two images.

K = imabsdiff(I,J);

Display the absolute difference image.

figure
imshow(K,[])

Read image and convert it to a gpuArray.

I = gpuArray(imread('cameraman.tif'));

Filter the image, performing the operation on a GPU.

J = imgaussfilt(I);

Calculate the absolute difference between the filtered image and original image.

K = imabsdiff(I,J);

Display the absolute difference image.

figure
imshow(K,[])

Input Arguments

collapse all

Input image, specified as a real, nonsparse numeric array of any dimension.

To compute the absolute difference using a GPU, specify X as a gpuArray that contains a numeric array.

Example: x = imread('cameraman.tif');

Example: X = gpuArray(imread('cameraman.tif'));

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

Input image, specified as a numeric array. Y must be the same size and class as X.

To compute the absolute difference using a GPU, specify Y as a gpuArray that contains a numeric array of the same size and class as the array in X.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

Output Arguments

collapse all

Difference image, returned as a numeric array. Z has the same class and size as X and Y. If X and Y are integer arrays, then imabsdiff truncates elements in the output that exceed the range of the integer type.

If the difference image is computed using a GPU, then Z is returned as a gpuArray containing a numeric array of the same size and class as in X and Y.

Tips

  • If X is of class double, then use the expression abs(X-Y) instead of this function.

  • If X is of class logical, then use the expression XOR(X,Y) instead of this function.

  • When X and Y are of class uint8, int16, or single, then imabsdiff can use hardware optimization to run faster.

  • imabsdiff runs on a GPU if at least one of X and Y are gpuArrays. It is not necessary that both inputs are gpuArrays.

Extended Capabilities

Introduced before R2006a