Home  >  Article  >  Java  >  java image convolution operation, Gaussian blur and Laplacian operator

java image convolution operation, Gaussian blur and Laplacian operator

黄舟
黄舟Original
2016-12-30 11:36:223262browse

Please read the before reading, thank you! <br><br> Regarding convolution, we have already mentioned it in the previous article. If you don’t understand, you can read the previous article. <br><br>After seeing the title, smart children should understand their direct relationship. For the convolution operation, different results can be obtained by using different templates (Mask). The convolution operation is implemented first. <br><br>The code is as follows: </preface></p><pre class="brush:java;toolbar:false">public void filter(double[][] mask) { toGray();//灰度化 int mh = mask.length; int mw = mask[1].length; int sh = (mh+1)/2; int sw = (mw+1)/2; double maskSum = math.sum(mask); int[] d= new int[w*h]; for(int i=(mh-1)/2+1;i<h-(mh-1)/2;i++){ for(int j=(mw-1)/2+1;j<w-(mw-1)/2;j++){ int s = 0; for(int m=0; m<mh ; m++){ for(int n=0;n<mw;n++){ s = s + (int)(mask[m] *this.data[j+n-sw +(i+m-sh)*w]); } } if(maskSum != 0) s /= maskSum; if(s < 0) s =0; if(s > 255) s = 255; d[j + i * w] = s; } } this.data = d; }

For the Gaussian template generated by the Gaussian kernel as follows:

java image convolution operation, Gaussian blur and Laplacian operator

java image convolution operation, Gaussian blur and Laplacian operator


The running results are as follows. The right side is the result generated by the Gaussian 7*7 template:

java image convolution operation, Gaussian blur and Laplacian operator

Sharpening template:

java image convolution operation, Gaussian blur and Laplacian operator

Run result:

java image convolution operation, Gaussian blur and Laplacian operator

Laplacian operator:

java image convolution operation, Gaussian blur and Laplacian operator

Run Result:

java image convolution operation, Gaussian blur and Laplacian operator

The above is the content of java image convolution operation, Gaussian blur and Laplacian operator. For more related content, please pay attention to the PHP Chinese website (www.php .cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn