MATLAB 图像处理:直方图的最后一个 bin 上升

MATLAB image processing: last bin of my histogram shoots up

我使用 imadjust 函数降低了原始图像的对比度。然而,当我为这个低对比度图像生成直方图时,我注意到最后一个 bin 突然上升并且没有反映原始图像的直方图。我很确定当你降低对比度时,bin 高度相对相同但直方图作为一个整体变得更窄。但在这种情况下,虽然变窄了,但最后一个箱子看起来比预期的要高很多。我附上了我的代码和其他相关图片。

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')

最后一个 bin "shoots up",因为 imadjust 限制了像素范围。

命令:J = imadjust(im_gray,[0 0.5], [0.3 0.5]);
im_gray 以上 0.5128 以上)的所有值,并将它们替换为 0.5uint8 范围内 128 的值)。

imadjust 文档有点不清楚:

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.

它没有说明超出范围 [low_in high_in] 的值会发生什么。

从上一句就可以理解:

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.

  • low_in 以下的所有值都映射到 low_out
  • high_in 以上的所有值都映射到 high_out

0.5 以上(128 以上)的所有 im_gray 值都映射到 J 中的 0.5。
由于 im_gray 有很多像素高于 128,因此 J 有很多像素 等于 128。

直方图的中心 bin 大约占总像素的一半。

您可以使用 sum(J(:) == 128) 进行检查。