Loading problem...
In digital image processing and computer vision, understanding the distribution of pixel intensities is fundamental to analyzing and enhancing images. One of the most basic yet powerful metrics for quantifying an image's visual characteristics is its intensity range, which measures the spread of brightness values across all pixels.
The intensity range (also known as the dynamic range or pixel contrast) is defined as the difference between the maximum and minimum pixel values in a grayscale image:
$$\text{Intensity Range} = \max(I) - \min(I)$$
where I represents all pixel intensity values in the image.
Understanding Intensity Range:
For standard 8-bit grayscale images, pixel values range from 0 (pure black) to 255 (pure white). The intensity range provides crucial insights:
High intensity range (close to 255): The image utilizes the full brightness spectrum, exhibiting strong contrast between dark and light regions. This typically results in visually striking images with clear distinctions between features.
Low intensity range (close to 0): The image has limited brightness variation, appearing flat or washed out. All pixels cluster around similar intensity values, resulting in poor visual contrast.
Zero intensity range: All pixels have identical values, creating a uniform, single-color image with no variation whatsoever.
Why Intensity Range Matters:
This metric serves as a diagnostic tool in image preprocessing pipelines. Before applying advanced computer vision algorithms, practitioners often check the intensity range to determine if contrast enhancement (such as histogram stretching or equalization) is needed to improve feature visibility.
Your Task:
Write a Python function that computes the intensity range of a grayscale image. The function should:
img = np.array([[0, 50], [200, 255]])255This 2×2 grayscale image contains four pixels with intensities 0, 50, 200, and 255.
• Maximum pixel value: 255 (pure white) • Minimum pixel value: 0 (pure black) • Intensity Range: 255 - 0 = 255
The image exhibits full dynamic range, utilizing the complete spectrum from pure black to pure white. This indicates maximum possible contrast for an 8-bit grayscale image.
img = np.array([[100, 100], [100, 100]])0This 2×2 image is completely uniform—every pixel has the exact same intensity value of 100.
• Maximum pixel value: 100 • Minimum pixel value: 100 • Intensity Range: 100 - 100 = 0
An intensity range of zero indicates a perfectly flat image with no contrast. Visually, this would appear as a solid medium-gray square with no distinguishable features.
img = np.array([[0, 85, 170, 255]])255This 1×4 single-row image represents a gradient pattern with evenly spaced intensity values.
• Pixel values from left to right: 0 → 85 → 170 → 255 • Maximum pixel value: 255 • Minimum pixel value: 0 • Intensity Range: 255 - 0 = 255
Despite being a linear arrangement rather than a 2D image, the computation remains the same: find the global maximum and minimum across all pixels. This gradient spans the full intensity spectrum, resulting in maximum contrast.
Constraints