# Local Standardization from the input of an Image Array

Jul 23rd, 2021
1,402
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #!/usr/bin/python3
2.
3. from numpy import asarray
4.
5. def local_standardization():
6.     x = 3
7.     y = 2
8.     z = 3
9.     matrix = []
10.     # taking 3*2*3 matric from the user as an image input
11.     for i in range(x):
12.         matrix.append([])
13.         for j in range(y):
14.             matrix[i].append([])
15.             for k in range(z):
16.                 matrix[i][j].append(input(""))
17.     pixels=asarray(matrix)
18.     pixels=pixels.astype('float32')
19.     #calculate per-channel means and standard deviations
20.     means=pixels.mean(axis=(0,1),dtype='float64')
21.     std=pixels.std(axis=(0,1),dtype='float64')
22.     print('Means(Before Standardization): %s, Stds(Before Standardization): %s' % (means,std))
23.     #per-channel standardization of pixels
24.     pixels=(pixels-means)/std
25.     means=pixels.mean(axis=(0,1),dtype='float64')
26.     std=pixels.std(axis=(0,1),dtype='float64')
27.     print('Means(After Standardization): %s, Stds(After Standardization): %s' % (means, std))
28.     # print(pixels.shape)
29.     return pixels
30. print(local_standardization())
31.
32.
33.
34. # sample input([[[111,12,33],
35. #         [ 44,15,16]],
36. #         [[ 75,98,19],
37. #         [120,131,112]],
38. #         [[ 13,141,15],
39. #         [ 16,127,183]]])
40.
RAW Paste Data