# Image difference after Image registration and alignment

**URL:** <https://forum.opencv.org/t/image-difference-after-image-registration-and-alignment/10553>\
**Category:** Python\
**Created:** [October 14, 2022, 9:50am UTC](https://forum.opencv.org/t/image-difference-after-image-registration-and-alignment/10553 "2022-10-14T09:50:25Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Tanu](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@Tanu](https://forum.opencv.org/u/Tanu)\
**Post date:** [October 27, 2022, 5:03pm UTC](https://forum.opencv.org/t/image-difference-after-image-registration-and-alignment/10553/6 "2022-10-27T17:03:10Z")

</div>

I have two images which are similar but one image is having lighter shade of color compared to other. When I try to get difference between two images everything is shown as different even though objects are just having different shades of gray color. Is there any way to ignore the color / shade difference while finding difference?

Code:

imageA = cv2.imread(“Image1.png”)  
imageB = cv2.imread(“Image2.png”)

grayA = cv2.cvtColor(imageA, cv2.COLOR\_BGR2GRAY)  
grayB = cv2.cvtColor(imageB, cv2.COLOR\_BGR2GRAY)

diff = cv2.absdiff(grayA, grayB)

thresh = cv2.threshold(diff, 0, 255, cv2.THRESH\_BINARY\_INV | cv2.THRESH\_OTSU)[1]  
cnts = cv2.findContours(thresh.copy(), cv2.RETR\_EXTERNAL, cv2.CHAIN\_APPROX\_SIMPLE)  
cnts = imutils.grab\_contours(cnts)

for c in cnts:  
(x, y, w, h) = cv2.boundingRect(c);  
cv2.rectangle(imageA, (x, y), (x + w, y + h), (0, 0, 255), 2)

cv2.imwrite(“result.png”, imageA)

 ![Image1](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/9/995eaba30302e06083f89d0dab4f4e9283ad5ffe.jpeg)

 ![Image2](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/7/7c6faa4442fc202e04a779f9982a5ea577947947.png)

 ![bailey-Difference](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/4/4ea9d887a772386ad2b7b24e918b1e27d2ad5478.jpeg)

Appreciate the help.

---

_[View the full topic](https://forum.opencv.org/t/image-difference-after-image-registration-and-alignment/10553)._
