PIXELBANKv8.2.1
Menu

Image as Matrix

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 xx and yy 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 nn. 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:

  1. Flatten the 2D array into a 1D array of pixel values.
  2. Calculate the mean pixel value.
  3. Find the minimum and maximum pixel values.
  4. Compute the variance and standard deviation.
Mean=1ni=1nxi\text{Mean} = \frac{1}{n} \sum_{i=1}^{n} x_i

This technique is widely used in image preprocessing and normalization.

Example:

Input:
image_stats([[100, 150], [200, 50]])
Output:
{'mean': 125.0, 'min': 50, 'max': 200, 'std': 55.9017}
Reasoning:

Mean = (100+150+200+50)/4 = 125

Constraints:

  • Image is a 2D array with dimensions H×W where 1 ≤ H, W ≤ 100
  • Pixel values are integers in range [0, 255]
  • Return values rounded to 4 decimal places
Editor

Test Results

0/0
Run code to see test results.