繁体   English   中英

MATLAB 图像处理:我的直方图的最后一个 bin 出现了

[英]MATLAB image processing: last bin of my histogram shoots up

我使用 imadjust 功能降低了原始图像的对比度。 然而,当我为这张低对比度图像生成直方图时,我注意到最后一个 bin 出现并没有反映原始图像的直方图。 我很确定当你降低对比度时,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“上升”,因为imadjust正在限制像素的范围。

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

imadjust文档有点不清楚:

J = imadjust(I,[low_in high_in],[low_out high_out]) 将 I 中的强度值映射到 J 中的新值,使得 low_in 和 high_in 之间的值映射到 low_out 和 high_out 之间的值。

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

你可以从上一句理解:

J = imadjust(I,[low_in high_in]) 将 I 中的强度值映射到 J 中的新值,使得 low_in 和 high_in 之间的值映射到 0 和 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)进行检查。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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