Advertisement
czlowiekzgon

Untitled

Apr 28th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import math
  4. import collections
  5. def Histogram(obraz,iloscP):
  6. unique_elements, counts_elements = np.unique(obraz, return_counts=True)
  7. uniqueElements = np.arange(256)
  8. countsElements = np.zeros(256)
  9. for x,y in zip(unique_elements, counts_elements):
  10. countsElements[int(x)] = int(y)
  11.  
  12. zakres = math.ceil(255 / iloscP)
  13. X = np.zeros(iloscP)
  14. Y = np.zeros(iloscP)
  15. for i,val in zip(range(iloscP),np.array_split(uniqueElements, iloscP)):
  16. X[i] = val[-1]
  17. for i,countsPix in zip(range(iloscP),np.array_split(countsElements, iloscP)):
  18. Y[i] = np.sum(countsPix)
  19.  
  20.  
  21. return X,Y,uniqueElements,countsElements
  22.  
  23.  
  24.  
  25.  
  26. obraz = plt.imread("kierowca.jpg")
  27. obraz = obraz[:,:,2]
  28. iloscP = 256
  29. zakres = math.ceil(255 / iloscP)
  30. X,Y,uniqueE,countsE = Histogram(obraz,iloscP)
  31.  
  32.  
  33. x1 = X[np.where(Y > 1000)[0][0]]
  34. x2 = X[np.where(Y > 1000)[0][-1]]
  35.  
  36. def Rozciganie(obraz):
  37. image2 = obraz
  38. size = image2.size
  39. unique_elements, counts_elements = np.unique(obraz, return_counts=True)
  40. uniqueElements = np.arange(256)
  41. countsElements = np.zeros(256)
  42. for x, y in zip(unique_elements, counts_elements):
  43. countsElements[int(x)] = int(y)
  44.  
  45. cumulativeSumCounts = np.cumsum(countsE)
  46. valMin = cumulativeSumCounts[np.where(cumulativeSumCounts > 0)[0][0]]
  47.  
  48. for x,y in zip(uniqueE,cumulativeSumCounts):
  49. image2 = np.where(obraz == x,round(( ((y - valMin))/ (size - valMin )) * 255),image2)
  50.  
  51. return image2
  52.  
  53. image2 = Rozciganie(obraz)
  54.  
  55. X,Y,uniqueE,countsE = Histogram(image2,iloscP)
  56. plt.imshow(image2)
  57. #plt.bar(X,Y)
  58. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement