Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. from Cimpl import *
  2. #Code written by Adam Kahraman
  3.  
  4.  
  5. '''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.
  6. '''
  7.  
  8. original_image = load_image(choose_file())
  9. new_image = copy(original_image)
  10.  
  11. def grayscale(image: Image) -> Image:
  12.     """Return a grayscale copy of image.
  13.  
  14.    >>> image = load_image(choose_file())
  15.    >>> gray_image = grayscale(image)
  16.    >>> show(gray_image)
  17.    """
  18.     new_image = copy(image)
  19.     for x, y, (r, g, b) in image:
  20.  
  21.         # Use the pixel's brightness as the value of RGB components for the
  22.         # shade of gray. These means that the pixel's original colour and the
  23.         # corresponding gray shade will have approximately the same brightness.
  24.        
  25.         brightness = (r + g + b) // 3
  26.        
  27.         # or, brightness = (r + g + b) / 3
  28.         # create_color will convert an argument of type float to an int
  29.        
  30.         gray = create_color(brightness, brightness, brightness)
  31.         set_color(new_image, x, y, gray)      
  32.     return new_image
  33.  
  34.  
  35.  
  36. def sepia(image: Image) -> Image:
  37.     '''Returns a sepia copy of an image selected when the function calls the grayscale function that is calling new_image.
  38.    >>>sepia(grayscale(new_image))
  39.    '''
  40.     sepia_image = copy(new_image)
  41.     for x, y, (r, g, b) in image:
  42.         if r >= 191:
  43.             b = b * 0.93
  44.             r = r * 1.08
  45.         if r <= 191:
  46.             if r >= 63:
  47.                 b = b * 0.85
  48.                 r = r * 1.15
  49.         if r < 63:
  50.             b = b * 0.9
  51.             r = r * 1.1  
  52.         new_colour = create_color(r, g, b)
  53.         set_color(sepia_image, x, y, new_colour)
  54.     return show(sepia_image)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement