Advertisement
Guest User

Co-Occurrence Matrix

a guest
Oct 17th, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. import numpy as np
  2. file1 = open("contrast.txt","w")
  3. arr = np.zeros((256, 256))
  4. sum = 0
  5. img = Image.open("Ocean_a.bmp")
  6. gray_img = img.convert('L')
  7. for i in range (0,gray_img.size[0]):
  8.     for j in range (0,gray_img.size[1] - 1):
  9.         currPixel = gray_img.getpixel((i, j))
  10.         currPixel1 = gray_img.getpixel((i, j + 1))
  11.         arr[currPixel,currPixel1] = arr[currPixel,currPixel1] + 1;
  12. for i in range (0,arr.shape[0]):
  13.     for j in range (0,arr.shape[1]):
  14.         sum += arr[i,j]*np.power((i-j), 2)
  15. file1.write("Ocean_a.bmp: "+str(sum))
  16. file1.write("\n")
  17. print(sum)
  18. arr = np.zeros((256, 256))
  19. sum = 0
  20. img = Image.open("Ocean_b.bmp")
  21. gray_img = img.convert('L')
  22. for i in range (0,gray_img.size[0]):
  23.     for j in range (0,gray_img.size[1] - 1):
  24.         currPixel = gray_img.getpixel((i, j))
  25.         currPixel1 = gray_img.getpixel((i, j + 1))
  26.         arr[currPixel,currPixel1] = arr[currPixel,currPixel1] + 1;
  27. for i in range (0,arr.shape[0]):
  28.     for j in range (0,arr.shape[1]):
  29.         sum += arr[i,j]*np.power((i-j), 2)
  30. file1.write("Ocean_b.bmp: "+str(sum))
  31. print(sum)
  32. file1.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement