Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the shape property of an image represent?
The shape property shows the dimensions of the image, usually as (height, width, channels). It tells how tall, wide, and how many color channels the image has.
Click to reveal answer
beginner
What is dtype in the context of an image?
dtype means the data type of the image pixels, like uint8 for values 0-255 or float32 for decimal values. It affects how pixel values are stored and processed.
Click to reveal answer
beginner
How do you find the total number of pixels in an image?
Multiply the height by the width of the image. For example, an image with shape (100, 200) has 100 × 200 = 20,000 pixels.
Click to reveal answer
intermediate
What does the size property of an image tell you?
size gives the total number of elements (pixels × channels) in the image array. For example, a 100×200 RGB image has size 100 × 200 × 3 = 60,000.
Click to reveal answer
intermediate
Why is knowing the dtype important when working with images?
Because it affects memory use and how pixel values are interpreted. For example, uint8 stores integers 0-255, while float32 can store decimals, which is important for some image processing tasks.
Click to reveal answer
What does the shape (64, 64, 3) of an image mean?
A64 pixels total with 3 channels
BWidth 64, height 64, 3 color channels
C3 images of size 64x64
DHeight 64, width 64, 3 color channels
✗ Incorrect
The shape is (height, width, channels), so 64 height, 64 width, and 3 color channels (like RGB).
If an image has dtype uint8, what is the range of pixel values?
A-128 to 127
B0 to 1
C0 to 255
DAny decimal number
✗ Incorrect
uint8 means unsigned 8-bit integers, so pixel values range from 0 to 255.
How do you calculate the total number of pixels in an image?
AMultiply height by width
BAdd height and width
CMultiply channels by width
DDivide height by width
✗ Incorrect
Total pixels = height × width.
What does the size property of an image array represent?
ANumber of color channels
BTotal number of elements (pixels × channels)
CWidth of the image
DHeight of the image
✗ Incorrect
Size is the total number of elements in the array, including all pixels and channels.
Why might you convert an image's dtype from uint8 to float32?
ATo allow decimal pixel values for precise calculations
BTo reduce memory usage
CTo increase pixel value range to 0-65535
DTo make the image grayscale
✗ Incorrect
float32 allows decimal values, useful for some image processing and neural network inputs.
Explain what the shape, dtype, and size properties of an image tell you.
Think about how these properties describe the image's structure and data.
You got /3 concepts.
Describe why understanding image properties is important before processing images in machine learning.
Consider how these properties affect model training and predictions.
You got /3 concepts.
Practice
(1/5)
1. What does the shape property of an image represent?
easy
A. The file size of the image in bytes
B. The data type of the pixel values
C. The dimensions and number of color channels of the image
D. The compression level of the image
Solution
Step 1: Understand what shape means in images
The shape of an image is a tuple that shows its height, width, and number of color channels.
Step 2: Differentiate shape from other properties
File size and data type are different properties; shape specifically refers to dimensions and channels.
Final Answer:
The dimensions and number of color channels of the image -> Option C
Quick Check:
Shape = dimensions + channels [OK]
Hint: Shape always shows height, width, and channels [OK]
Common Mistakes:
Confusing shape with file size
Mixing up data type with shape
Thinking shape shows compression
2. Which of the following is the correct way to get the data type of an image stored in a NumPy array named img?
easy
A. img.dtype
B. img.type()
C. img.data_type
D. img.get_dtype()
Solution
Step 1: Recall NumPy syntax for data type
In NumPy, the data type of an array is accessed using the dtype attribute.
Step 2: Check each option
Only img.dtype is valid syntax; others are incorrect or do not exist.
Final Answer:
img.dtype -> Option A
Quick Check:
Use .dtype to get data type [OK]
Hint: Use .dtype attribute for NumPy array data type [OK]
What is the error in this code if the goal is to represent a color image?
medium
A. The array values are out of range for images
B. The dtype should be float instead of int
C. The shape attribute is called incorrectly
D. The array shape lacks a color channel dimension
Solution
Step 1: Check the array shape
The array shape is (2, 2), meaning 2 rows and 2 columns, no color channels.
Step 2: Understand color image requirements
A color image needs 3 dimensions: height, width, and channels (usually 3 for RGB).
Final Answer:
The array shape lacks a color channel dimension -> Option D
Quick Check:
Color images need 3D shape [OK]
Hint: Color images need 3D shape (height, width, channels) [OK]
Common Mistakes:
Thinking dtype must be float for images
Assuming shape attribute is wrong
Believing pixel values are out of range
5. You have a grayscale image loaded as a NumPy array with shape (256, 256) and dtype float32. You want to convert it to an 8-bit unsigned integer image suitable for display. Which code snippet correctly does this?
hard
A. img_uint8 = (img * 255).astype(np.uint8)
B. img_uint8 = img.astype(np.uint8)
C. img_uint8 = img / 255
D. img_uint8 = img.astype(np.float64)
Solution
Step 1: Understand dtype conversion needs
Converting from float32 (0 to 1 range) to uint8 (0 to 255) requires scaling by 255.
Step 2: Check each option
img_uint8 = (img * 255).astype(np.uint8) scales and converts correctly. img_uint8 = img.astype(np.uint8) converts without scaling, causing wrong values. Options A, B, and D do not convert to uint8 properly.
Final Answer:
img_uint8 = (img * 255).astype(np.uint8) -> Option A
Quick Check:
Scale float to 255 then convert to uint8 [OK]
Hint: Multiply floats by 255 before uint8 conversion [OK]