# Program 8: Read an image and display it using Python
# photo.jpg must be in the same folder as this program.

import cv2
import matplotlib.pyplot as plt

image = cv2.imread("photo.jpg")

# OpenCV stores colours in the order Blue, Green, Red (BGR).
# Matplotlib expects Red, Green, Blue (RGB), so the order is swapped.
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

plt.figure(figsize=(8, 4.5))
plt.subplot(1, 2, 1)
plt.imshow(image)
plt.title("Shown as BGR (colours wrong)")
plt.axis("off")
plt.subplot(1, 2, 2)
plt.imshow(image_rgb)
plt.title("Converted to RGB (correct)")
plt.axis("off")
plt.show()

print("Image read successfully")
