'How to subtract two images in python?

Here is the code I am using, I don't understand how to resolve this error.

import cv2
import imutils
image = cv2.imread(r"D:\mydata\o1\1\original_1_1.png")
image1 = cv2.imread(r"D:\mydata\o1\1\original_1_6.png")
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image1 = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)
image = imutils.resize(image, width=min(400, len(image[0])))
image1 = imutils.resize(image1, width=min(400, len(image1[0])))
result = cv2.absdiff(image1, image)
cv2.imshow(result)
Traceback (most recent call last)

    <ipython-input-10-c242f9498457> in <module>
          7 image = imutils.resize(image, width=min(400, len(image[0])))
          8 image1 = imutils.resize(image1, width=min(400, len(image1[0])))
    ----> 9 result = cv2.absdiff(image1, image)
         10 cv2.imshow(result)

error: OpenCV(3.4.2)
C:\projects\opencv-python\opencv\modules\core\src\arithm.cpp:659:
error: (-209:Sizes of input arguments do not match)

The operation is neither 'array op array' (where arrays have the same
size and the same number of channels), nor 'array op scalar', nor
'scalar op array' in function 'cv::arithm_op'


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source