Documentation

imabsdiff

Absolute difference of two images

Syntax

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

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

Code Generation support: Yes.

MATLAB Function Block support: Yes.

Examples

collapse all

Display Absolute Difference between Filtered image and Original

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,[])

Display Absolute Difference Between Filtered Image and Original on GPU

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

X — Input imagereal, nonsparse numeric array

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

Y — Input imagereal, nonsparse numeric array

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

gpuarrayX — Input imageGPUarray

Input image, specified as a GPUarray.

Example: gpuarrayZ = imabsdiff(gpuarrayX,gpuarrayY);

gpuarrayY — Input imageGPUarray

Input image, specified as a GPUarray.

Example: gpuarrayZ = imabsdiff(gpuarrayX,gpuarrayY);

Output Arguments

collapse all

Z — Difference imagereal, nonsparse, numeric array

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.

gpuarrayZ — Difference imagegpuArray

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

More About

expand all

Code Generation

This function supports the generation of C code using MATLAB® Coder™. For more information, see Code Generation for Image Processing.

MATLAB Function Block

You can use this function in the MATLAB Function Block in Simulink.

Tips

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

Introduced before R2006a

Was this topic helpful?