Images are often processed as 2D signals. What is the main reason for this approach?
Think about how images are structured in terms of pixels and their arrangement.
Images have two spatial dimensions: width and height. Each pixel has an intensity value, so images can be seen as 2D signals where each point corresponds to a pixel's intensity.
Given the following 2D array representing a grayscale image, what is the output of the code that sums all pixel values?
import numpy as np image = np.array([[10, 20, 30], [40, 50, 60], [70, 80, 90]]) total_intensity = np.sum(image) print(total_intensity)
Sum all the numbers in the 2D array.
The sum of all pixel values in the 3x3 array is 10+20+30+40+50+60+70+80+90 = 450.
What is the shape of the output after applying a 2D Fourier Transform to a grayscale image of shape (256, 256)?
import numpy as np image = np.random.rand(256, 256) ft_image = np.fft.fft2(image) print(ft_image.shape)
Consider how the 2D FFT output shape relates to the input shape.
The 2D Fourier Transform output has the same shape as the input image, so (256, 256).
Which code snippet correctly visualizes a 2D numpy array as a grayscale image?
import numpy as np import matplotlib.pyplot as plt signal = np.array([[0, 1], [2, 3]]) # Visualization code here
Think about which matplotlib function displays 2D arrays as images.
plt.imshow with cmap='gray' correctly displays a 2D array as a grayscale image.
What error will the following code produce when trying to access a pixel value?
image = [[10, 20, 30], [40, 50, 60], [70, 80, 90]] pixel = image[1][2] print(pixel)
Consider how Python lists are indexed.
Python lists do not support multi-dimensional indexing with commas; this causes a TypeError. Using separate indexing like image[1][2] works correctly.
