Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. %jasnosc i kontrast
  2. %
  3. %
  4. %
  5. %
  6. import numpy as np
  7. import matplotlib.pyplot as plt
  8. from scipy import misc as mc
  9.  
  10. def warstwa(img):
  11. r=img[:,:,0]
  12. g=img[:,:,1]
  13. b=img[:,:,2]
  14. s1 = 0.2126*r + 0.7152*g + 0.0722 *b
  15. return s1
  16.  
  17.  
  18. #
  19. def jik():
  20. img2= warstwa(img)
  21. jasnosc=(np.sum(img2))/(M*N)
  22. iloraz= 1.0/(M*N)
  23. kontrast= np.power(iloraz* np.sum(np.power(img2-jasnosc,2)) ,0.5)
  24.  
  25.  
  26. return jasnosc, kontrast
  27.  
  28. #
  29.  
  30.  
  31. img = mc.imread('kierowca.png')
  32.  
  33. print img.dtype
  34. print img.shape
  35. N= img.shape[1]
  36. M= img.shape[0]
  37. print jik()
  38.  
  39. #dla zwyklego unit8
  40. img2= img.copy()
  41. img2 = img2 +150
  42.  
  43. img3= img.copy()
  44. img3= img3 * 2
  45.  
  46. img4 = img.copy()
  47. img4=np.power(img4,0.2)
  48.  
  49. img5 = img.copy()
  50. img4=np.power(img4,2)
  51.  
  52.  
  53.  
  54.  
  55. #dla float64
  56. imgfloat = img.astype('float64')
  57.  
  58. img2float= imgfloat.copy()
  59. img2float = img2float +150
  60.  
  61. img3float= imgfloat.copy()
  62. img3float= img3float * 2
  63.  
  64. img4float = imgfloat.copy()
  65. img4float=np.power(img4float,0.2)
  66.  
  67. img5float = imgfloat.copy()
  68. img5float =np.power(img5float,2)
  69.  
  70. #M= img.shape[0];
  71. #N= img.shape[1];
  72.  
  73. #print jik()
  74. plt.subplot(2,5,1)
  75. plt.imshow(img)
  76.  
  77. plt.subplot(2,5,6)
  78. plt.imshow(imgfloat)
  79.  
  80. plt.subplot(2,5,2)
  81. plt.imshow(img2)
  82.  
  83. plt.subplot(2,5,7)
  84. plt.imshow(img2float)
  85.  
  86. plt.subplot(2,5,3)
  87. plt.imshow(img3)
  88.  
  89. plt.subplot(2,5,8)
  90. plt.imshow(img3float)
  91.  
  92. plt.subplot(2,5,4)
  93. plt.imshow(img4)
  94.  
  95. plt.subplot(2,5,9)
  96. plt.imshow(img4float)
  97.  
  98. plt.subplot(2,5,5)
  99. plt.imshow(img5)
  100.  
  101. plt.subplot(2,5,10)
  102. plt.imshow(img5float)
  103.  
  104.  
  105.  
  106. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement