Implement a function to compute basic statistics of a grayscale image represented as a 2D matrix of pixel values. In computer vision, images are often treated as 2D arrays where each element represents the intensity of a pixel, ranging from 0 (black) to 255 (white), and can be described using x and y coordinates.
The mean pixel value is a measure of the average intensity, calculated as the sum of all pixel values divided by the total number of pixels n. The minimum and maximum pixel values represent the darkest and brightest points in the image. The standard deviation measures the spread of pixel values from the mean, calculated using the variance formula.
Here are the steps to compute these statistics:
This technique is widely used in image preprocessing and normalization.
image_stats([[100, 150], [200, 50]])
{'mean': 125.0, 'min': 50, 'max': 200, 'std': 55.9017}Mean = (100+150+200+50)/4 = 125