Python exercice. consider the atttached file for further details.   Old-fashioned 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, as shown in the figures below. Original Sepia     Original Image & Sepia Image Write and test a function named sepia that converts a 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 a sepia effect follows. Note that the value for green does not chang

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter7: Input/output Technology
Section: Chapter Questions
Problem 6VE
icon
Related questions
Question
100%
Python exercice.
consider the atttached file for further details.

 

Old-fashioned 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, as shown in the figures below.

Original Sepia
   

Original Image & Sepia Image

Write and test a function named sepia that converts a 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 a sepia effect follows.
Note that the value for green does not change.

(red, green, blue) = image.getPixel(x, y)
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)

 

images.py

To instantiate an image from a file, enter

 

image = Image(aGifFileName)                   

 

To instantiate a blank image, enter

 

image = Image(aWidth, aHeight)

 

Image methods:

 

draw()                          Displays the image in a window 
getWidth()  -> anInt            The width in pixels
getHeight() -> anInt            The height in pixels
getPixel(x, y)  -> (r, g, b)    The RGB values of pixel at x, y
setPixel(x, y, (r, g, b))       Resets pixel at x, y to (r, g, b)
save()                          Saves the image to the current file name
save(aFileName)                 Saves the image to fileName

 

LICENSE: This is open-source software released under the terms of the
GPL (http://www.gnu.org/licenses/gpl.html).
"""

 

import image
def convertSepia(input_image):

 

    grayscale_image=image.EmptyImage(input_image.getWidth(),input_image.getHeight())
    for col in range (input_image.getWidth):
        for row in range(input_image.getHeight()):
            p=input_image.getPixel(col,row)

 

            R=p.getRed()
            G=p.getGreen()
            B=p.getBlue()

 

            newR=(R*1.1+G*0.769+B*0.9)
            newG=(R*1.15+G*0.686+B*0.85)
            newB=(R*1.08+G*0.534+B*0.08)

 

            newpixel=image.Pixel(newR,newG,newB)
            grayscale_image.setPixel(col,row,newpixel)
        
        sepia_image=image.EmptyImage(input_image.getWidth(),input_input_image.getHeight())
        for col in range(input_image.getWidth()):
            for row in range(input_image.getHeight()):
                p=grayscale_image.getPixel(col,row)
                red=p.getRed()
                if red>140:
                    val=(R*0.393+G*0.769+B*0.189)
                else:
                    val=0
                green=p.getGreen()
                if green>140:
                    val=(R*0.349+G*0.686+B*0.168)
                else:
                    val=0
                blue=p.getBlue()
                if Blue>140:
                    val=(R*0.272+G*0.534+B*0.131)
                else:
                    val=0
                newpixel=image.Pixel(val,val,val)
                sepia_image.setPixel(col,row,newpixel)
            return sepia_image
        win=image.ImageWin()img=image.Image ("sepia")
        
        sepia_img=convertSepia(img)sepia_img.draw(win)

 

        win.exitonclick()
images.py
sepia.py
smokey.gif
Transcribed Image Text:images.py sepia.py smokey.gif
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
CMPTR
CMPTR
Computer Science
ISBN:
9781337681872
Author:
PINARD
Publisher:
Cengage
Enhanced Discovering Computers 2017 (Shelly Cashm…
Enhanced Discovering Computers 2017 (Shelly Cashm…
Computer Science
ISBN:
9781305657458
Author:
Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Publisher:
Cengage Learning