簡體   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