Python Image Pixels Assignment

Refer to the notes and official PIL documentation for help.

https://www.nemoquiz.com/python/#images

https://pillow.readthedocs.io/en/stable/reference/Image.html

Practice Tasks

1) Create a new image using Image.new(), then create a pixels object using Image.load(). Iterate through all of the pixels to make them all random colors. Import random and use random.randint().

2) Create another image with mode “L” and make a vertical gradient, from dark to light. The pixels at the top should be zero and the pixels at the bottom should be 255. Make the image 256 pixels tall so the loop will be easier to figure out.

3) Use your gradient from the previous part to blend two images together smoothly from top to bottom. Load two images, resize them to the same size, and resize your gradient to be the same size as the others. Use the paste function to copy one image onto the other, with the gradient as the mask.

4) Open another existing image and create a pixels object using Image.load(). Iterate through all of its pixels and save images with the following modifications:

4a) Set the green and blue values to zero while preserving the red.

4b) Switch all of the color values around to make a weird color image.

4c) Make a negative by changing color values from x to (255 – x).

5) Pick any image and iterate through only a centered rectangle of pixels. Use the range function, but do not iterate through the full height and width. Make a modification of your choice to that area (make it grayscale, change the colors, darken it, etc)

6) Pick a small image and paste a repeating row of that image onto a background in a straight line. Use a for loop with the paste function called inside the for loop. Paste the images so that there is a bit of space between each copy of the image.

7) Find a color image of a person or object and remove its background using a website such as remove.bg. Upload the original image AND the transparent background version. Next, create a black and white version of this image. Finally, create a final version of this image in which only the person is in color, and the background is black and white. You will need to paste the color image onto the black and white image.

(You can create a grayscale image by setting every pixel equal to the average value of the three RGB color values.
For example, (250, 150, 200) would become (200, 200, 200).)