In the lecture we saw that rotating an image changes the histogram of the image. But what I do not understand is, how does rotating an image changes the histogram of an image ? Don't histograms mean the probability of having a pixel that has the same corresponding intensity value ? How is the location of the pixel connected with the histogram ? (everything in grayscale)
In my head we should always get the same histogram if we have the exact same image with rotation. Here I wrote a code, that plot the histogram of both original and rotated image. Here I get the same histogram even if I am rotating the image.
import cv2
import matplotlib.pyplot as plt
import numpy as np
import imageio
img_input = cv2.imread('dog.png')
img = cv2.cvtColor(img_input, cv2.COLOR_BGR2GRAY)
fig, ax = plt.subplots(1, 2, figsize=(20, 10))
hist, bins = np.histogram(img, bins=255, density=True)
# Show the images
ax[0].set_title('Input Image')
ax[0].imshow(img, cmap='gray')
ax[1].set_title('Histogram')
ax[1].bar(bins[:-1], hist, width=0.05, edgecolor='k'); ## ; to print the unwanted displaying part
img_rotated= cv2.rotate(img,cv2.ROTATE_90_CLOCKWISE)
fig, ax = plt.subplots(1, 2, figsize=(20, 10))
hist_rot, bins_rot = np.histogram(img_rotated, bins=255, density=True)
# Show the images
ax[0].set_title('Input Image Rotated')
ax[0].imshow(img_rotated, cmap='gray')
ax[1].set_title('Histogram')
ax[1].bar(bins[:-1], hist_rot, width=0.05, edgecolor='k'); ## ; to print the unwanted displaying part