V. quick image processing question
Could anybody give me a method to calculate a gausian matrix / kernal of unknown width, height and standard deviation Please.
publicdouble[][] gauss(int w,int h,int sd)
Could anybody give me a method to calculate a lapacian matrix / kernal of unknown width, height and standard deviation Please.
publicdouble[][] laplace(int w,int h,int sd)
public class Kernels {
public static void main(String[] args) {
double[][] result = gauss(41,41,5.0);
printKernel(result);
}
public static void printKernel(double[][] k) {
for(int j=0;j<k.length;j++) {
for(int i=0;i<k[j].length;i++) {
System.out.print(k[j][i]+",");
}
System.out.println();
}
}
// produces a 2D gaussian kernel with a unit height.
public static double[][] gauss(int w, int h, double sd) {
double[][] result = new double[h][w];
if(((w%2)==0) || ((h%2)==0)) throw new IllegalArgumentException("w and h must be odd numbers");
if((w><1)||(h<1)) throw new IllegalArgumentException("w and h must be greater then or equal to
1");
int cx = (w/2);
int cy = (h/2);
for( int j=0;j<h;j++) {
for(int i=0;i<w;i++) {
double r=Math.sqrt(((cx-i)*(cx-i))+((cy-j)*(cy-j)));
result[j][i] = Math.pow(Math.E,-((r*r)/(2.0*(sd*sd))));
}
}
return result;
}
}
Now its up to you to write the laplacien as I cannot be arsed to.
The above is not particularly useful as you normally want a 2D gaussian with a unit volume rather then
a unit height as the one above gives. I just cant remember the scaling factor.
matfud>
> > I only need to know how to calculate a gaussian and
> > laplacian kernals. Thank you NEway
>
> You want someone to write a method to compute
> gaussian
> kernel tables of arbitrary size for you for 4 duke
> dollars.
>
> Good luck :)
Just another example of someone passing up the opportunity of challenge and becoming more dependent in the process.