【问题标题】:MATLAB image processing: last bin of my histogram shoots upMATLAB 图像处理:我的直方图的最后一个 bin 突然出现
【发布时间】:2020-01-19 22:21:55
【问题描述】:

我使用了 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')

【问题讨论】:

  • 如果有帮助,请考虑接受答案。

标签: matlab height histogram bin imaging


【解决方案1】:

最后一个 bin “弹出”,因为 imadjust 正在限制像素范围。

命令:J = imadjust(im_gray,[0 0.5], [0.3 0.5]);:
获取高于im_gray0.5(高于128)的所有值,并将它们替换为0.5128 范围内的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) 进行检查。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-16
    • 1970-01-01
    • 2015-12-17
    • 2012-10-15
    • 1970-01-01
    • 1970-01-01
    • 2013-11-01
    相关资源
    最近更新 更多