set range for histogram

16 ビュー (過去 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 Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by