Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need some help with this Old fashion photographs from the nineteenth century are

ID: 3606589 • Letter: N

Question

Need some help with this

Old fashion photographs from the nineteenth century are not quite black and white and not quite color, but seem to have shades of gray, brown, and blue. This effect is known as sepia. Write and test a function named sepia that converts color image to sepia. This function should first call grayscale to convert the color image to grayscale. A code segment for transforming the grayscale values to achieve effect follows. Note that the value for green does not change.

If red < 63:

     red = int(red * 1.1)

      blue = int(blue * 0.9)

elif red < 192:

       red = int(red * 1.15)

       blue = (blue * 0.85)

else:

        red = min(int(red * 1.08), 255)

      blue = int (blue * 0.93)

Explanation / Answer

The code in python

import Image
  
   def sepia (image, grayscale):
        if red < 63:
            red = int(red * 1.1)
            blue = int(blue * 0.9)
        elif red < 192:
            red = int(red * 1.15)
            blue = int(blue * 0.85)
        else:
            red = min(int(red * 1.08), 255)
            blue = int(blue * 0.93)
           
   def grayscale(image):
        for y in xrange(image.getHeight()):
            for x in xrange(image.getWidth()):
                (r, g, B)/> = image.getPixel(x, y)
                r = int(r * 0.299)
                g = int(g * 0.587)
                b = int(b * 0.114)
                lum = r + g + b
                image.setPixel(x, y, (lum, lum, lum))
       
   def main:
        filename = input("Enter a filename ")
        image = Image(filename)
        print "Close the image window to continue."
        image.draw()
        sepia(image)
        print "Close the image window to quit."
        image.draw()
   main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote