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
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
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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.
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()
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
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
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education