c# - Normalizing an image after (gaussian) filtering -


i have implemented gaussian filter following algorithm of nixon aguado. algorithm (after finding template described here gaussian template) following.

the pseudo code in matlab style believe.

function convolved=convolve(image,template) %new image point brightness convolution of template image %usage:[new image]=convolve(image,template of point values) %parameters:image-array of points % template-array of weighting coefficients %author: mark s. nixon %get image dimensions [irows,icols]=size(image); %get template dimensions [trows,tcols]=size(template); %set temporary image black temp(1:irows,1:icols)=0;  %half of template rows trhalf=floor(trows/2); %half of template cols tchalf=floor(tcols/2); %then convolve template x=trhalf+1:icols-trhalf %address columns except border     y=tchalf+1:irows-tchalf %address rows except border         sum=0;         iwin=1:trows %address template columns             jwin=1:tcols %address template rows                 sum=sum+image(y+jwin-tchalf-1,x+iwin-trhalf-1)* template(jwin,iwin);             end         end         temp(y,x)=sum;     end end  %finally, normalise image convolved=normalise(temp);  

anyway, worries me last part "normalise". have tried algorithm (written in c#) , pixels got value 255.00000003 (which larger 255). should "normalise" results enlarge 0-255 range? wouldn't modifying image (other gaussian) wan't operation involve gaussian filter , nothing else.


edit: have eliminated "normalization" , seems works well, have no idea why authors of book recommended it. still, worries me program crash if reason value > 255 appears , cannot drawn.

as has been pointed out others in comments, normalizing image in sense ensures range of each channel 0 255 bad.

normalizing image in sense each value clamped between 0 , 255 should not necessary appropriate filter kernel. in practise can necessary or useful because of way floating point numbers work. floating point numbers can't represent every possible real number, , every computation can introduce inaccuracy. might cause of 255.00000003 1 of values.

like many signal processing algorithms, 1 assumes discrete time/space, continous values. it's easier reason kind of algortihms , describe them mathematically.

on computer don't have continuous values. images use discrete values, integer between 0 , 255 each channel (8 bit per channel). sound encoded 16 bit per channel.

in vast majority of cases perfeectly acceptable, yet filter (although non-linear one) after gaussian filter output. yes, in strict sense modify output of gaussian filter, either when save image or when display on screen.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -