set range for histogram

10 views (last 30 days)
bindhu a
bindhu a on 10 Aug 2016
Answered: Samayochita on 27 Mar 2025
img = imread('underwaterimage.jpg');
figure(1)
imshow(img);title('Input Image');
rr = histeq(img);
figure(2);imshow(rr);title('histo-red Plane');
  • how to set the range of this histogram from 13 to 242
  • the histogram value is generally from 0 to 255

Answers (1)

Samayochita
Samayochita on 27 Mar 2025
Hi Bindhu,
To apply histogram equalization to an image and ensure that the resulting pixel values are constrained within a specific range “[13, 242]” instead of the default “[0, 255]”, I would suggest a few modifications to the code mentioned above:
  • “histeq” function works only on grayscale image. If the image is RGB (colored), it needs to be converted to grayscale.
if size(img,3) == 3 % check if the image has three color channels (RGB).
img = rgb2gray(img); % convert it to grayscale
end
  • Use “imadjust” function is used to map the intensity values of the image from the range [13, 242] to the full range [0, 255].
adjusted_img = imadjust(img, [13/255, 242/255], []);
  • [13/255, 242/255]” specifies the input range in normalized form (since image intensity values are typically in the range 0 to 1 for processing).
  • “[]” specifies that the full output range [0, 1] should be used.
  • “histeq” function is used to perform histogram equalization on the intensity-adjusted image.
  • This enhances the contrast of the image by spreading out the most frequent intensity values.
rr = histeq(adjusted_img);
figure(2);
imshow(rr); % show the processed image
title('Histogram-Equalized Image with Adjusted Range');
For more information on “histeq”, “imadjust”, “rgb2gray” functions please refer to the following documentation links:
Hope this helps.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!