我想在我的隱寫算法中使用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
如何計算索貝爾量級,並保持N最高? – Miki