-
Complete image is below Want to find the coordinates of the grey missing part. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
At first, I wanted to suggest from PIL import Image, ImageChops
with Image.open("complete.png") as complete:
with Image.open("missing.jpg") as missing:
delta = ImageChops.subtract_modulo(complete.convert("RGB"), missing)
print(delta.getbbox()) However, while your first image is a PNG, your second image is a JPEG. Because JPEG is a lossy format, when your image was saved as a JPEG file, subtle changes would have been created, meaning that a simple comparison cannot be made. Instead, the comparison needs to include a threshold. from PIL import Image, ImageChops
with Image.open("complete.png") as complete:
with Image.open("missing.jpg") as missing:
complete_l = complete.convert("L")
missing_l = missing.convert("L")
def check(x, y):
return abs(complete_l.getpixel((x, y)) - missing_l.getpixel((x, y))) > 3
coords = []
for x in range(complete.width):
for y in range(complete.height):
if check(x, y):
coords.append(x)
break
if len(coords) == 1:
break
for y in range(complete.height):
for x in range(complete.width):
if check(x, y):
coords.append(y)
break
if len(coords) == 2:
break
for x in reversed(range(complete.width)):
for y in range(complete.height):
if check(x, y):
coords.append(x)
break
if len(coords) == 3:
break
for y in reversed(range(complete.height)):
for x in range(complete.width):
if check(x, y):
coords.append(y)
break
if len(coords) == 4:
break
print(coords) This code prints |
Beta Was this translation helpful? Give feedback.
-
Thank you. |
Beta Was this translation helpful? Give feedback.
At first, I wanted to suggest
However, while your first image is a PNG, your second image is a JPEG. Because JPEG is a lossy format, when your image was saved as a JPEG file, subtle changes would have been created, meaning that a simple comparison cannot be made.
Instead, the comparison needs to include a threshold.