2010-08-10 110 views
1

我試圖檢測一維直方圖中的第一個谷值,以用作閾值點。 (處理從黑暗到明亮/從左到右)谷值檢測的平滑一維直方圖(OpenCV)

不幸的是,一些直方圖有小峯,缺口和鋸齒狀邊緣。我寫的算法陷在這些問題上。我想我需要消除粗糙的邊緣,因爲我需要的峯谷非常突出。

有沒有人有一些指示,以在OpenCV中平滑一維直方圖的最佳方式?

這裏表示算法掛住了鋸齒狀的邊緣和失敗:

http://applist.s3.amazonaws.com/junk/failed.png

藍線:峯值
紅線:谷

回答

1

在我看來,你是執行某種分割。你可以嘗試用自適應算法來做這件事,它通過計算一些點的平均值來設置閾值本身。這種特定的算法假定邊界點代表背景,而其餘點代表對象。這裏的算法:

calculate u1 -> the grayscale average of boundary points 
calculate u2 -> the grayscale average of all other points 
T_old = 0 
T_new = (u1 + u2)/2 
while (T_new != T_old) 
//you might want to modify this by introducing an epsilon value, something like 
// if T_new near T_old (abs(T_new-T_old)>1) 
u1 = grayscale average of points where grayscale intensity is lower than T_new 
u2 = grayscale average of points where grayscale intensity is higher or equal to T_new 
T_old =T _new 
T_new = (u1 + u2)/2 
end 
threshold = T_new 

這應該找到一個灰度圖像接近最佳閾值。

2

嘗試模糊直方圖或圖像。

因爲並不是所有的圖像照明級別都在源圖像上使用,所以valeys可能在那裏。在做直方圖之前,您可以通過模糊圖像來輕鬆解決此問題。或者嘗試做一些直方圖移動平均值,這樣突然的變化就會消失。

+0

砸,這工作非常出色。在計算直方圖之前,我將高斯模糊應用於源圖像。很簡單,謝謝! – developroom 2010-08-10 10:30:02

0

可能的方法來克服這個:

  • 近似直方圖與高斯曲線
  • 嘗試擴張,然後侵蝕直方圖圖像