}
}
}
intvy = 500, ny = 0;
for (int x = 0; x <src.Width; x++)
{
//top
for (int y = 0; y <src.Height; y++)
{
if (polynom[y, x] == 1f)
{
pixel = Color.Black;
res.SetPixel(x, y, pixel);
if (y <vy) vy = y;
break;
}
else
{
pixel = Color.Blue;
dest.SetPixel(x, y, pixel);
}
}
//bottom
for (int y = src.Height-1; y > 0; y--)
{
if (polynom[y, x] == 1f)
{
pixel = Color.Black;
res.SetPixel(x, y, pixel);
if (y >ny) ny = y;
break;
}
else
{
pixel = Color.Blue;
dest.SetPixel(x, y, pixel);
}
}
}
#endregion
MyPoint point = newMyPoint(lx, rx, 40+vy, ny);
getParameters(point, dest, image);
//res.Save("counter.bmp");
return res;
}
publicstaticfloat[,] normalization(int[,] b)
{
//(x-min)/(max-min)
int min = minM(b);
int max = maxM(b);
float[,] a = getFloatMas(b);
for (int y = 0; y <a.GetLength(0); y++)
for (int x = 0; x <a.GetLength(1); x++)
{
a[y, x] = (float)(a[y, x] - min) / (max - min);
}
return a;
}
publicstaticintmaxM(int[,] a)
{
int max = -10000;
for (inti = 0; i<a.GetLength(0); i++)
{
for (int j = 0; j <a.GetLength(1); j++)
if (a[i,j] > max)
{
max = a[i,j];
}
}
return max;
}
publicstaticintminM(int[,] a)
{
int min = 10000;
for (inti = 0; i<a.GetLength(0); i++)
{
for (int j = 0; j <a.GetLength(1); j++)
if (a[i, j] < min)
{
min = a[i, j];
}
}
return min;
}
publicstaticfloat[,] getFloatMas(int[,] a)
{
float[,] b = newfloat[a.GetLength(0), a.GetLength(1)];
for (int y = 0; y <a.GetLength(0); y++)
for (int x = 0; x <a.GetLength(1); x++)
b[y, x] = (float)a[y, x];
return b;
}
privatestaticvoidgetParameters(MyPoint point, Bitmapdest, MyImage image)
{
//Dispersia
//1. Mat
double Mat = 0;
int k = 0;
int t = 0;
for (int y = point.getMinY(); y <point.getMaxY(); y++)
for (int x = point.getMinX(); x <point.getMaxX(); x++)
{
ColorcurrentPix = dest.GetPixel(x, y);
if (currentPix != Color.Blue&¤tPix != Color.Black)
{
floatff = currentPix.GetBrightness() * 255f;
if (ff< 100f) t++;
Mat = Mat + currentPix.GetBrightness()*255f;
k++;
}
}
Mat = Mat / k;
//2. Disp
doubleDisp = 0;
for (int y = point.getMinY(); y <point.getMaxY(); y++)
for (int x = point.getMinX(); x <point.getMaxX(); x++)
{
ColorcurrentPix = dest.GetPixel(x, y);
if (currentPix != Color.Blue&¤tPix != Color.Black)
{
Disp = Disp + (currentPix.GetBrightness() * 255f) * (currentPix.GetBrightness() * 255f) - Mat * Mat;
}
}
Disp = Disp / (k - 1);
image.setDisp(Disp);
//diametr = max_x - min_x
double d = (point.getMaxX() - point.getMinX()) / 2000.0; //20 пикс = 1см -> /100 переводвметры
d = d >0.20 ? d - 0.06 : d;
d = d >0.15 ? d - 0.02 : d;
image.setD(d);
//V = (pi*D^3)/6
double v = (Math.PI * Math.Pow(d, 3)) / 6.0;
image.setV(v);
//m = V * ro
double mas = 0;
if (Disp< 1450)
{
mas = v * 420.0;
}
else
{
mas = v * 320.0;
}
image.setMas(mas);
//dest.Save("blue.bmp");
}
}