Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.applet.*;
- import java.awt.*;
- import java.awt.image.*;
- import java.net.*;
- import java.util.*;
- import java.io.*;
- import java.lang.Math.*;
- import java.awt.Color.*;
- /**
- * Convolution is the code for applying the convolution operator.
- */
- public class convolution {
- //convolution 2d program
- public static double [][] convolution2D(double [][] input,
- int width, int height,
- double [][] kernel,
- int kernelWidth,
- int kernelHeight){
- int smallWidth = width - kernelWidth + 1;
- int smallHeight = height - kernelHeight + 1;
- double [][] output = new double [smallWidth][smallHeight];
- for(int i=0;i<smallWidth;++i){
- for(int j=0;j<smallHeight;++j){
- output[i][j]=0;
- }
- }
- for(int i=0;i<smallWidth;++i){
- for(int j=0;j<smallHeight;++j){
- output[i][j] = singlePixelConvolution(input,i,j,kernel,
- kernelWidth,kernelHeight);
- //if (i==32- kernelWidth + 1 && j==100- kernelHeight + 1) System.out.println("Convolve2D: "+output[i][j]);
- }
- }
- return output;
- }
- //main program driverconv.java
- public class driverconv {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- convolution ce = new convolution();
- double[][] m1= {{1,2},{3,4}};
- double[][] m2= {{1,1},{1,1}};
- System.out.println(convolution.convolution2D(m1, 2, 2, m2, 2, 2));
- }
- }
Add Comment
Please, Sign In to add comment