ImageChops.difference计算“两个图像之间逐像素差的绝对值”,这将导致返回一个不同的图像。它的代码在https://github.com/python-pillow/Pillow/blob/master/src/PIL/ImageChops.py#L88。更准确地说,对于2幅图像,image1和image2作为新图像返回以下内容:
image1.im.chop_difference(image2.im)
其中:
- chop_difference被定义为(PyCFunction)_chop_difference at imaging.c#L3085
- _chop_difference映射到imaging.c#L2016上的ImagingChopDifference
- ImagingChopDifference是https://github.com/python-pillow/Pillow/blob/4aba749c3c0ff0bc24b525886c0c89c3dca1d43f/libImaging/Imaging.h#L322引用的外部函数,在http://svn.effbot.org/public/tags/pil-1.1.4/libImaging/Chops.c的Chops.c中定义为:
ImagingChopDifference(成像imIn1,成像imIn2) { CHOP(abs((int) in1x - (int) in2x),NULL);}
- CHOP是以下类函数的C宏,它也在Chops.c中定义。它将算术运算的结果剪辑到范围(256)。注意,在这段代码中,'#‘不是开始注释,而是’# defining‘是定义常量或创建宏的C指令。
#定义CHOP(操作,模式)\ int x,y;\ imOut = create(imIn1,imIn2,mode);\ if (!imOut)\返回NULL;\ for (y = 0;y< imOut->ysize;y++) {\ UINT8 8* out =(UINT8 8*) imOut->imagey;\ UINT8 8* in1 =(UINT8 8*)imIn2 1->imagey;\UINT8 8* in2 =(UINT8 8*)imIn2 2->;对于(x = 0;x行大小;x++) {\ int =操作;\ if (temp <= 0)\ outx = 0;\ else if (temp >= 255)\ outx = 255;\ else\ outx = temp;\ }\ }\返回imOut;
- 在使用GNU预处理程序cpp对(4)和(3)中的代码进行预处理后,结果是可编译的ImagingChopDifference函数如下:
静态成像ImagingChopDifference(成像imIn1,成像imIn2) { int x,y;成像imOut;imOut = create(imIn1,imIn2,NULL);if (!imOut)返回NULL;for (y = 0;y< imOut->ysize;y++) {UINT8 8* out =(UINT8 8*) imOut->imagey;UINT8 8* in1 =(UINT8 8*)imIn1 1->imagey;UINT8 8* in2 =(UINT8 8*)imIn1 2->;对于(x = 0;x< imOut->linesize;x++) { int temp =abs (int) in1x -(Int) in2x);if (temp <= 0) outx = 0;否则if (temp >= 255) outx = 255;for outx = temp;}返回imOut;}
GNU C预处理器cpp广泛应用于Linux和Unix系统中。它的CentOS 7.0手册页位于http://www.unix.com/man-page/centos/1/cpp/。它的完整手册在https://gcc.gnu.org/onlinedocs/cpp/index.html,其中包括一章关于宏。
CHOP是CHannel OPeration的缩写,其中通道是指数字图像通道(参见image),而对通道操作结果的裁剪记录在http://effbot.org/imagingbook/imagechops.htm中)。