From: Bang Nhan on 17 Apr 2010 23:20 Hi, I wonder why the possible width in the Canny edge detector in the m.function 'edge' is 1:30? Why 30? and what will be different if I change 30 to other value, i.e less than 30? And what the pw do anyway? Here is portion of the edge code for the canny from the image processing toolbox " % Design the filters - a gaussian and its derivative pw = 1:30; % possible widths ssq = sigma^2; width = find(exp(-(pw.*pw)/(2*ssq))>GaussianDieOff,1,'last'); if isempty(width) width = 1; % the user entered a really small sigma end " Thanks
From: Walter Roberson on 18 Apr 2010 00:11 Bang Nhan wrote: > Hi, > > I wonder why the possible width in the Canny edge detector in the > m.function 'edge' is 1:30? Why 30? and what will be different if I > change 30 to other value, i.e less than 30? > And what the pw do anyway? > Here is portion of the edge code for the canny from the image processing > toolbox > > " > % Design the filters - a gaussian and its derivative > > pw = 1:30; % possible widths > ssq = sigma^2; > width = find(exp(-(pw.*pw)/(2*ssq))>GaussianDieOff,1,'last'); > if isempty(width) > width = 1; % the user entered a really small sigma > end > " If you were to reduce pw to a limit less than 30, you would get a small speed-up, probably unnoticeable unless you repeated the function many many times. As for the upper value: if you examine the expression, you will see that by 30, you are dealing in exp(-450/ssq) . That's pow(4e-196,1/ssq), which is going to be less than eps(1) unless ssq is at least 12 1/4, which corresponds to sigma 3.5 . 3 1/2 standard deviations is enough for 99.95% of the population; relatively few people are likely to use a sigma greater than 3.
From: Bang Nhan on 18 Apr 2010 00:25 > > If you were to reduce pw to a limit less than 30, you would get a small > speed-up, probably unnoticeable unless you repeated the function many > many times. > > As for the upper value: if you examine the expression, you will see that > by 30, you are dealing in exp(-450/ssq) . That's pow(4e-196,1/ssq), > which is going to be less than eps(1) unless ssq is at least 12 1/4, > which corresponds to sigma 3.5 . 3 1/2 standard deviations is enough for > 99.95% of the population; relatively few people are likely to use a > sigma greater than 3. Hi Walter, First thanks for your reply. Second, there are something that I am not quite understand. For me, I am trying to find the edge of the image using canny edge detection, and if I correct the pw to 1:1 or 1:2, with an image 200X200 elements in the matrix, it take very short time to get the edge. But if I keep pw=1:30, it take a lot longer. So I have been using the edge with the modified pw=1:1. But I just do that since it is faster, but I do know how that gonna affect the performance of the edge detector. So that is why I put the question up. Also, where did you get pow(4e-196,1/ssq)? And what does it mean by less than eps(1)? The sigma I have been using is 5 or 10, since I want the FWHM of the gaussian to cover at least 10 pixels of the 200x200. Did I do that wrong? Thanks
From: Bang Nhan on 18 Apr 2010 03:26 Hi Walter, So one thing I want to make sure, is the pw determine how large the filter mask gonna be? In Gonzalez and Woods's Digital Image Processing using MATLAB, they mentioned that the default size for the linear filter is 3x3 matrix. So I wonder if the Gaussian filter in the Canny is also set to have the default 3x3? First when I saw the pw1:30, I thought that is the default size for the Gaussian filter. Is that the right thinking? If not then how may I tell how large the mask in the canny is? Thanks Bang
From: Walter Roberson on 18 Apr 2010 01:14
Bang Nhan wrote: > Second, there are something that I am not quite understand. For me, I am > trying to find the edge of the image using canny edge detection, and if > I correct the pw to 1:1 or 1:2, with an image 200X200 elements in the > matrix, it take very short time to get the edge. But if I keep pw=1:30, > it take a lot longer. So I have been using the edge with the modified > pw=1:1. > But I just do that since it is faster, but I do know how that gonna > affect the performance of the edge detector. So that is why I put the > question up. I don't know the answer to that, but I would tend to think the accuracy would be considerably reduced. > Also, where did you get pow(4e-196,1/ssq)? If pw can be 1:30 then pw includes 30. exp(-(pw.*pw)/(2*ssq)) then becomes exp(-(30*30)/(2*ssq)) which is exp(-900/(2*ssq)) which is exp(-450/ssq) which is pow(exp(-450),1/ssq) which is pow(4e-196,1/ssq) > And what does it mean by less > than eps(1)? eps(1) is the smallest double precision number such that 1+eps(1) is different than 1. In standard IEEE double precision, eps(1) is basically 2^(-53) . If you have a numeric value which is 1 or greater and you attempt to add a numeric value less than eps(1), then the addition will have no practical effect. And that's what that exp() expression involving pw is about: calculating the distance at which contributions of values from pixels further away than the distance will have no practical effect on the result. The canny filter is defined in _theory_ as requiring one to calculate the contributions extending to infinity, but the fact is that due to floating point precision limitations, there is no point in going out to infinity; the expression figures out how far it is worth bothering going to. When you reduce pw to the range 1:1 then you are, by definition, not using a canny filter -- not unless your sigma is so _small_ that exp(-2/(sigma^2)) is smaller than the gaussian cut-off. That's probably somewhere around sigma < 0.233 . > The sigma I have been using is 5 or 10, since I want the > FWHM of the gaussian to cover at least 10 pixels of the 200x200. Did I > do that wrong? Lowering the upper limit on pw is equivalent to using a smaller sigma in the same proportion. Thus if you specified a sigma of 10, but change the upper limit on pw from 30 down to 1, the effect is as if you had left the upper limit at 30 but specified a sigma 1/30 as large -- i.e., sigma 10/30 = 1/3 in your case. |