【发布时间】:2014-06-05 05:13:34
【问题描述】:
我知道有很多关于删除重复项,但我似乎无法正确处理,我想知道是否有人能告诉我我做错了什么。因此,下面的代码包含一个嵌套的 for 循环,它遍历图像(由大小为 256x256 的矩阵组成),然后将其传递给 ImagePlus 以计算半径、θ 和值。问题是半径中有重复项,我想为每个重复项总结如下值:
......
r=1.44 mm/c (167), value=63
r=1.43 mm/c (167), value=77
r=1.43 mm/c (168), value=70
r=1.42 mm/c (169), value=63
r=1.42 mm/c (169), value=64
r=1.41 mm/c (170), value=70
r=1.41 mm/c (171), value=67
r=1.40 mm/c (171), value=71
...........
所以应该是这样的:
r= 1.43, value=147 (70+77)
r= 1.42, value= 127 (63+64)
r= 1.41, value= 137 (70+67)
....
这是我一直在尝试的,但我没有任何运气!我也尝试过使用 Sets,但我需要它按特定顺序排列,它不能把它搞砸。
final XYSeries data = new XYSeries("Third");
double rMax = -1;
double [][] radiusArray = new double[256][256];
double [][] valueArray = new double[256][256];
for(int i =0; i< 256; i++){
for(int y =0; y< 256; y++){
//image.getPixel(i, y);
//This is taking the pixel position and calculating the r and value at that pixel
String x = image.getLocationAsString(i, y);
String n = image.getValueAsString(i, y);
String delim = ", value=";
String [] tokens = n.split(delim);
double num = Double.parseDouble(tokens[1]);
//if(image.getR() < 1.43){
String [] t = x.split("r=");
String[] b = t[1].split(" mm/c");
//System.out.print("Meet b: "+b[0]);
double radius = Double.parseDouble(b[0]);
String [] theta = x.split("theta= ");
String [] token2 = theta[1].split(Character.toString(IJ.degreeSymbol));
float thetaNum = Float.parseFloat(token2[0]);
//System.out.print(" This is the theta value: "+thetaNum+" ");
if(radius > rMax){
rMax = radius;
}
radiusArray[i][y] = radius;
valueArray[i][y] = num;
//if(thetaNum <= 180.00){
System.out.print(x);
System.out.print(n);
System.out.print(" "+num);
System.out.println();
data.add(radius, num);
//}
//}
}
}
更新:
所以我能够摆脱重复,但现在它似乎每隔一个数字就跳过一次,我不知道为什么?
double summation;
for(int i=1; i< 256; i++){
for(int y=1; y< 256; y++){
if(radiusArray[i] != radiusArray[y]){
//System.out.print("its okay"+radiusArray[i][y]+" ");
String n = image.getValueAsString(i, y);
//System.out.println(valueArray[i][y]);
String delim = ", value=";
String [] tokens = n.split(delim);
double num = Double.parseDouble(tokens[1]);
// System.out.print(radiusArray[i][y]);
// System.out.println(" value= "+num);
}
else{
String n = image.getValueAsString(i, y);
String m = image.getValueAsString(i-1, y-1);
String delim = ", value=";
String [] tokens = n.split(delim);
double num = Double.parseDouble(tokens[1]);
String mDelim = ", value=";
String [] mtokens = m.split(delim);
double mnum = Double.parseDouble(tokens[1]);
summation = mnum+ num;
System.out.print(radiusArray[i][y]);
System.out.println(" value= "+summation);
}
}
}
这是我现在得到的:
1.64 value= 186.0
1.62 value= 130.0
1.61 value= 120.0
1.59 value= 150.0
1.58 value= 134.0
1.56 value= 130.0
1.55 value= 136.0
1.54 value= 108.0
1.52 value= 144.0
1.51 value= 118.0
【问题讨论】:
标签: java duplicates