Complete the code to load an image as a 2D grayscale array.
import numpy as np from PIL import Image img = Image.open('image.jpg').convert([1]) img_array = np.array(img)
The 'L' mode converts the image to grayscale, which is a 2D signal representation.
Complete the code to access the pixel value at row 10, column 15.
pixel_value = img_array[[1], 15]
Row index is 10, so use img_array[10, 15] to get the pixel value.
Fix the error in the code to compute the average pixel intensity.
average_intensity = np.[1](img_array)Use np.mean() to calculate the average intensity of the image pixels.
Fill both blanks to create a dictionary of pixel intensities for pixels greater than 128.
bright_pixels = { (i, j): img_array[i, j] for i in range(img_array.shape[[1]]) for j in range(img_array.shape[[2]]) if img_array[i, j] > 128 }img_array.shape[0] is rows, img_array.shape[1] is columns.
Fill all three blanks to create a new image array with pixel values normalized between 0 and 1.
normalized_img = (img_array - [1]) / ([2] - [3])
Normalization subtracts the minimum and divides by the range (max - min).
