import cv2
import numpy as np
import matplotlib.pyplot as plt

image_path_latest = "******.jpg"
img_latest = cv2.imread(image_path_latest)
height_latest, width_latest, _ = img_latest.shape

output_size_latest = height_latest * 2
canvas_latest = np.zeros((output_size_latest, output_size_latest, 3), dtype=np.uint8)

cx_latest, cy_latest = output_size_latest // 2, output_size_latest // 2

for y in range(height_latest):
    for x in range(width_latest):
        theta = (x / width_latest) * 2 * np.pi
        r = height_latest - y
        new_x = int(cx_latest + r * np.cos(theta))
        new_y = int(cy_latest - r * np.sin(theta))
        if 0 <= new_x < output_size_latest and 0 <= new_y < output_size_latest:
            canvas_latest[new_y, new_x] = img_latest[y, x]

plt.figure(figsize=(8, 8))
plt.imshow(cv2.cvtColor(canvas_latest, cv2.COLOR_BGR2RGB))
plt.title("Custom Polar Mapping (Y→r, X→θ) - Latest Image")
plt.axis("off")
plt.savefig("output.png", dpi=1000, bbox_inches='tight', pad_inches=0)
plt.show()