from image import *
img = Image("motorcycle.jpg")
pixels = img.getPixels()
for p in pixels:
#INSERT LINES HERE
img.updatePixel(p)
win = ImageWin(img.getWidth(), img.getHeight())
img.draw(win)
I.
r = p.getRed()
p.setRed(r * 180)
II.
b = p.getBlue()
p.setBlue(b * 1.8)
III.
b = p.getBlue()
p.setBlue(b * 180)
IV.
p.setBlue(b * 1.8)
I
No, this code would increase red, not blue, by 180%.
II
Correct.
III
No, you have to convert the percentage you want to increase by into a decimal. If you want to increase a color by 180%, you would multiply by 1.8.
IV
No, you have to get the blue value first in order to increase it by a certain amount.
I.
from image import *
img = Image("vangogh.jpg")
halfway = (int) (img.getHeight() / 2)
for x in range(img.getWidth()):
for y in range(halfway, img.getHeight()):
p = img.getPixel(x, y)
r = p.getRed()
g = p.getGreen()
b = p.getBlue()
newPixel = Pixel(r, g, b)
img.setPixel(x, y - halfway, newPixel)
win = ImageWin(img.getWidth(),img.getHeight())
img.draw(win)
II.
from image import *
img = Image("vangogh.jpg")
halfway = (int) (img.getWidth() / 2)
for x in range(halfway):
for y in range(img.getHeight()):
p = img.getPixel(x, y)
r = p.getRed()
g = p.getGreen()
b = p.getBlue()
newPixel = Pixel(r, g, b)
img.setPixel(halfway + x, y, newPixel)
win = ImageWin(img.getWidth(),img.getHeight())
img.draw(win)
III.
from image import *
img = Image("vangogh.jpg")
halfway_x = (int) (img.getWidth() / 2)
halfway_y = (int) (img.getHeight() / 2)
for x in range(halfway_x):
for y in range(halfway_y):
p = img.getPixel(x, y)
r = p.getRed()
g = p.getGreen()
b = p.getBlue()
newPixel = Pixel(r, g, b)
img.setPixel(x, halfway_y + y, newPixel)
win = ImageWin(img.getWidth(),img.getHeight())
img.draw(win)
IV.
from image import *
img = Image("vangogh.jpg")
halfway = (int) (img.getHeight() / 2)
for x in range(img.getWidth()):
for y in range(halfway):
p = img.getPixel(x, y)
r = p.getRed()
g = p.getGreen()
b = p.getBlue()
newPixel = Pixel(r, g, b)
img.setPixel(x, halfway + y, newPixel)
win = ImageWin(img.getWidth(),img.getHeight())
img.draw(win)
I
Correct. This code block copies from the bottom half of the image to the top half.
II
Try again. This code block copies from the left half to the right half.
III
Try again. This code block copies the top left quadrant to the bottom left quadrant.
IV
Try again. This code block copies the top half of the image onto the bottom of the image.
from image import *
img = Image("vangogh.jpg")
for x in range(img.getWidth()):
for y in range(img.getHeight()):
p = img.getPixel(x, y)
img.setPixel(img.getWidth() - 1 - y,
img.getHeight() - 1 - x,
p)
win = ImageWin(img.getWidth(),img.getHeight())
img.draw(win)
The image is rotated 90 degree to the right.
We would have to create a new image and set the values in the new image from the old pixel values for this to be true.
The image is mirrored around a diagonal line from the top left to the bottom right.
Close, try again!
The image is mirrored vertically.
This would be true if the pixels were copied to the same row.
The image is mirrored around a diagonal line from the top right to the bottom left.