Instead of using diff or just subtracting im1-im2 I would rather suggest the OpenCV cv::absdiff
using namespace cv; Mat im1 = imread("image1.jpg"); Mat im2 = imread("image2.jpg"); Mat diff; absdiff(im1, im2, diff);
Since images are usually stored using unsigned formats, the subtraction methods @Dat and @ ssh99 will kill all the negative differences. For example, if some pixel of the BMP image has the value [20, 50, 30] for im1 and [70, 80, 90] for im2 , using both im1 - im2 and diff(im1, im2, diff) will result in the value [0,0,0] , since 20-70 = -50 , 50-80 = -30 , 30-90 = -60 , and all negative results will be converted to unsigned value 0 , which in most cases is not what Do you want to. The absdiff method will instead calculate the absolute values ββof all subtractions, thereby creating more reasonable ones [50,30,60] .
John smith
source share