-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpixel_diff.py
More file actions
27 lines (23 loc) · 1.2 KB
/
pixel_diff.py
File metadata and controls
27 lines (23 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import numpy as np
from PIL import Image
# open images
image_1 = Image.open("test_images/rgb_test_image.png")
image_2 = Image.open("super_secret_14.png")
width = image_1.width
height = image_1.height
count = 0
labels = ["red", "green", "blue"]
# Convert the images to a NumPy arrays
image_array_1 = np.array(image_1.getdata())
pixels, color_channels = image_array_1.shape
image_array_2 = np.array(image_2.getdata())
print(f"Image is w:{width}, h:{height} {pixels} pixels {color_channels} color channels")
for pixel in range(len(image_array_1)):
for color_channel in range(color_channels):
if image_array_1[pixel][color_channel] != image_array_2[pixel][color_channel]:
print(f"{str(pixel // width).rjust(3)}, {str(pixel % width).rjust(3)}", end=" ")
print(f"{str(labels[color_channel]).rjust(5)}", end=" ")
print(f"({str(image_array_1[pixel][0]).rjust(3)}, {str(image_array_1[pixel][1]).rjust(3)},{str(image_array_1[pixel][2]).rjust(3)})", end = "")
print(f" - ({str(image_array_2[pixel][0]).rjust(3)}, {str(image_array_2[pixel][1]).rjust(3)},{str(image_array_2[pixel][2]).rjust(3)})")
count += 1
print(f"Summary: {count} pixels changed by 1 bit")