Advertisement
czlowiekzgon

Untitled

Apr 18th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.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. 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] > 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 = 10)
  29. #plt.subplot(2,6,7)
  30.  
  31. plt.show()
  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. # image2 = image[:,:,2]
  39. # mean = np.mean(image)
  40. #
  41. # unique_elements, counts_elements = np.unique(image2, return_counts=True)
  42. # cumulativeSumCounts = np.cumsum(counts_elements)
  43. # for x,y in zip(unique_elements,cumulativeSumCounts):
  44. # image2[image2 == x] = ((y - min(cumulativeSumCounts)) * 255)/ (np.size(image2))
  45. # X,Y,uniqueE,countsE = Histogram(image2,iloscP)
  46. # plt.bar(X,Y,width = zakres,edgecolor='red',align = "edge")
  47. # plt.xticks(X,fontsize = 10)
  48. # plt.show()
  49. # image2 = np.where(np.logical_or(image < x1 , image > x2),image2,image2 * a )
  50. # image2[image < x1] = 0
  51. # image2[image > x2] = 255
  52. # image2[image2 < 0] = 0
  53. # image2[image2 > 255] = 255
  54. # Xl,Yl,uniqueEL,countsEL = Histogram(image2,iloscP)
  55. # plt.subplot(2,6,2)
  56. # plt.bar(Xl,Yl,width = zakres,edgecolor='red',align = "edge")
  57. # plt.xticks(Xl,fontsize = 1.5)
  58. # plt.subplot(2,6,8)
  59. # plt.plot(uniqueEL,countsEL)
  60. #
  61. # image2 = image
  62. # image2 = np.where(np.logical_or(image < x1 , image > x2),image2,image2 ** 2 )
  63. # image2[image < x1] = 0
  64. # image2[image > x2] = 255
  65. # image2[image2 < 0] = 0
  66. # image2[image2 > 255] = 255
  67. # Xp,Yp,uniqueEP,countsEP = Histogram(image2,iloscP)
  68. # plt.subplot(2,6,3)
  69. # plt.bar(Xp,Yp,width = zakres,edgecolor='red',align = "edge")
  70. # plt.xticks(Xp,fontsize = 1.5)
  71. # plt.subplot(2,6,9)
  72. # plt.plot(uniqueEP,countsEP)
  73. #
  74. # image2 = image
  75. # image2 = np.where(np.logical_or(image < x1 , image > x2),image2,np.sqrt(image2))
  76. # image2[image < x1] = 0
  77. # image2[image > x2] = 255
  78. # image2[image2 < 0] = 0
  79. # image2[image2 > 255] = 255
  80. # Xs,Ys,uniqueES,countsES = Histogram(image2,iloscP)
  81. # plt.subplot(2,6,4)
  82. # plt.bar(Xs,Ys,width = zakres,edgecolor='red',align = "edge")
  83. # plt.xticks(Xs,fontsize = 1.5)
  84. # plt.subplot(2,6,10)
  85. # plt.plot(uniqueES,countsES)
  86. #
  87. # image2 = image
  88. # image2 = np.where(np.logical_or(image < x1 , image > x2),image2,np.log(image2))
  89. # image2[image < x1] = 0
  90. # image2[image > x2] = 255
  91. # image2[image2 < 0] = 0
  92. # image2[image2 > 255] = 255
  93. # XL,YL,uniqueEL,countsEL = Histogram(image2,iloscP)
  94. # plt.subplot(2,6,5)
  95. # plt.bar(XL,YL,width = zakres,edgecolor='red',align = "edge")
  96. # plt.xticks(XL,fontsize = 1.5)
  97. # plt.subplot(2,6,11)
  98. # plt.plot(uniqueEL,countsEL)
  99. #
  100. # image2 = image
  101. # image2 = np.where(np.logical_or(image < x1 , image > x2),image2,image2 ** a)
  102. # image2[image < x1] = 0
  103. # image2[image > x2] = 255
  104. # image2[image2 < 0] = 0
  105. # image2[image2 > 255] = 255
  106. # Xpa,Ypa,uniqueEPA,countsEPA = Histogram(image2,iloscP)
  107. # plt.subplot(2,6,6)
  108. # plt.bar(Xpa,Ypa,width = zakres,edgecolor='red',align = "edge")
  109. # plt.xticks(Xpa,fontsize = 1.5)
  110. # plt.subplot(2,6,12)
  111. # plt.plot(uniqueEPA,countsEPA)
  112. #
  113. #
  114. #
  115. #
  116. # plt.savefig("graph.svg")
  117. # plt.show()
  118. # image = np.array(plt.imread("kierowca.jpg"))
  119. # image2 = image[:,:,2]
  120. # mean = np.mean(image)
  121. #
  122. #
  123. # cumulativeSumCounts = np.cumsum(Y)
  124. # cumulativeSumCounts = cumulativeSumCounts / np.size(image2)
  125. #
  126. # indexMIN = np.where(cumulativeSumCounts > 0)[0][0]
  127. # valMin = cumulativeSumCounts[indexMIN]
  128. # newX = []
  129. # for x, y in zip(X,cumulativeSumCounts):
  130. # newX.append(((y - valMin) / (1 - valMin) ) * iloscP)
  131. # print(newX)
  132. # unique_elements, counts_elements = np.unique(image2, return_counts=True)
  133. # cumulativeSumCounts = np.cumsum(counts_elements)
  134. # for x,y in zip(unique_elements,cumulativeSumCounts):
  135. # image2[image2 == x] = ((y - min(cumulativeSumCounts)) * 255)/ (np.size(image2))
  136. # X,Y,uniqueE,countsE = Histogram(image2,iloscP)
  137. # plt.bar(X,Y,width = zakres,edgecolor='red',align = "edge")
  138. # plt.xticks(X,fontsize = 10)
  139. # plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement