Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- file1 = open("contrast.txt","w")
- arr = np.zeros((256, 256))
- sum = 0
- img = Image.open("Ocean_a.bmp")
- gray_img = img.convert('L')
- for i in range (0,gray_img.size[0]):
- for j in range (0,gray_img.size[1] - 1):
- currPixel = gray_img.getpixel((i, j))
- currPixel1 = gray_img.getpixel((i, j + 1))
- arr[currPixel,currPixel1] = arr[currPixel,currPixel1] + 1;
- for i in range (0,arr.shape[0]):
- for j in range (0,arr.shape[1]):
- sum += arr[i,j]*np.power((i-j), 2)
- file1.write("Ocean_a.bmp: "+str(sum))
- file1.write("\n")
- print(sum)
- arr = np.zeros((256, 256))
- sum = 0
- img = Image.open("Ocean_b.bmp")
- gray_img = img.convert('L')
- for i in range (0,gray_img.size[0]):
- for j in range (0,gray_img.size[1] - 1):
- currPixel = gray_img.getpixel((i, j))
- currPixel1 = gray_img.getpixel((i, j + 1))
- arr[currPixel,currPixel1] = arr[currPixel,currPixel1] + 1;
- for i in range (0,arr.shape[0]):
- for j in range (0,arr.shape[1]):
- sum += arr[i,j]*np.power((i-j), 2)
- file1.write("Ocean_b.bmp: "+str(sum))
- print(sum)
- file1.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement