Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. from Cimpl import *
  2. # Written by Adam Kahraman.
  3.  
  4. '''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.
  5. '''
  6.  
  7. original_image = load_image(choose_file())
  8. new_image = copy(original_image)
  9.  
  10. def _adjust_components(RGB: int) -> int:
  11.     '''Function does a quadrant check for a RGB value and returns the average value for each quadrant.
  12.    >>>_adjust_components(12)
  13.    31
  14.    >>>_adjust_components(150)
  15.    159
  16.    >>>_adjust_components(100)
  17.    95
  18.    '''
  19.     Q1 = range(192, 256)
  20.     Q2 = range(128, 192)
  21.     Q3 = range(64, 128)
  22.     Q4 = range(0, 64)
  23.    
  24.     average = 0
  25.    
  26.     if RGB in Q1:
  27.         average = 223
  28.     if RGB in Q2:
  29.         average = 159
  30.     if RGB in Q3:
  31.         average = 95
  32.     if RGB in Q4:
  33.         average = 31
  34.     return average
  35.  
  36. def posterize(image: Image) -> Image:
  37.     '''Returns a posterized copy of an image selected when the function calls new_image
  38.    >>>posterize(new_image)
  39.    '''
  40.     new_image = copy(image)
  41.     for x, y, (r, g, b) in image:
  42.         r = _adjust_components(r)
  43.         g = _adjust_components(g)
  44.         b = _adjust_components(b)
  45.         new_color = create_color(r, g, b)
  46.         set_color(new_image, x, y, new_color)      
  47.     return show(new_image)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement