enlarge.py """ File: enlarge.py Project 7.11 Defines and tests a function to enlarge an image. """ from images import Image def enlarge(imag
enlarge.py """ File: enlarge.py Project 7.11 Defines and tests a function to enlarge an image. """ from images import Image def enlarge(imag
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
enlarge.py |
"""
File: enlarge.py
Project 7.11
Defines and tests a function to enlarge an image.
"""
from images import Image
def enlarge(image, factor):
"""Builds and returns a copy of the image which is larger
by the factor."""
def block_copy_pixel_to(image, row_index, line, pixel_to_copy, factor):
for x in range(factor):
for y in range(factor):
image.setPixel(row_index + x, line + y, pixel_to_copy)
old_height = image.getHeight()
old_width = image.getWidth()
new_height = old_height * factor
new_width = old_width * factor
new_image = Image(new_width, new_height)
nhi = 0 # new height index
for ohi in range(old_height): # original image height index
# new left & right indices
nli = 0
nri = new_width - 1
# original left & right indices
oli = 0
ori = old_width - 1
# Copy blocks of the same pixel to the new image
while oli < ori:
old_left_pixel = image.getPixel(oli, ohi)
block_copy_pixel_to(new_image, nli, nhi, old_left_pixel, factor)
old_right_pixel = image.getPixel(ori, ohi)
block_copy_pixel_to(new_image, nri - factor, nhi, old_right_pixel, factor)
# Increment the image indices
nli += factor
nri -= factor
oli += 1
ori -= 1
# increment new image row index
nhi += factor
return new_image
def main():
filename = input("Enter the image file name: ")
image = Image(filename)
newimage = enlarge(image, 2)
newimage.draw()
if __name__ == "__main__":
main()
|
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
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