Advertisement
Guest User

Contrast Algorithm

a guest
Oct 17th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. def change_contrast(A, B, C, D, out_image_name):
  2.     img = Image.open("Ocean.bmp").convert('L')
  3.     gray_img = img.copy()
  4.     for i in range (0,img.size[0]):
  5.         for j in range (0,img.size[1]):
  6.             currPixel= img.getpixel((i, j))
  7.             m = 0
  8.             b = 0
  9.             if(currPixel <= A):
  10.                 m = (B-0)/(A-0)
  11.                 b = B - int(m * A)
  12.             elif(currPixel <= C):
  13.                 m = (D-B)/(C-A)
  14.                 b = D - int(m * C)
  15.                 #print(b)
  16.             else:
  17.                 m = (255-D)//(255-C)
  18.                 b = 255 - int(m * 255)
  19.             resultedPixel = int(m * (currPixel)) + b
  20.             gray_img.putpixel((i,j),(resultedPixel))
  21.     plt.imshow(gray_img, cmap="gray")
  22.     gray_img.save(out_image_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement