Write a function that pinkifies white in a picture. Input a picture

Question:

Write a function that pinkifies white in a picture. Input a picture, then check each pixel to see if the red, green, and blue are all over 100. If so, set that pixel to pink.

Answer:

Program plan:

• Define a python function setpink() that takes an input picture

• Get the red, green and blue component of each pixel of the picture in the for loop

• If the red, green and blue value of the pixel is greater than 100 set the color of the pixel to pink

Program:

************************************************************************

Python function that pinkifies white in a picture

************************************************************************

Define a python function that takes an input picture

def setpink(pic):

Get the red, green and blue component of each pixel of the picture using the for loop

for px in getPixels(pic):

#Get the red, green and blue value of all the pixels of the picture

r = getRed(px)

g = getGreen(px)

b = getBlue(px)

If the red, green and blue value of the pixel is greater than 100 set the color of the pixel to pink

#if the red, green and blue value is greater than 100 set the color of the pixels to pink

if(r >= 100 and g >= 100 and b >= 100):

setColor(px,pink)

Sample Output:

>>>

======= Loading Program =======

>>> f = “barbara.jpg”

>>> p = makePicture(f)

>>> explore(p)

>>>

Output of the picture before running the program:

Output of the picture after running the program:

>>> setpink(p)

>>> explore(p)

>>>

Leave a Comment

Your email address will not be published. Required fields are marked *