当前位置:首页 > 地信家园 > matlab图像处理imabsdiff函数和imsubtract函数的差别和用法

matlab图像处理imabsdiff函数和imsubtract函数的差别和用法

今天技术宅在使用matlab做数字图像处理的时候,需要使用到图像的减法运算,具体来说,是这样的:

 图像的减法运算(差分方法)

用途:检测图像变化及运动物体,作为许多图像处理工作的准备步骤。

函数调用格式:

Z = imsubtract(X,Y)

Z = imabsdiff(X,Y)

实现:图像-图像,图像-常数

可以看到,减法运算中有两种函数可以,imsubtract(X,Y)和 imabsdiff(X,Y),我想看看他们的差别,在网上找了一些然后综合matlab的帮助文件,总结如下:

总的来说,两者基本没有太大的差别,但是减法操作有时会导致某些像素值变为一个负数,对于uint8或uint16类型的数据,如果发生这种情况,那么imsubtract函数自动将这些负数截取为0,而imabsdiff计算后取了绝对值,从而使用的时候,为了避免差值产生负值,同时避免像素值运算结果之间差异过小(减去后结果为负数的不好都变成0),建议调用函数imabsdiff。

附两者的help说明:

imsubtract

Subtract one image from another or subtract constant from image

Syntax

Z = imsubtract(X,Y)

Description

Z = imsubtract(X,Y) subtracts each element in array Y from the corresponding element in array X and returns the difference in the corresponding element of the output array Z. X and Y are real, nonsparse numeric arrays of the same size and class, or Y is a double scalar. The array returned, Z, has the same size and class as X unless X is logical, in which case Z is double.

If X is an integer array, elements of the output that exceed the range of the integer type are truncated, and fractional values are rounded.

Note On Intel architecture processors, imsubtract can take advantage of the Intel Integrated Performance Primitives (Intel IPP) library, thus accelerating its execution time. The (Intel IPP) library is activated only if array X is of class uint8, int16, or single.

Examples

Subtract two uint8 arrays. Note that negative results are rounded to 0.
X = uint8([ 255 10 75; 44 225 100]);
Y = uint8([ 50 50 50; 50 50 50 ]);
Z = imsubtract(X,Y)
Z =

205 0 25
0 175 50

Estimate and subtract the background of an image:
I = imread(‘rice.png’);
background = imopen(I,strel(‘disk’,15));
Ip = imsubtract(I,background);
imshow(Ip,[])

Subtract a constant value from an image:
I = imread(‘rice.png’);
Iq = imsubtract(I,50);
figure, imshow(I), figure, imshow(Iq)

imabsdiff

Absolute difference of two images

Syntax

Z = imabsdiff(X,Y)

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.

Note This function 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.

Examples

Calculate 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

友荐云推荐
  • «
  • »
  • 作者:
    除非注明,本文原创:技术宅,欢迎转载!转载请以链接形式注明本文地址,谢谢。
    原文链接:http://www.jishuzh.com/gis/matlab图像处理imabsdiff函数和imsubtract函数的差别和用法.html

    2 thoughts on “matlab图像处理imabsdiff函数和imsubtract函数的差别和用法

    1. 创意礼物

      这个还是蛮有用的 以前一直不知道什么差别呢

      1. 技术宅 (Post author) 

        以后还会有很多类似的东西 欢迎继续访问哈

    评论已关闭.