Python script:
import cv2 as cv
import pandas as pd
import itertools
import numpy as np
imgfile = "old_image.png"
image = cv.imread(imgfile)
# Convert the image from BGR (OpenCV's default) to RGB
image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
height, width, _ = image.shape
pixel_data = []
for y in range(height):
for x in range(width):
r, g, b = image[y, x]
pixel_data.append((x, y, r, g, b))
df = pd.DataFrame(pixel_data, columns=["x", "y", "red", "green", "blue"])
# print(df)
columns_to_mix = ["x", "y", "red", "green"]
# Generate all permutations
permutations = list(itertools.permutations(columns_to_mix))
print(permutations)
images = []
for perm in permutations:
permuted_df = df[list(perm) + ["blue"]]
permuted_df.columns = ["x", "y", "red", "green", "blue"]
print(permuted_df)
# Reconstruct the image
permuted_image = np.zeros((height, width, 3), dtype=np.uint8)
for _, row in permuted_df.iterrows():
x, y, r, g, b = int(row["x"]), int(row["y"]), int(row["red"]), int(row["green"]), int(row["blue"])
permuted_image[y, x] = [r, g, b]
images.append(permuted_image)
# Navigation loop to display images
current_index = 0
threshold = 90 # Tweak this if QR code is not detected
while True:
# Convert the image to black and white
gray_image = cv.cvtColor(images[current_index], cv.COLOR_RGB2GRAY)
_, binary_image = cv.threshold(gray_image, threshold, 255, cv.THRESH_BINARY)
cv.imshow("Permuted Image - B/W", binary_image)
print(f"Showing image {current_index + 1} of {len(images)}")
key = cv.waitKey(0) & 0xFF
if key == 27: # ESC key to exit
break
elif key == 81: # Left arrow key
current_index = (current_index - 1) % len(images)
elif key == 83: # Right arrow key
current_index = (current_index + 1) % len(images)
cv.destroyAllWindows()