Complete the code to display an image using nearest neighbor interpolation.
import matplotlib.pyplot as plt import numpy as np image = np.random.rand(5, 5) plt.imshow(image, interpolation='[1]') plt.show()
The 'nearest' interpolation method displays the image by picking the nearest pixel value without smoothing.
Complete the code to display an image using bilinear interpolation.
import matplotlib.pyplot as plt import numpy as np image = np.random.rand(10, 10) plt.imshow(image, interpolation='[1]') plt.show()
Bilinear interpolation smooths the image by averaging the nearest 2x2 pixels.
Fix the error in the code to use bicubic interpolation correctly.
import matplotlib.pyplot as plt import numpy as np image = np.random.rand(8, 8) plt.imshow(image, interpolation=[1]) plt.show()
The interpolation parameter must be a string in quotes, so 'bicubic' is correct.
Fill both blanks to create a dictionary of images with their interpolation methods.
images = {'img1': np.random.rand(4, 4), 'img2': np.random.rand(6, 6)}
methods = ['[1]', '[2]']
image_dict = {k: (v, m) for k, v, m in zip(images.keys(), images.values(), methods)}This creates a dictionary pairing each image with its interpolation method: 'nearest' for 'img1' and 'bilinear' for 'img2'.
Fill all three blanks to create a dictionary comprehension filtering images with interpolation 'nearest' and size > 5.
images = {'a': np.random.rand(3, 3), 'b': np.random.rand(7, 7), 'c': np.random.rand(10, 10)}
methods = {'a': '[1]', 'b': '[2]', 'c': '[3]'}
filtered = {k: v for k, v in images.items() if methods[k] == 'nearest' and v.shape[0] > 5}Only images 'b' and 'c' have interpolation 'nearest' and size > 5. 'b' and 'c' are assigned 'nearest', 'a' is 'bilinear'.