91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 21KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-01
  • 語言: Matlab
  • 標簽: canny算子??

資源簡介

該代碼使用matlab實現,代碼結構清晰完整,方便大家學習

資源截圖

代碼片段和文件信息


function?e=canny(I)
???
%?????gray?=?rgb2gray(I);
????gray=I;
????a?=?im2single(gray);
???
????[mn]?=?size(a);
????%?用于輸出的邊界位圖
????e?=?false(mn);
???
????%?Magic?numbers
????GaussianDieOff?=?.0001;?
????PercentOfPixelsNotEdges?=?.7;?%?用于閥值選擇
????ThresholdRatio?=?.4;??????????%?低閥值相對高閥值的比值
????sigma?=?1;?%設置sigma
????thresh?=?[];
???
????%?設計濾波器?-?a?gaussian和它的導數
????pw?=?1:30;?%?possible?widths
????ssq?=?sigma^2;
????width?=?find(exp(-(pw.*pw)/(2*ssq))>GaussianDieOff1‘last‘);%find函數很給力...
????if?isempty(width)
????width?=?1;??%?the?user?entered?a?really?small?sigma
????end
???
????t?=?(-width:width);
????gau?=?exp(-(t.*t)/(2*ssq))/(2*pi*ssq);?????%?高斯一維濾波
???
????%?Find?the?directional?derivative?of?2D?Gaussian?(along?X-axis)
????%?Since?the?result?is?symmetric?along?X?we?can?get?the?derivative?along
????%?Y-axis?simply?by?transposing?the?result?for?X?direction.
????[xy]=meshgrid(-width:width-width:width);
????dgau2D=-x.*exp(-(x.*x+y.*y)/(2*ssq))/(pi*ssq);%二維高斯方向導數
???
????%?Convolve?the?filters?with?the?image?in?each?direction
????%?The?canny?edge?detector?first?requires?convolution?with
????%?2D?gaussian?and?then?with?the?derivitave?of?a?gaussian.
????%?Since?gaussian?filter?is?separable?for?smoothing?we?can?use
????%?two?1D?convolutions?in?order?to?achieve?the?effect?of?convolving
????%?with?2D?Gaussian.??We?convolve?along?rows?and?then?columns.
???
????%用一階高斯濾波器平滑圖像
????aSmooth=imfilter(agau‘conv‘‘replicate‘);???%?run?the?filter?accross?rows
????aSmooth=imfilter(aSmoothgau‘‘conv‘‘replicate‘);?%?and?then?accross?columns
???
????%應用方向導數
????ax?=?imfilter(aSmooth?dgau2D?‘conv‘‘replicate‘);
????ay?=?imfilter(aSmooth?dgau2D‘?‘conv‘‘replicate‘);
???
????%計算梯度幅值
????mag?=?sqrt((ax.*ax)?+?(ay.*ay));
????magmax?=?max(mag(:));
????if?magmax>0
?????mag?=?mag?/?magmax;???%?normalize
????end
???
????%?選擇高低兩個閥值用于雙閥值算法檢測和連接邊緣.
????if?isempty(thresh)
?????counts=imhist(mag?64);
?????highThresh?=?find(cumsum(counts)?>?PercentOfPixelsNotEdges*m*n...
???????????????????1‘first‘)?/?64;
?????lowThresh?=?ThresholdRatio*highThresh;
?????thresh?=?[lowThresh?highThresh];
????elseif?length(thresh)==1
?????highThresh?=?thresh;
?????if?thresh>=1
??????eid?=?sprintf(‘Images:%s:thresholdMustBeLessThanOne‘?mfilename);
??????msg?=?‘The?threshold?must?be?less?than?1.‘;
??????error(eid‘%s‘msg);
????end
?????lowThresh?=?ThresholdRatio*thresh;
?????thresh?=?[lowThresh?highThresh];
?????elseif?length(thresh)==2
?????lowThresh?=?thresh(1);
?????highThresh?=?thresh(2);
?????if?(lowThresh?>=?highThresh)?||?(highThresh?>=?1)
??????eid?=?sprintf(‘Images:%s:thresholdOutOfRange‘?mfilename);
??????msg?=?‘Thresh?must?be?[low?high]?where?low???????error(eid‘%s‘msg);
?????end
????end
???
????%?The?next?step?is?to?do?the?non-maximum?supression.?
????%?We?will?accrue?indices?which?specify?ON?pixels?in?strong?edgemap
????%?The?array?e?will?become?the?weak?edge?m

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-12-08?21:15??CorrelationMatching\
?????文件????????3667??2017-12-08?21:14??CorrelationMatching\canny.m
?????文件?????????857??2017-12-08?21:15??CorrelationMatching\cannyFindLocalMaxima.m
?????文件?????????256??2017-12-08?21:38??CorrelationMatching\main.m
?????文件???????22995??2011-12-24?18:59??CorrelationMatching\Scene.jpg
?????文件????????1521??2011-12-18?17:32??CorrelationMatching\Template_1.jpg
?????文件????????9752??2011-12-16?17:35??CorrelationMatching\Template_2.jpg

評論

共有 條評論