Advertisement
Guest User

Untitled

a guest
May 16th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from scipy import misc as mc
  4.  
  5. def normalizacja(count,image):
  6. offset=255.0/count
  7. output = np.zeros((image.shape[0],image.shape[0]))
  8. i = 0
  9. tmp = 0
  10. while (i < 255.0):
  11. for j in range (0,image.shape[0]):
  12. for k in range (0,image.shape[1]):
  13. if (image[j][k] > i and image[j][k] <= i+offset):
  14. output[j][k] = tmp
  15. tmp = tmp+1
  16. i=i+offset
  17. return output
  18.  
  19.  
  20.  
  21. def rgb2gray(img):
  22. r = img[:, :, 0]
  23. g = img[:, :, 1]
  24. b = img[:, :, 2]
  25. s1 = 0.2126 * r + 0.7152 * g + 0.0722 * b
  26. return s1
  27.  
  28. def test(img, dlx, dly):
  29. P = np.max(img).astype(int)+1
  30. C = np.zeros((P,P))
  31. wysokosc=len(img)
  32. szerokosc=len(img[0])
  33.  
  34. for i in range (0,wysokosc-dlx):
  35. for j in range (0,szerokosc-dly):
  36. x=img[i,j]
  37. x=x.astype(int)
  38. y=img[i+dlx,j+dly]
  39. y=y.astype(int)
  40. C[x,y] = C[x,y]+1
  41. return C
  42.  
  43. liczba_przedzialow = 255
  44.  
  45. img = mc.imread('oko1.png')
  46. img = rgb2gray(img)
  47. img = normalizacja(liczba_przedzialow, img)
  48. img2 = mc.imread('oko2.png')
  49. img2 = rgb2gray(img2)
  50. img2 = normalizacja(liczba_przedzialow, img2)
  51.  
  52.  
  53.  
  54. plt.subplot(2, 2, 1);
  55. plt.imshow(img, cmap=plt.cm.gray, vmin=0, vmax=liczba_przedzialow)
  56. plt.title("oko1.png")
  57. plt.subplot(2, 2, 2);
  58. plt.imshow(test(img, 0, 1), cmap=plt.cm.gray, vmin=0, vmax=liczba_przedzialow)
  59. plt.title("macierz wspowwystepowania oko1.png")
  60.  
  61.  
  62. plt.subplot(2, 2, 3);
  63. plt.imshow(img2, cmap=plt.cm.gray, vmin=0, vmax=liczba_przedzialow)
  64. plt.title("oko2.png")
  65. plt.subplot(2, 2, 4);
  66. plt.imshow(test(img2, 0, 1), cmap=plt.cm.gray, vmin=0, vmax=liczba_przedzialow)
  67. plt.title("macierz wspowwystepowania oko2.png")
  68.  
  69. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement