c# - Gaussian Filter implemetation -


i preparing implement gaussian filter in c#, , in preparation reading literature on this. have disagreeing sources.

one book (japanese text: practical image processing introduction uchimura) specifies equation calculate template

w(u,v)= (1/2*pi*sigma^2) exp(-(x^2+v^2)/(2*sigma^2)).  

i think correct, although author links size , sigma size = 3*sigma.

finally excellent book (feature extraction & image processing computer vision nixon , aguado, p.106) gives correct equation, when implementing in code gives different implementation.

w(u,v)= (1/sum)* exp(-(x^2+v^2)/(2*sigma^2))  

where sum sum of values of exponentials. below pseudo code provide - think close matlab.

function template=gaussian_template(winsize,sigma) %template gaussian averaging %usage:[template]=gaussian_template(number, number) %parameters: winsize-size of template (odd, integer) % sigma-variance of gaussian function %author: mark s. nixon %centre half of window size centre=floor(winsize/2)+1; %we'll normalise total sum sum=0;  %so work out coefficients , running total i=1:winsize     j=1:winsize         template(j,i)=exp(-(((j-centre)*(j-centre))+((i-centre)*(i-centre)))/(2*sigma*sigma))         sum=sum+template(j,i);     end end %and normalise template=template/sum;  

although correct equation , code implementation give similar results degree, wondering why in same book implementation , equation different.

my question is, have of worked gaussian filtering implementations, , equation correct implement? idea why book gives simpler implementation?

both implementations normalizing sum of coefficients 1.0. second implementation computes sum manually exact figure , best way go. other implementation gives exact sum continuous version of filter. however, discretizing filter gives approximation approximated sum not same continuous integral.

side note: might want keep in mind gaussian non-linear across single pixel. sampling @ pixel centers give inaccurate result. better sample @ sub-pixel , average on entire pixel.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -