Skip to main content

Section 18.8 Multiple Choice Questions

Activity 18.8.1.

What are the three colors parts that make up each pixel?
  • red, blue and yellow
  • These are the primary colors for paint, but computers use light.
  • red, green and blue
  • Correct. Computers use red, green, and blue light to make all of the colors.
  • red, white and blue
  • Try again.
  • blue, black and red
  • Try again.

Activity 18.8.2.

What does the following code block do?
from image import *
img = Image('beach.jpg')
pixels = img.getPixels()
for p in pixels:
    r = p.getRed()
    p.setGreen(r)
    img.updatePixel(p)
  • Sets the green value in every pixel to the red value.
  • Correct. It sets the green value to the red value.
  • Switches the green and red values in every pixel.
  • It only sets the green value, not the red value.
  • Creates a green filter on the image.
  • What does it set the green value to?
  • The code has no effect on pixel color.
  • It does change the pixel color.

Activity 18.8.3.

Every pixel has a color with a red value, a green value and a blue value. What is the range (minimum value and maximum value)?
  • 0 to 100
  • The maximum value is not 100.
  • 0 to 255
  • Correct. The minimum value is 0 and the maximum is 255.
  • 1 to 10
  • Neither of these is correct.
  • 1 to 255
  • The minimum value is not 1.

Activity 18.8.4.

If a pixel has red=0, green=255, and blue=0, what color will it be?
  • Red
  • Try again. If red equals 0, there will be no red color in the resulting pixel.
  • Green
  • Correct. Since green equals 255 and the other two values equal 0, the resulting pixel color will be green.
  • Black
  • Try again. All values must be 0 for the pixel to be black.
  • Blue
  • Try again. If blue equals 0, there will be no blue color in the resulting pixel.
  • White
  • Try again. All values must be 255 for the pixel to be white.

Activity 18.8.5.

Which code block should you insert in the for loop below to correctly increase the blue by 180%?
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.

Activity 18.8.6.

Which of the following would reduce the green value by 25%?
  • multiply the green value by 25
  • To reduce the green value you must multiply by a value that is less than 1.
  • multiply the green value by 0.25
  • This would reduce it by 75%.
  • multiply the green value by 0.5
  • This would reduce it by 50%.
  • multiply the green value by 0.75
  • This would reduce it by 25%.

Activity 18.8.7.

Which code block would allow you to copy the bottom half of the image onto the top half?
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.

Activity 18.8.8.

Which of the following combinations of red (r), green (g), and blue (b) values makes white?
  • r = 255, g = 0, b = 0
  • This would be red.
  • r = 0, g = 0, b = 0
  • This would be black (no light).
  • r = 0, g = 255, b = 0
  • This would be green
  • r = 255, g = 255, b = 255
  • Correct. To make white set all values to 255.

Activity 18.8.9.

What happens when we run the following code?
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.
  • Correct.

Activity 18.8.10.

What line of code sets the red, green and blue values simultaneously?
  • setPixel(r, g, b)
  • There is no setPixel method.
  • Pixel(r, g, b)
  • Correct. You can set the red, blue, and green when you create a Pixel.
  • setAll(r, g, b)
  • There is no setAll method.
  • This cannot be accomplished using a single line of code.
  • You can actually set the red, blue, and green at the same time.
You have attempted of activities on this page.