算法:
private int sum_rgb(string filename)
{
double[] a = new double[3] { 0, 0, 0 };
double[,] array = new double[1920, 1080];
Bitmap curBitmap = (Bitmap)Image.FromFile(filename);
int wide = curBitmap.Width;
int height = curBitmap.Height;
Color srcColor;
Color srcColor2;
double RR = 0;
double GG = 0;
double BB = 0;
double YY = 0;
//外挂配置档,大于多少像素就说明是黑点
int par_value = Convert.ToInt32(read_ini("Par", "ABSvalue"));
double YY2 = 0;
double YY3 = 0;
int kk = 0;
for (int y3 = 0; y3 < height; y3++)
{
for (int x3 = 0; x3 < wide; x3++)
{
srcColor = curBitmap.GetPixel(x3, y3);
RR = srcColor.R;
GG = srcColor.G;
BB = srcColor.B;
YY = RR * 0.299 + GG * 0.587 + BB * 0.114;
array[x3,y3] = YY;
}
}
//图片大小切成120乘120,每块大小为16乘9
for (int iii = 0; iii < 120; iii++)
{
for (int jjj = 0; jjj < 120; jjj++)
{
if (YY2 == 0)
{
for (int i = 0; i < 16; i++)
{
for (int j = 0; j < 9; j++)
{
YY2 += array[i + iii * 16, j + jjj * 9];
}
}
YY2 = YY2 / (144);
}
YY3 = 0;
for (int ii = 0; ii < 16; ii++)
{
for (int jj = 0; jj < 9; jj++)
{
if (Math.Abs(array[ii + iii * 16, jj + jjj * 9] - YY2) > par_value)
{
kk += 1;
}
YY3 += array[ii + iii * 16, jj + jjj * 9];
}
}
YY2 = YY3 / 144;
}
}
return kk;
}
返回有多少个这样的点大于所设定的像素值.