Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Cimpl import *
- # Written by Adam Kahraman.
- '''Program returns the original picture selected and also the original picture with added filter of setting the components of Red and Green to zero while not changing the components of Blue in each pixel. Assuming that the image selected is in the same folder as the program.
- '''
- original_image = load_image(choose_file())
- new_image = copy(original_image)
- def _adjust_components(RGB: int) -> int:
- '''Function does a quadrant check for a RGB value and returns the average value for each quadrant.
- >>>_adjust_components(12)
- 31
- >>>_adjust_components(150)
- 159
- >>>_adjust_components(100)
- 95
- '''
- Q1 = range(192, 256)
- Q2 = range(128, 192)
- Q3 = range(64, 128)
- Q4 = range(0, 64)
- average = 0
- if RGB in Q1:
- average = 223
- if RGB in Q2:
- average = 159
- if RGB in Q3:
- average = 95
- if RGB in Q4:
- average = 31
- return average
- def posterize(image: Image) -> Image:
- '''Returns a posterized copy of an image selected when the function calls new_image
- >>>posterize(new_image)
- '''
- new_image = copy(image)
- for x, y, (r, g, b) in image:
- r = _adjust_components(r)
- g = _adjust_components(g)
- b = _adjust_components(b)
- new_color = create_color(r, g, b)
- set_color(new_image, x, y, new_color)
- return show(new_image)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement