Counting the pixels in an image

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Counting the pixels in an image

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. How do you work out the total number of pixels in an image?
A width * height
B width + height
2. An image is 1920 x 1080 pixels. What is the total number of pixels?
A 2,073,600
B 3,000
3. Which one is the correct first step when calculating the file size of a bitmap image?
A Find the total pixels: width * height
B Multiply by the sample rate
4. An image is 10 pixels wide and 4 pixels high. How many pixels is it in total?
A 14 pixels
B 40 pixels
5. In the image 1920 x 1080, what does 1920 stand for?
A The number of rows (height)
B The number of pixels in each row (width)

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1pixels = width * height AThe answer 3000 is just the two numbers added together (1920 + 1080). The product is 2,073,600 pixels.
21920 * 1080 = 2073600 Btotal_pixels = 800 * 600
3The width is the number of pixels in each row, and the height is the number of rows, so multiply them to get the total pixels CWidth and height are added instead of multiplied. Adding gives only the pixels along two edges, not the total in the whole image. It should be width * height.
4Counting the pixels is the first step before working out the file size of a bitmap image Dfile_size = total_pixels * colour_depth
5pixels = width + height EWorks out the total number of pixels in an image by multiplying the pixels per row by the number of rows
61920 * 1080 = 3000 FA 1920 x 1080 image contains 2,073,600 pixels in total

Definitions

pixels = width * height

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
pixels = width _ height
2.
______ = width * height
3.
pixels = _____ * height
4.
pixels = width * ______
5.
width = 1920 height = 1080 OUTPUT _____ * height

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A width = 1920
B height = 1080
C pixels = width * height
D print(pixel)
Question 2
A width == 800
B height = 600
C pixels = width * height
D print(pixels)
Question 3
A width = 1920
B height = 1080
C pixels = width + height
D print(pixels)
Question 4
A cols = 640
B rows = 480
C total = cols * cols
D print(total)
Question 5
A width = 1024
B heigth = 768
C pixels = width * height
D print(pixels)

Answer Key

Counting the pixels in an image
Section A: Quick Questions
Q1
A — width * height
Q2
A — 2,073,600
Q3
A — Find the total pixels: width * height
Q4
B — 40 pixels
Q5
B — The number of pixels in each row (width)
Section B: Match the Pairs
Q1
pixels = width * height → Works out the total number of pixels in an image by multiplying the pixels per row by the number of rows
Q2
1920 * 1080 = 2073600 → A 1920 x 1080 image contains 2,073,600 pixels in total
Q3
The width is the number of pixels in each row, and the height is the number of rows, so multiply them to get the total pixels → total_pixels = 800 * 600
Q4
Counting the pixels is the first step before working out the file size of a bitmap image → file_size = total_pixels * colour_depth
Q5
pixels = width + height → Width and height are added instead of multiplied. Adding gives only the pixels along two edges, not the total in the whole image. It should be width * height.
Q6
1920 * 1080 = 3000 → The answer 3000 is just the two numbers added together (1920 + 1080). The product is 2,073,600 pixels.
Section C: Definitions
Q1
pixels = width * height — Total pixels = pixels per row times number of rows. For 1920 x 1080 that is 2,073,600 pixels. This is the first step when working out image file size.
Section D: Fill in the Blanks
Q1
pixels = width * height
Q2
pixels = width * height
Q3
pixels = width * height
Q4
pixels = width * height
Q5
width = 1920 height = 1080 OUTPUT width * height
Section E: Spot the Error
Q1
D — The total was stored in a variable called pixels, but this line prints pixel, which does not exist. It should be print(pixels).
Q2
A — A double equals sign compares two values. It does not store one. The width must be assigned with a single equals sign: width = 800.
Q3
C — Total pixels is pixels per row times number of rows, so the values must be multiplied, not added. It should be pixels = width * height.
Q4
C — The width (pixels per row) is multiplied by itself, so the number of rows is never used. It should be total = cols * rows.
Q5
B — The variable name is misspelled. Line 3 uses height, which would not exist, so the program would crash. It should be height = 768.