Exp 4-7
Exp 4-7
Exp 4-7
[[1 2 2 1]
[2 1 2 1]
[1 2 2 1]
[2 1 2 1]]
[[ 0.5 0.5 0.5 0.5 ]
[ 0.65 0.27 -0.27 -0.65]
[ 0.5 -0.5 -0.5 0.5 ]
[ 0.27 -0.65 0.65 -0.27]]
In [ ]:
localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 1/4
10/5/23, 11:33 AM Untitled1
for y in range(col):
temp_sum+=img_seg[x][y]*cos((2*x+1)*u*pi/(2*row))*cos((2*y+1)*v
temp.append(alpha_fun(u,row)*alpha_fun(v,row)*temp_sum)
dct_eq.append(temp)
return np.round(np.array(dct_eq),2)
print(dct_img(img_seg))
import cv2
import numpy as np
import matplotlib.pyplot as plt
img=cv2.imread('C:/Users/WT LAB/Desktop/BR/download.jpeg',cv2.IMREAD_GRAYSCALE)
img=cv2.resize(img,(550,350))
window='img'
print(img)
print("\n Input image\n")
cv2.imshow(window,img)
cv2.waitKey(0)
cv2.destroyAllWindows()
[[9 9 9 ... 9 9 9]
[9 9 9 ... 9 9 9]
[9 9 9 ... 9 9 9]
...
[7 7 7 ... 8 8 8]
[7 7 7 ... 9 9 9]
[7 7 7 ... 9 9 9]]
Input image
In [5]: img_float=np.float32(img)/255
dct=cv2.dct(img_float)
img_dct=np.clip(np.uint16(dct*255),0,255)
print("we see higher values(white pixels) nearer to[0,0], second half is almost nea
plt.imshow(img_dct,cmap='gray')
we see higher values(white pixels) nearer to[0,0], second half is almost nearer to
0 (black pixels)
<matplotlib.image.AxesImage at 0x24fe612a3d0>
Out[5]:
localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 2/4
10/5/23, 11:33 AM Untitled1
localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 3/4
10/5/23, 11:33 AM Untitled1
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 4/4
Assignment Question
Aim
Generate a 8X8 matrix. For each non overlapping block of size 2X2
submatrices = []
for i in range(0, 8, 2):
for j in range(0, 8, 2):
submatrix = np.array([[matrix_8x8[i][j], matrix_8x8[i][j +
1]],
[matrix_8x8[i + 1][j], matrix_8x8[i + 1]
[j + 1]]])
submatrices.append(submatrix)
for submatrix in submatrices:
print(submatrix)
[[ 1 2]
[ 9 10]]
[[ 3 4]
[11 12]]
[[ 5 6]
[13 14]]
[[ 7 8]
[15 16]]
[[17 18]
[25 26]]
[[19 20]
[27 28]]
[[21 22]
[29 30]]
[[23 24]
[31 32]]
[[33 34]
[41 42]]
[[35 36]
[43 44]]
[[37 38]
[45 46]]
[[39 40]
[47 48]]
[[49 50]
[57 58]]
[[51 52]
[59 60]]
[[53 54]
[61 62]]
[[55 56]
[63 64]]
# mean
for submatrix in submatrices:
sum = 0
for i in range (0,2):
for j in range (0,2):
sum = sum + submatrix[i][j]
print(sum/4)
5.5
7.5
9.5
11.5
21.5
23.5
25.5
27.5
37.5
39.5
41.5
43.5
53.5
55.5
57.5
59.5
s.no|median|maximum|minimum
0 | 2 | 10 | 1
1 | 4 | 12 | 3
2 | 6 | 14 | 5
3 | 8 | 16 | 7
4 | 18 | 26 | 17
5 | 20 | 28 | 19
6 | 22 | 30 | 21
7 | 24 | 32 | 23
8 | 34 | 42 | 33
9 | 36 | 44 | 35
10 | 38 | 46 | 37
11 | 40 | 48 | 39
12 | 50 | 58 | 49
13 | 52 | 60 | 51
14 | 54 | 62 | 53
15 | 56 | 64 | 55
#transpose
for submatrix in submatrices:
print(submatrix.T)
[[ 1 9]
[ 2 10]]
[[ 3 11]
[ 4 12]]
[[ 5 13]
[ 6 14]]
[[ 7 15]
[ 8 16]]
[[17 25]
[18 26]]
[[19 27]
[20 28]]
[[21 29]
[22 30]]
[[23 31]
[24 32]]
[[33 41]
[34 42]]
[[35 43]
[36 44]]
[[37 45]
[38 46]]
[[39 47]
[40 48]]
[[49 57]
[50 58]]
[[51 59]
[52 60]]
[[53 61]
[54 62]]
[[55 63]
[56 64]]
[1, 2, 9, 10]
[3, 4, 11, 12]
[5, 6, 13, 14]
[7, 8, 15, 16]
[17, 18, 25, 26]
[19, 20, 27, 28]
[21, 22, 29, 30]
[23, 24, 31, 32]
[33, 34, 41, 42]
[35, 36, 43, 44]
[37, 38, 45, 46]
[39, 40, 47, 48]
[49, 50, 57, 58]
[51, 52, 59, 60]
[53, 54, 61, 62]
[55, 56, 63, 64]
[[ 1]
[ 2]
[ 9]
[10]]
[[ 3]
[ 4]
[11]
[12]]
[[ 5]
[ 6]
[13]
[14]]
[[ 7]
[ 8]
[15]
[16]]
[[17]
[18]
[25]
[26]]
[[19]
[20]
[27]
[28]]
[[21]
[22]
[29]
[30]]
[[23]
[24]
[31]
[32]]
[[33]
[34]
[41]
[42]]
[[35]
[36]
[43]
[44]]
[[37]
[38]
[45]
[46]]
[[39]
[40]
[47]
[48]]
[[49]
[50]
[57]
[58]]
[[51]
[52]
[59]
[60]]
[[53]
[54]
[61]
[62]]
[[55]
[56]
[63]
[64]]
10/12/23, 11:01 AM exp6
input image
localhost:8889/nbconvert/html/exp6.ipynb?download=false 1/5
10/12/23, 11:01 AM exp6
In [22]: p=1
gamma=0.8
p_img1_L=p*(img1**gamma)
p_img2_L=p*(img2**gamma)
gamma=1
p_img1_E=p*(img1**gamma)
p_img2_E=p*(img2**gamma)
gamma=1.18
p_img1_G=p*(img1**gamma)
p_img2_G=p*(img2**gamma)
show_images([img1,p_img1_L,p_img1_E,p_img1_G ],["input img","r < 1","r=1","r>1"],(1
show_images([img2,p_img2_L,p_img2_E,p_img2_G ],["input img","r < 1","r=1","r>1"],(1
In [23]: p=15
log11= p*np.log(1.0000001 + img1)
log21= p*np.log(1.0000001 + img2)
p=30
log12= p*np.log(1.0000001 + img1)
log22= p*np.log(1.0000001 + img2)
p=55
log13= p*np.log(1.0000001 + img1)
log23= p*np.log(1.0000001 + img2)
show_images([img1,log11,log12,log13],["input img","p=15","p=30","p=55"],(16,25))
show_images([img1,log21,log22,log23],["input img","p=15","p=30","p=55"],(16,25))
localhost:8889/nbconvert/html/exp6.ipynb?download=false 2/5
10/12/23, 11:01 AM exp6
row,col = len(img1),len(img1[0])
res_img1 = []
res_img2 =[]
for i in range(row):
temp1 = []
temp2 = []
for j in range(col):
temp1.append(fg_highlight(1+img1[i][j]))
temp2.append(fg_highlight(1+img2[i][j]))
res_img1.append(temp1)
res_img2.append(temp2)
show_images([img1, res_img1],["input img","fg highlighted image"],(10,10))
show_images([img2, res_img2],["input img","fg highlighted image"],(10,10))
localhost:8889/nbconvert/html/exp6.ipynb?download=false 3/5
10/12/23, 11:01 AM exp6
row,col = len(img1),len(img1[0])
res_img1 = []
res_img2 =[]
for i in range(row):
temp1 = []
temp2 = []
for j in range(col):
temp1.append(section_highlight(1+img1[i][j]))
temp2.append(section_highlight(1+img2[i][j]))
res_img1.append(temp1)
res_img2.append(temp2)
show_images([img1, res_img1],["input img","section highlighted image"],(10,10))
show_images([img2, res_img2],["input img","section highlighted image"],(10,10))
localhost:8889/nbconvert/html/exp6.ipynb?download=false 4/5
10/12/23, 11:01 AM exp6
Result
1.Found the negative of an image. 2.Applied power low transformation for gamma<1,
gamma=1, gamma>1 3.Applied log transformation on an image 4.Highlight certain
specified regions present in an image
localhost:8889/nbconvert/html/exp6.ipynb?download=false 5/5
10/19/23, 10:28 AM experiment 7
1. To perform Mean filtering with filter sizes 3x3, 5x5,7x7 and 11x11
2. To perform Median filtering with filter sizes 3x3, 5x5,7x7 and 11x11
3. Add Gaussian Noise to the image and perform Mean and Median filtering
4. Add Salt & Pepper Noise to the image and perform Mean and Median filtering
Date-19/10/23
Input image
In [16]: filter_sizes = [(3, 3), (5, 5), (7, 7), (11, 11)]
for s in filter_sizes:
im = cv2.blur(img1, s)
show_images([img1, im], ["input", f"{s[0]}x{s[1]} mean filtered"], (8, 8))
In [6]: #Add Gaussian Noise to the image and perform Mean and Median filtering:
import numpy as np
row,col= img1.shape
mean = 0
var = 0.1
sigma = var**0.5
gauss = np.random.normal(mean,sigma,(row,col))
gauss = gauss.reshape(row,col)
In [ ]:
1. Roberts operator
2. Sobel operator
3. Prewitt operator
4. Laplacian operator Date-19/10/23
Input images
import numpy as np
from scipy import ndimage
eb_v=np.array([[1,0],[0,-1]])
rb_h=np.array([[0,1],[-1,0]])
img=np.array(img1,dtype='float')
In [ ]: