Computer Vision Lab Exp 1
Group Members:
2K19/IT/008 (Akaash Nidhiss)
2K19/IT/018 (Anasuya Mithra)
2K19/SE/003 (Ahmad Habib Khan)
2K19/CO/068 (Anshuman Roy)
Aim:
Draw Probability density functions.
Take a given image or Hand drawing with black pen and apply these PDFs to 3x3 matrix of the given
image. Also compute histogram of the Image Gradients.
Code:
import cv2
import numpy as np
import matplotlib.pyplot as plt
# Lenna.png image produced by Ahmad Khan (2K19/SE/003)
img = cv2.imread("Lenna.png")[0:510, 0:510]
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray1 = np.copy(gray)
gray2 = np.copy(gray)
gray3 = np.copy(gray)
x = np.linspace(0, 1, 510)
p = 0.4
lam = 0.7
mean = 0.53
dev = 0.14
y = [((dev*np.sqrt(2*np.pi))**(-1))*np.exp(-(i - mean)**2/(2 * dev**2))
for i in x]
y = [i/max(y) for i in y]
ex = [np.exp(i) for i in x]
bern = [p**i/(1 - p)**(1 - i) for i in x]
# e^x distribution made by Ahmad Khan (2K19/SE/003)
for i in range(len(gray1)):
for j in range(len(ex)):
gray1[j][i] *= ex[i]
# bernoulli distribution made by Anshuman Roy (2K19/CO/068)
for i in range(len(gray2)):
for j in range(len(bern)):
gray2[j][i] *= bern[i]
# normal distribution made by Anshuman Roy (2K19/CO/068)
for i in range(len(gray3)):
for j in range(len(y)):
gray3[j][i] *= y[i]
plt.imshow(gray,cmap = 'gray')
plt.show()
plt.imshow(gray1,cmap = 'gray')
plt.show()
plt.imshow(gray2,cmap = 'gray')
plt.show()
plt.imshow(gray3,cmap = 'gray')
plt.show()
windowsize_r = 170
windowsize_c = 170
# histogram made by Akaash Nidhiss (2K19/IT/008) and Anasuya Mithra
(2K19/IT/018)
tiles = []
for r in range(0,gray.shape[0], windowsize_r):
for c in range(0,gray.shape[1], windowsize_c):
window = gray[r:r+windowsize_r,c:c+windowsize_c]
tiles.append(window)
for image in tiles:
freq = [0]*256
pixels = image.flatten()
for i in pixels:
freq[i] += 1
x = [i for i in range(256)]
plt.plot(x, freq)
plt.show()
Output:
1)
e^x distribution:
2)
bernoulli distribution:
3)
normal distribution:
4)
Histograms:
5)
6)
7)
8)
9)
10)
11)
12)
13)
Conclusion:
When we apply the various probability density functions, such as e^x, bernoulli’s and Normal/Gaussian
distribution, from the series of gray colour mapped images obtained, we see how the magnitude of each
pixel was multiplied by the pdf function applied to it.
Using this, we then produce 9 histograms by dividing the image into 9 parts, and each histogram maps
out the frequency of every pixel intensity in that window tile.