简体   繁体   中英

MATLAB image processing: last bin of my histogram shoots up

I used the imadjust function to lower the contrast of my original image. However, when I generated the histogram for this low-contrast image, I'm noticing that the last bin shoots up and doesn't reflect the histogram of the original image. I'm pretty sure that when you lower the contrast, the bin heights are relatively the same but the histogram as a whole gets narrower. But in this case, although it gets narrower, the last bin appears a lot taller than it's supposed to. I have attached my code and other related images.

im = imread('elephant.jpg');

%converts image to grayscale and displays it
im_gray = rgb2gray(im);
figure; 
imshow(im_gray)
title ('Original Gray-scale Image');

%displays the histogram of the grayscale image
figure; 
imhist(im_gray);
axis([0 255 0 22920])
title ('Histogram of the Original Gray-scale Image')
xlabel ('Pixel Value (Gray-level), ai')
ylabel ('Number of Pixels, Ni')

%lowers the contrast of original image --> deteriorated image
J = imadjust(im_gray,[0 0.5], [0.3 0.5]);
figure;
imshow(J);
title ('Deteriorated Image')

%displays histogram of the deteriorated image
figure;
imhist(J);
axis([0 255 0 489000])
title ('Histogram of the Deteriorated Image')
xlabel ('Pixel Value (Gray-level), ai')
ylabel ('Number of Pixels, Ni')

降低对比度后的直方图 原始图像的直方图

Last bin "shoots up", because imadjust is clamping the range of the pixels.

The command: J = imadjust(im_gray,[0 0.5], [0.3 0.5]); :
Takes all values above 0.5 (above 128 ) of im_gray , and replace them with 0.5 (value of 128 in uint8 range).

imadjust documentation is a little unclear:

J = imadjust(I,[low_in high_in],[low_out high_out]) maps intensity values in I to new values in J such that values between low_in and high_in map to values between low_out and high_out.

It doesn't say what happens to the values outside the range [low_in high_in] .

You can understand it from the previous sentence:

J = imadjust(I,[low_in high_in]) maps intensity values in I to new values in J such that values between low_in and high_in map to values between 0 and 1.

  • All values below low_in are mapped to low_out .
  • All values above high_in are mapped to high_out .

All im_gray values above 0.5 (above 128) are mapped to 0.5 in J .
Since im_gray has many pixels above 128, J has many pixels that equals 128.

The center bin of the histogram counts about half of the total pixels.

You can use sum(J(:) == 128) , for checking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM