2015-10-07 37 views
2

我想在我的隱寫算法中使用canny邊緣檢測,因此當我需要例如250像素隱藏信息時,我必須找到最佳低/高閾值,以便canny找到圖像中至少250個最銳利的像素。最佳高/低canny閾值找到任意像素數

另一個例子,當我需要500像素的隱藏信息時,我必須找到低/高閾值以找到至少500像素的圖像。

我以爲我可以使用二進制搜索,但是它不返回最優threshold.this是我的二進制搜索功能:

function [ th ] = getThreshold(I, N, w) 
% limit is set to 1% of the message 
% length 
% no. of edge pixels,ne ? N + 0.01 × N 
% and ne ? N 
% ne = number of edge pixels in I, when 
% Canny edge detector is used on I with 
% high threshold th and low threshold 
% tl = 0.4 ? th and width w 

limit = (0.01 * N); 

tmax = 0.8; 
tmin = 0; 
set = true; 

while(set) 
    th = double((tmax + tmin)/2); 
    BW = edge(I,'canny',[tmin tmax],'both',w); 
    % it returns the number of pixels in the edges obtained through Canny 
    %  edge detector 
    ne = getEdgePixelCount(BW); 

    diff = ne - N; 
    if diff > limit 
     tmin = th; 
    elseif diff < 0 
     tmax = th; 
    else 
     set = false; 
end 
end 
+0

如何計算索貝爾量級,並保持N最高? – Miki

回答

0

所施行的MATLAB本身你檢查過優化的門檻?從MATLAB文檔您有:

在所有情況下,邊試探性地選擇默認的門檻,根據輸入的數據。改變閾值的最好方法是運行一次邊緣,將計算的閾值捕獲爲第二個輸出參數。然後,從邊緣計算的值開始,調整閾值(更少的邊緣像素)或更低(更邊緣像素)。>>

因此,爲了得到優化MATLAB門檻精明的你可以使用

[~, th] = edge(yourpicture,'canny'); 

,然後申請日乘以一定係數f優化的閾值(從我的經驗˚F應該是1-3之間),你必須嘗試:

edgepict =邊緣(yourpicture, 'canny',f * th,'both',sigma);

請注意,th是一個包含th_low和th_high的矢量。 Th_low默認爲0.4 * th_high(如果我沒有記錯的話),我不會改變它。除了因子f之外,你還可以使用默認情況下的sigma(sqrt(2))。 Sigma指的是在Canny算法的第一步中應用的高斯模糊的半徑。