Guest User

Untitled

a guest
Feb 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. import java.applet.*;
  2. import java.awt.*;
  3. import java.awt.image.*;
  4. import java.net.*;
  5. import java.util.*;
  6. import java.io.*;
  7. import java.lang.Math.*;
  8. import java.awt.Color.*;
  9.  
  10. /**
  11. * Convolution is the code for applying the convolution operator.
  12. */
  13. public class convolution {
  14.  
  15. //convolution 2d program
  16.  
  17. public static double [][] convolution2D(double [][] input,
  18. int width, int height,
  19. double [][] kernel,
  20. int kernelWidth,
  21. int kernelHeight){
  22. int smallWidth = width - kernelWidth + 1;
  23. int smallHeight = height - kernelHeight + 1;
  24. double [][] output = new double [smallWidth][smallHeight];
  25. for(int i=0;i<smallWidth;++i){
  26. for(int j=0;j<smallHeight;++j){
  27. output[i][j]=0;
  28. }
  29. }
  30. for(int i=0;i<smallWidth;++i){
  31. for(int j=0;j<smallHeight;++j){
  32. output[i][j] = singlePixelConvolution(input,i,j,kernel,
  33. kernelWidth,kernelHeight);
  34. //if (i==32- kernelWidth + 1 && j==100- kernelHeight + 1) System.out.println("Convolve2D: "+output[i][j]);
  35. }
  36. }
  37. return output;
  38. }
  39.  
  40.  
  41.  
  42.  
  43. //main program driverconv.java
  44.  
  45. public class driverconv {
  46.  
  47. public static void main(String[] args) {
  48. // TODO Auto-generated method stub
  49. convolution ce = new convolution();
  50. double[][] m1= {{1,2},{3,4}};
  51. double[][] m2= {{1,1},{1,1}};
  52.  
  53.  
  54. System.out.println(convolution.convolution2D(m1, 2, 2, m2, 2, 2));
  55.  
  56. }
  57.  
  58. }
Add Comment
Please, Sign In to add comment