Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- from numpy import asarray
- def local_standardization():
- x = 3
- y = 2
- z = 3
- matrix = []
- # taking 3*2*3 matric from the user as an image input
- for i in range(x):
- matrix.append([])
- for j in range(y):
- matrix[i].append([])
- for k in range(z):
- matrix[i][j].append(input(""))
- pixels=asarray(matrix)
- pixels=pixels.astype('float32')
- #calculate per-channel means and standard deviations
- means=pixels.mean(axis=(0,1),dtype='float64')
- std=pixels.std(axis=(0,1),dtype='float64')
- print('Means(Before Standardization): %s, Stds(Before Standardization): %s' % (means,std))
- #per-channel standardization of pixels
- pixels=(pixels-means)/std
- means=pixels.mean(axis=(0,1),dtype='float64')
- std=pixels.std(axis=(0,1),dtype='float64')
- print('Means(After Standardization): %s, Stds(After Standardization): %s' % (means, std))
- # print(pixels.shape)
- return pixels
- print(local_standardization())
- # sample input([[[111,12,33],
- # [ 44,15,16]],
- # [[ 75,98,19],
- # [120,131,112]],
- # [[ 13,141,15],
- # [ 16,127,183]]])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement