出于某种原因,当我尝试运行convolution2d程序时,我没有使用main方法获得输出。我在这做错了什么? 该程序应该在另一个文件中查看卷积2d方法,然后在下一个文件中返回。
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
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));
}
}
答案 0 :(得分:0)
System.out.println()无法打印数组。如果要打印数组的值,首先应该创建一个String(使用for循环可以迭代数组并构造字符串)