Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

imabsdiff

Absolute difference of two images

Syntax

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

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.

example

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

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 = imfilter(I,fspecial('gaussian'));

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. X must be the same size and class as Y.

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

Example: Z = imabsdiff(X,Y);

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

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

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

Example: Z = imabsdiff(X,Y);

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

Input image, specified as a GPUarray.

Example: gpuarrayZ = imabsdiff(gpuarrayX,gpuarrayY);

Input image, specified as a GPUarray.

Example: gpuarrayZ = imabsdiff(gpuarrayX,gpuarrayY);

Output Arguments

collapse all

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

Difference image, returned as a gpuArray. gpuarrayZ has the same class and size as gpuarrayX and gpuarrayY.

Tips

  • When X and Y are of class uint8, int16, or single, imabsdiff might take advantage of hardware optimization to run faster.

Extended Capabilities

Introduced before R2006a

Was this topic helpful?