Challenge - 5 Problems
Image Rotation and Zoom Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of rotated image shape
What is the shape of the image after rotating a 100x100 array by 45 degrees using scipy.ndimage.rotate with reshape=True?
SciPy
import numpy as np from scipy.ndimage import rotate image = np.ones((100, 100)) rotated = rotate(image, 45, reshape=True) print(rotated.shape)
Attempts:
2 left
💡 Hint
Think about how rotating a square by 45 degrees increases the bounding box size.
✗ Incorrect
Rotating a 100x100 image by 45 degrees with reshape=True expands the output shape to fit the entire rotated image. The new shape is approximately 142x142 due to the diagonal length.
❓ data_output
intermediate2:00remaining
Zoomed image pixel value at center
Given a 5x5 image with all zeros except the center pixel set to 1, what is the pixel value at the center after zooming by 2 using scipy.ndimage.zoom?
SciPy
import numpy as np from scipy.ndimage import zoom image = np.zeros((5,5)) image[2,2] = 1 zoomed = zoom(image, 2) center_value = zoomed[5,5] print(round(center_value, 2))
Attempts:
2 left
💡 Hint
Zooming uses interpolation which spreads the pixel value.
✗ Incorrect
Zooming by 2 doubles the image size and interpolates pixel values. The center pixel value reduces to about 0.5 due to interpolation smoothing.
🔧 Debug
advanced2:00remaining
Identify error in rotation code
What error does the following code raise?
import numpy as np
from scipy.ndimage import rotate
image = np.ones((50, 50))
rotated = rotate(image, '90')
print(rotated.shape)
SciPy
import numpy as np from scipy.ndimage import rotate image = np.ones((50, 50)) rotated = rotate(image, '90') print(rotated.shape)
Attempts:
2 left
💡 Hint
Check the type of the angle argument passed to rotate.
✗ Incorrect
The rotate function expects a numeric angle, but a string '90' was passed, causing a TypeError.
❓ visualization
advanced2:00remaining
Effect of zoom factor on image size
If you zoom a 64x64 image by a factor of 1.5 using scipy.ndimage.zoom, what will be the shape of the resulting image?
SciPy
import numpy as np from scipy.ndimage import zoom image = np.zeros((64,64)) zoomed = zoom(image, 1.5) print(zoomed.shape)
Attempts:
2 left
💡 Hint
Zoom rounds the output shape to the nearest integer.
✗ Incorrect
Zooming 64 by 1.5 gives 96, and scipy.ndimage.zoom rounds the output shape to (96, 96).
🚀 Application
expert3:00remaining
Combining rotation and zoom effects
You have a 128x128 image. You first rotate it by 30 degrees with reshape=False, then zoom it by 0.5. What is the shape of the final image?
SciPy
import numpy as np from scipy.ndimage import rotate, zoom image = np.ones((128,128)) rotated = rotate(image, 30, reshape=False) final = zoom(rotated, 0.5) print(final.shape)
Attempts:
2 left
💡 Hint
reshape=False keeps the shape same after rotation; zoom scales down by half rounding to nearest integer.
✗ Incorrect
Rotation with reshape=False keeps shape (128,128). Zoom by 0.5 scales to 64 (128*0.5), and scipy.ndimage.zoom output shape is rounded to nearest integer, resulting in (64,64).