0
0
SciPydata~20 mins

Image interpolation in SciPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Image Interpolation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of resizing an image with scipy.ndimage.zoom
What is the shape of the output image after applying scipy.ndimage.zoom with a zoom factor of 2 on a 2D grayscale image of shape (50, 50)?
SciPy
import numpy as np
from scipy.ndimage import zoom

image = np.ones((50, 50))
zoomed_image = zoom(image, 2)
print(zoomed_image.shape)
A(51, 51)
B(50, 50)
C(25, 25)
D(100, 100)
Attempts:
2 left
💡 Hint
Think about how zoom factor affects each dimension size.
🧠 Conceptual
intermediate
1:30remaining
Understanding interpolation order in scipy.ndimage.zoom
Which interpolation order in scipy.ndimage.zoom corresponds to cubic spline interpolation?
Aorder=1
Border=3
Corder=0
Dorder=5
Attempts:
2 left
💡 Hint
Order 0 is nearest neighbor, order 1 is linear.
data_output
advanced
2:00remaining
Resulting pixel value after zoom with linear interpolation
Given a 1D array arr = np.array([0, 10, 20]), what is the output of scipy.ndimage.zoom(arr, 2, order=1)?
SciPy
import numpy as np
from scipy.ndimage import zoom

arr = np.array([0, 10, 20])
result = zoom(arr, 2, order=1)
print(result)
A[ 0. 5. 10. 15. 20.]
B[ 0. 10. 20.]
C[ 0. 7.5 15. 20.]
D[ 0. 3.3 6.6 10. 20.]
Attempts:
2 left
💡 Hint
Linear interpolation fills values evenly between points.
🔧 Debug
advanced
2:00remaining
Identify the error in zooming a color image
What error occurs when running this code to zoom a color image with shape (100, 100, 3) using scipy.ndimage.zoom(image, 2)?
SciPy
import numpy as np
from scipy.ndimage import zoom

image = np.ones((100, 100, 3))
zoomed = zoom(image, 2)
print(zoomed.shape)
AValueError: zoom() missing required argument 'zoom'
BTypeError: float object cannot be interpreted as an integer
COutput shape is (200, 200, 6) which is incorrect
DOutput shape is (200, 200, 3) which is correct
Attempts:
2 left
💡 Hint
Check how zoom interprets a single float for multi-dimensional arrays.
🚀 Application
expert
1:30remaining
Choosing correct zoom parameters for RGB image resizing
You want to resize an RGB image of shape (120, 160, 3) to double its width and height but keep color channels unchanged using scipy.ndimage.zoom. Which zoom parameter is correct?
A(2, 2, 1)
B2
C(2, 2, 2)
D(1, 1, 3)
Attempts:
2 left
💡 Hint
Color channels should not be scaled.