What is histogram shrinking?

In the world of digital image processing, a number of various techniques are used to enhance the quality and visual appearance of images to modify them according to the user's demands. One of these techniques is histogram shrinking.

Histogram shrinking in digital image processing

Contrary to histogram stretching, histogram shrinking is a powerful method that can significantly improve an image's contrast and dynamic range. This process can bring out the finer details and enhance the aspects of an image that could have been lost due to poor lighting or limited dynamic range.

Mathematical implementation

Here's the mathematical implementation of histogram shrinking.

In this formula:

  • I(r,c)I(r,c) represents the original pixel value of an image.

  • I(r,c)minI(r,c)_{min} and I(r,c)maxI(r,c)_{max} showcase the original image's minimum and maximum pixel values.

  • After histogram shrinking, the new maximum and minimum values of the image pixels are represented as MaxMax and MinMin, respectively.

Graphical representation

We can best illustrate the effects of histogram stretching through the following graphs.

Original Histogram
Original Histogram

After applying the histogram shrinking procedure, the abovementioned histogram changes into something like this.

Shrunk histogram
Shrunk histogram

Matlab implementation

We can perform histogram shrinking using Matlab through the following function.

function enhancedImage = histogramShrinking(originalImage, minimumValue, maximumValue, newMinValue, newMaxValue)
% Compute the histogram of the original image
histogram = imhist(originalImage);
% Compute the cumulative distribution function (CDF)
cdf = cumsum(histogram) / numel(originalImage);
% Calculate the mapping function
mappingFunction = ((0:255) - minimumValue) / (maximumValue - minimumValue) ...
* (newMaxValue - newMinValue) + newMinValue;
% Apply the mapping function to the original image
enhancedImage = uint8(mappingFunction(double(originalImage) + 1));
% Display the original and enhanced images
figure;
subplot(2,1,1); imshow(originalImage); title('Original Image');
subplot(2,1,2); imshow(enhancedImage); title('Enhanced Image');
end

Code explanation

The enhancedImage function takes a couple of parameters like

  • originalImage

  • minimumValue

  • maximumValue

  • newMinValue

  • newMaxValue

and returns an enhancedImage whose histogram has been manipulated according to the user's inputs.

  • Lines 3–6: We compute the histogram and the cumulative distributive functionThe cumulative distribution function (CDF) is calculated by taking the cumulative sum of the histogram values and dividing it by the total number of pixels in the originalImage. of the original image using imhist() and cumsum() functions.

  • Lines 8–10: The mapping function is calculated based on the provided minimumValue, maximumValue, newMinValue, and newMaxValue. After histogram shrinking, it maps the original pixel values to the desired range of pixel values. This is done by linearly scaling the original pixel values within the range of [minimumValue, maximumValue] to the new range of [newMinValue, newMaxValue].

  • Lines 12–13: The mapping function is applied to originalImage by first converting it to double precision. The +1 is added to ensure that the pixel values fall within the range of the mapping function indices (0-255). The result is then converted back to uint8 data type to obtain the enhanced image.

  • Lines 15–18: The enhancedImage is displayed along with the originalImage in a figure for visual comparison. The subplot function creates two subplots: the first subplot displays the original image, and the second displays the enhanced image. The title function is used to add titles to the subplots.

% Load the original image
originalImage = imread('input_image.jpg');
% Define the parameters for histogram shrinking
minimumValue = 0;
maximumValue = 255;
newMinValue = 0;
newMaxValue = 200;
% Perform histogram shrinking
enhancedImage = histogramShrinking(originalImage, minimumValue, maximumValue, newMinValue, newMaxValue);

This code will compute the histogram of the original image, calculate the mapping function based on the provided parameters, and then apply the mapping function to the original image. The enhanced image will be displayed for visual comparison.

Conclusion

Whether it's improving contrast, expanding the dynamic range, reducing noise, or adjusting saturation, histogram shrinking offers a versatile approach to enhancing the visual quality of digital images. As image processing technologies evolve, histogram shrinking remains a valuable tool for image enhancement.

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved