+= return 不是新分配的值吗?
Doesn't += return the newly assigned value?
我正在遍历图像并对所有像素的值求和。我这样做是为了创建一个完整的图像。为了让最后一个值易于使用,我创建了 the_sum
变量,我为每个像素添加了值。
如果您知道积分图像的工作原理,您就会知道此类图像中的每个像素都包含 加上 之前所有像素的总和。
因此:
integral_image[x][y][0] = (the_sum[0]+= (pixel & 0x00FF0000)>>16);
我增加总和并将其分配给当前像素。然而,Netbeans IDE 警告我,我不是在阅读 the_sum
.
算法中的某些内容已损坏,我不确定是什么。是我的方法有误还是 NetBeans 的误报?
为了避免误解,这是整个方法:
/* Generate an integral image. Every pixel on such image contains sum of colors or all the
pixels before and itself.
*/
public static double[][][] integralImage(BufferedImage image) {
int w = image.getWidth();
int h = image.getHeight();
double integral_image[][][] = new double[w][h][3];
double the_sum[] = new double[3];
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
int pixel = image.getRGB(x, y);
integral_image[x][y][0] = (the_sum[0]+= (pixel & 0x00FF0000)>>16);
integral_image[x][y][1] = (the_sum[1]+= (pixel & 0x0000FF00)>>8);
integral_image[x][y][2] = (the_sum[2]+= pixel & 0x000000FF);
}
}
return integral_image;
}
是的,+=
returns 新分配的值。这是来自 netbeans 的误报。
At run time, the result of the assignment expression is the value of the variable after the assignment has occurred.
http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.26
我正在遍历图像并对所有像素的值求和。我这样做是为了创建一个完整的图像。为了让最后一个值易于使用,我创建了 the_sum
变量,我为每个像素添加了值。
如果您知道积分图像的工作原理,您就会知道此类图像中的每个像素都包含 加上 之前所有像素的总和。
因此:
integral_image[x][y][0] = (the_sum[0]+= (pixel & 0x00FF0000)>>16);
我增加总和并将其分配给当前像素。然而,Netbeans IDE 警告我,我不是在阅读 the_sum
.
算法中的某些内容已损坏,我不确定是什么。是我的方法有误还是 NetBeans 的误报?
为了避免误解,这是整个方法:
/* Generate an integral image. Every pixel on such image contains sum of colors or all the
pixels before and itself.
*/
public static double[][][] integralImage(BufferedImage image) {
int w = image.getWidth();
int h = image.getHeight();
double integral_image[][][] = new double[w][h][3];
double the_sum[] = new double[3];
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
int pixel = image.getRGB(x, y);
integral_image[x][y][0] = (the_sum[0]+= (pixel & 0x00FF0000)>>16);
integral_image[x][y][1] = (the_sum[1]+= (pixel & 0x0000FF00)>>8);
integral_image[x][y][2] = (the_sum[2]+= pixel & 0x000000FF);
}
}
return integral_image;
}
是的,+=
returns 新分配的值。这是来自 netbeans 的误报。
At run time, the result of the assignment expression is the value of the variable after the assignment has occurred.
http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.26