Function to change contrast
(img: Image, level: int)
| 12 | |
| 13 | |
| 14 | def change_contrast(img: Image, level: int) -> Image: |
| 15 | """ |
| 16 | Function to change contrast |
| 17 | """ |
| 18 | factor = (259 * (level + 255)) / (255 * (259 - level)) |
| 19 | |
| 20 | def contrast(c: int) -> int: |
| 21 | """ |
| 22 | Fundamental Transformation/Operation that'll be performed on |
| 23 | every bit. |
| 24 | """ |
| 25 | return int(128 + factor * (c - 128)) |
| 26 | |
| 27 | return img.point(contrast) |
| 28 | |
| 29 | |
| 30 | if __name__ == "__main__": |