This repository provides an in-depth exploration of Arnold's Cat Map ๐ฑ๐บ๏ธ in the Google Colab environment. Arnold's Cat Map is a chaotic mathematical transformation, and this project enables users to implement, visualize, and analyze its effects on grayscale images. The code includes functionalities for loading images, generating histograms, applying the cat map transformation, and comparing original and transformed images.
import cv2
import numpy as np
import matplotlib.pyplot as plt
import urllib.request
from google.colab.patches import cv2_imshow
from random import randint
from PIL import Image
from PIL import ImageOps
from scipy.stats import Entropy
img = cv2.imdecode(np.asarray(bytearray(urllib.request.urlopen('image_url').read()), dtype=np.uint8), 0)
plt.imshow(img, 'gray')
For example, I used this picture:
def draw_hist(x_axis, input):
figsize = (5, 5)
fig, ax = plt.subplots(figsize=figsize)
plt.bar(x_axis, input, width=input.shape[0] / (x_axis[-1] - x_axis[0] + 1))
return fig, ax
hist = cv2.calcHist([img], [0], None, [256], [0, 256])
plt.hist(img.ravel(), bins=256, range=(0, 256))
plt.title('Grayscale Histogram')
plt.xlabel('Pixel Intensity')
plt.ylabel('Frequency')
plt.show()
The grayscale histogram of our image |
def arnold_cat_map(image, iterations):
# ... (as provided in your original code)
return image
ACMimg = arnold_cat_map(img, 10)
plt.imshow(ACMimg, 'gray')
The transformed image |
hist = cv2.calcHist([ACMimg], [0], None, [256], [0, 256])
plt.subplot(221), plt.imshow(img, 'gray'), plt.title('Original')
plt.subplot(222), plt.imshow(ACMimg, 'gray'), plt.title('Arnolds cat map image')
plt.subplot(223), plt.hist(img.ravel(), bins=256, range=(0, 256)), plt.title('Original histo')
plt.subplot(224), plt.hist(ACMimg.ravel(), bins=256, range=(0, 256)), plt.title('Arnolds cat map histo')
comparing the original photo's histogram with the transformed one |
pixel_probOrg = cv2.calcHist([img], [0], None, [256], [0, 256]) / img.size
pixel_probACM = cv2.calcHist([ACMimg], [0], None, [256], [0, 256]) / ACMimg.size
entropy_valOrg = entropy(pixel_probOrg, base=2)
entropy_valACM = entropy(pixel_probACM, base=2)
print("Entropy of the ORG image:", entropy_valOrg, "\nEntropy of the ACM image:", entropy_valACM)
Follow the provided code snippets to explore and understand the implementation of Arnold's Cat Map. Experiment with different images and iterations and analyze the resulting histograms and entropy values.
Upon analyzing the results of Arnold's Cat Map transformation, it becomes evident that the histogram and entropy values of the transformed image bear remarkable similarities to those of the original image. This intriguing resemblance can be attributed to the deterministic nature of Arnold's Cat Map algorithm.
The visual inspection of histograms reveals a notable correlation between the grayscale distribution of the original and transformed images. The structural integrity of the image is preserved through the cat map transformation, leading to histogram similarities.
The entropy values, a measure of information content, exhibit consistency between the original and transformed images. The deterministic and reversible nature of Arnold's Cat Map ensures that information entropy is maintained, contributing to the observed similarity.
In summary, the preservation of structural features and information entropy underscores the effectiveness of Arnold's Cat Map in maintaining critical characteristics during the transformation process.
This project is licensed under the MIT License. You can use, modify, and distribute the code as the license permits.
Have a cheery coding! ๐พ