Hi, I’m new to GitHub.

I’m writing a little image renderer in Java, so I also implemented a convolution algorithm, but I get a weird effect.

For example, here is the photo of a simple image, after the convolution is computed:

Original image:

Computed image:

And I used this matrix:

-1, -1, -1

-1, 8, -1

-1, -1, -1

Which is an edge detection matrix.

Now, why do I get a wrong result.

Here it is the algorithm code:

```
public void convolve(Kernel kernel, int mult){
int kwidth = kernel.width;
int kheight = kernel.height;
int widthrad = kwidth >>> 1;
int heightrad = kheight >>> 1;
int i, j, k, t; //indexes
double value;
double[][] kdata = kernel.kernel; //extracts the data from the kernel.
for(i = 0; i < width; i++){
for(j = 0; j < height; j++){
value = 0;
for(k = 0; k < kwidth; k++){
for(t = 0; t < kheight; t++){
value += kdata[k][t]*get2DCoordPixel(
getBound(i+k-widthrad, width),
getBound(j+t-heightrad, height));
}
}
drawPixel(i, j, (int) round(value*mult));
}
}
}
private int getBound(int val, int end){
if(val < 0) return 0;
if(val < end) return val;
return end - 1;
}
```

What am I doing wrong?

Thanks.

EDIT: Also, this algorithm is very slow. In my tests it takes about 100ms to compute a 1920x1080 image (using i3 8100 CPU). Is there a better alternative?