Advertisement
czlowiekzgon

Untitled

Apr 13th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 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. zakres = math.ceil(255 / iloscP)
  8. Y = np.zeros(iloscP)
  9. X = [x * zakres for x in range(1, iloscP + 1)]
  10. for x in range(0, iloscP):
  11. for y, z in zip(unique_elements, counts_elements):
  12. if x == 0 and (X[x + 1] > y):
  13. Y[x] = Y[x] + z
  14. elif (x < iloscP - 1) and (X[x + 1] > y) and (X[x] < y):
  15. Y[x] = Y[x] + z
  16. elif (x == iloscP - 1) and (X[x] <= y):
  17. Y[x] = Y[x] + z
  18. return X,Y,unique_elements,counts_elements
  19.  
  20. obraz = plt.imread("kierowca.jpg")
  21. obraz = obraz[:,:,2]
  22. iloscP = 15
  23. zakres = math.ceil(255 / iloscP)
  24. X,Y,uniqueE,countsE = Histogram(obraz,iloscP)
  25.  
  26. plt.subplot(2,6,1)
  27. plt.bar(X,Y,width = zakres,edgecolor='red',align = "edge")
  28. plt.xticks(X,fontsize = 1.5)
  29. plt.subplot(2,6,7)
  30. plt.plot(uniqueE,countsE)
  31.  
  32.  
  33. x1 = (np.where(Y > 1000)[0][0] + 1) * zakres
  34. x2 = (np.where(Y > 1000)[0][-1] + 2) * zakres
  35. a = 150 / (x2 - x1)
  36.  
  37. image = np.array(plt.imread("kierowca.jpg"))
  38. image = image[:,:,2]
  39. image2 = image
  40.  
  41. image2 = np.where(np.logical_or(image < x1 , image > x2),image2,image2 * a )
  42. image2[image < x1] = 0
  43. image2[image > x2] = 255
  44. image2[image2 < 0] = 0
  45. image2[image2 > 255] = 255
  46. Xl,Yl,uniqueEL,countsEL = Histogram(image2,iloscP)
  47. plt.subplot(2,6,2)
  48. plt.bar(Xl,Yl,width = zakres,edgecolor='red',align = "edge")
  49. plt.xticks(Xl,fontsize = 1.5)
  50. plt.subplot(2,6,8)
  51. plt.plot(uniqueEL,countsEL)
  52.  
  53. image2 = image
  54. image2 = np.where(np.logical_or(image < x1 , image > x2),image2,image2 ** 2 )
  55. image2[image < x1] = 0
  56. image2[image > x2] = 255
  57. image2[image2 < 0] = 0
  58. image2[image2 > 255] = 255
  59. Xp,Yp,uniqueEP,countsEP = Histogram(image2,iloscP)
  60. plt.subplot(2,6,3)
  61. plt.bar(Xp,Yp,width = zakres,edgecolor='red',align = "edge")
  62. plt.xticks(Xp,fontsize = 1.5)
  63. plt.subplot(2,6,9)
  64. plt.plot(uniqueEP,countsEP)
  65.  
  66. image2 = image
  67. image2 = np.where(np.logical_or(image < x1 , image > x2),image2,np.sqrt(image2))
  68. image2[image < x1] = 0
  69. image2[image > x2] = 255
  70. image2[image2 < 0] = 0
  71. image2[image2 > 255] = 255
  72. Xs,Ys,uniqueES,countsES = Histogram(image2,iloscP)
  73. plt.subplot(2,6,4)
  74. plt.bar(Xs,Ys,width = zakres,edgecolor='red',align = "edge")
  75. plt.xticks(Xs,fontsize = 1.5)
  76. plt.subplot(2,6,10)
  77. plt.plot(uniqueES,countsES)
  78.  
  79. image2 = image
  80. image2 = np.where(np.logical_or(image < x1 , image > x2),image2,np.log(image2))
  81. image2[image < x1] = 0
  82. image2[image > x2] = 255
  83. image2[image2 < 0] = 0
  84. image2[image2 > 255] = 255
  85. XL,YL,uniqueEL,countsEL = Histogram(image2,iloscP)
  86. plt.subplot(2,6,5)
  87. plt.bar(XL,YL,width = zakres,edgecolor='red',align = "edge")
  88. plt.xticks(XL,fontsize = 1.5)
  89. plt.subplot(2,6,11)
  90. plt.plot(uniqueEL,countsEL)
  91.  
  92. image2 = image
  93. image2 = np.where(np.logical_or(image < x1 , image > x2),image2,image2 ** a)
  94. image2[image < x1] = 0
  95. image2[image > x2] = 255
  96. image2[image2 < 0] = 0
  97. image2[image2 > 255] = 255
  98. Xpa,Ypa,uniqueEPA,countsEPA = Histogram(image2,iloscP)
  99. plt.subplot(2,6,6)
  100. plt.bar(Xpa,Ypa,width = zakres,edgecolor='red',align = "edge")
  101. plt.xticks(Xpa,fontsize = 1.5)
  102. plt.subplot(2,6,12)
  103. plt.plot(uniqueEPA,countsEPA)
  104.  
  105.  
  106.  
  107.  
  108. plt.savefig("graph.svg")
  109. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement