Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def change_contrast(A, B, C, D, out_image_name):
- img = Image.open("Ocean.bmp").convert('L')
- gray_img = img.copy()
- for i in range (0,img.size[0]):
- for j in range (0,img.size[1]):
- currPixel= img.getpixel((i, j))
- m = 0
- b = 0
- if(currPixel <= A):
- m = (B-0)/(A-0)
- b = B - int(m * A)
- elif(currPixel <= C):
- m = (D-B)/(C-A)
- b = D - int(m * C)
- #print(b)
- else:
- m = (255-D)//(255-C)
- b = 255 - int(m * 255)
- resultedPixel = int(m * (currPixel)) + b
- gray_img.putpixel((i,j),(resultedPixel))
- plt.imshow(gray_img, cmap="gray")
- gray_img.save(out_image_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement