Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- from scipy import misc as mc
- def getHist(img, n):
- H = np.zeros(n)
- width, height = img[:,:].shape
- space = np.linspace(0, 255, n+1);
- #print space
- for i in range(0, n):
- boolM = ( ((img[:,:] >= space[i]) & (img[:,:] < space[i+1])) | ((space[i+1]==255) & (img[:,:] >= space[i]) & (img[:,:] <= space[i+1])) )
- H[i] = np.sum(boolM)
- return H
- def getProperties(img):
- width, height = img[:,:,0].shape;
- brightness = float(np.sum(img[:,:,0]))/(width*height)
- contrastMat = img[:,:,0]-brightness
- contrastMat = contrastMat * contrastMat
- contrast = np.sqrt(float(np.sum(contrastMat))/(width*height))
- return brightness, contrast
- #
- A = np.array([[1, 0, 0.25], [1, 0.75, 0.5], [1, 0.5, 0.25]]) * 255.0
- print getHist( A, 3 ) # [3 2 4]
- print getHist( A, 5 ) # [1 2 2 1 3]
- img = mc.imread('lab2.png')
- img = img.astype("float64")
- H = getHist(img[:,:,0],11)
- plt.subplot(1,2,1)
- plt.bar(range(len(H)), H);
- img = img/255
- plt.subplot(1,2,2)
- plt.imshow(img)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement