【发布时间】:2015-07-14 13:18:23
【问题描述】:
在第 28 行,我想用 ch 数组替换 values。如果您运行该程序,直方图的值将出现在文件的开头。 .arff 文件打印正确,但 values 在 @data 字段中。显然,ch 是一个不兼容的类型。 Java中这种结构的修饰符是什么?
public static void main(String[] args) throws Exception
{
int i;
int[][][] ch = new int[4][4][4];
FastVector attributes;
Instances dataSet;
double[] values;
attributes = new FastVector();
for (i = 0; i < 512; i++)
attributes.addElement(new Attribute("bin" +(i+1))) ;
dataSet = new Instances("NormalizedHistogram_512bins", attributes, 3);
/*28*/ values = new double[dataSet.numAttributes()];
values[0] = 3;
values[1] =7;
values[3] = 1;
dataSet.add(new Instance(1.0, values));
values = new double[dataSet.numAttributes()];
values[2] = 2;
values[3] = 8;
/*37*/ dataSet.add(new Instance(1.0, values));
BufferedImage Image = ImageIO.read(new File("airplane_training1.jpg"));
for(int x = 0; x < Image.getWidth(); x++)
for(int y = 0; y < Image.getHeight(); y++) {
int color = Image.getRGB(x, y);
int alpha = (color & 0xff000000) >> 24;
int red = (color & 0x00ff0000) >> 16;
int green = (color & 0x0000ff00) >> 8;
int blue = color & 0x000000ff ;
ch[red / 64][green / 64][blue / 64]++;
}
for(int k = 0; k < ch.length; k++)
for(int j = 0; j < ch[k].length; j++)
for(int p = 0; p < ch[k][j].length; p++)
System.out.println( ch[k][j][p]);
NonSparseToSparse nonSparseToSparseInstance = new NonSparseToSparse();
nonSparseToSparseInstance.setInputFormat(dataSet);
Instances sparseImage = Filter.useFilter(dataSet, nonSparseToSparseInstance);
System.out.println(sparseImage);
ArffSaver arffSaverInstance = new ArffSaver();
arffSaverInstance.setInstances(sparseImage);
arffSaverInstance.setFile(new File("ESDN.arff"));
arffSaverInstance.writeBatch();
}
}
【问题讨论】:
-
已解决。我在 IDreamInCode 上发布了这个问题,但没有得到回复,我自己设法解决了这个问题。
标签: java arrays histogram arff