我正在尝试计算 java 中图像的标准偏差。我正在使用 rast.Sample 来获取每个灰度级,然后将其从均值中取出并对其进行平方。
我的代码是:
public int standardDeviation(BufferedImage source)
{
int width = source.getWidth();
int height = source.getHeight();
int totalPixels = width * height;
int temp = 0;
int VarianceSum = 0;
double SumSquared = 0;
int mean = mean(source);
double variance = 0;
int StandardDeviation = 0;
Raster rast = source.getRaster();
//Loop through rast getting each grey level.
for(int i =0; i<width; i++)
{
for(int j=0; j<width; j++)
{
temp = rast.getSample(i,j,0);
VarianceSum += (temp - mean);
SumSquared = Math.pow(VarianceSum,2);
}
}
variance = SumSquared/totalPixels;
System.out.println(temp);
System.out.println(VarianceSum);
//System.out.println(SumSquared);
System.out.println(totalPixels);
return StandardDeviation;
}
我在做傻事!请帮忙