I have designed a program that compares two images and gives you the coordinates of the pixels that are different in both images and plots the using pygame. I do not mind having to use another library or to remake my whole code but it should ideally take less that 0.6s to process and it should not reduce file size, all I need it to do is to return the coordinates relative to the image
My code:
import cv2
import pygame
from pygame.locals import *
import time
lib = 'Map1.png'
lib2 = 'Map2.png'
lib3 = ()
coordenatesx = ()
coordenatesy = ()
Read = list(cv2.imread(lib).astype("int"))
Read2 = list(cv2.imread(lib2).astype("int"))
counter = 0
pygame.init()
flags = DOUBLEBUF
screen = pygame.display.set_mode((500,500), flags, 4)
start = time.process_time()#To tell me how long it takes
for y in range(len(Read)):#y coords
for x in range(len(Read[y])):#x coords
all = list(Read[y][x])[0]
all2 = list(Read2[y][x])[0]
difference = (all)-(all2)
if difference > 10 or difference < -10: #To see if the pixel's difference is in the boundary if not it is different and it gets plotted
counter+=1
pygame.draw.rect(screen, (255, 0, 0), pygame.Rect(x, y, 1, 1))
pygame.display.update()
print(time. process_time() - start)
if counter >= (y * x) * 0.75:
print('They are similar images')
print('They are different by only :', str((counter / (y * x)) * 100), '%')
else:
print('They are different')
print('They are different by:', str((counter / (y * x)) * 100), '%')
pygame.display.update()
| image1 | image2 |
|---|---|
![]() |
![]() |

