set range for histogram

조회 수: 6 (최근 30일)
bindhu a
bindhu a 2016년 8월 10일
답변: Samayochita 2025년 3월 27일
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

답변 (1개)

Samayochita
Samayochita 2025년 3월 27일
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.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by