Ok, I need to create two arrays like this:
double[][] TrainPatterns = {
new double[] { 0.0, 0.0 },
new double[] { 0.0, 1.0 },
new double[] { 0.0, 2.0 }
};
double[][] TrainResults = {
new double[] { 0.0 },
new double[] { 1.0 },
new double[] { 1.0 }
};
But with 100 items each.
I am reading the values for arrays from an image (TrainPatterns contains x and y coordinates of a pixel, TrainResults contains the color of the pixel, 0 for black, 1 for white).
I am iterating through the image like this:
Bitmap objBitmap = new Bitmap("im.bmp");
for (int y = 0; y < objBitmap.Height; y++)
{
for (int x = 0; x < objBitmap.Width; x++)
{
// here I need to insert new double[] { (double)x, (double)y } to the
// TrainPatterns array
Color col = objBitmap.GetPixel(x, y);
if (col.R == 255 && col.G == 255 && col.B == 255)
{
// white color
// here I need to insert new double[] { 1.0 } to the
// TrainResults
}
if (col.R == 0 && col.G == 0 && col.B == 0)
{
// black color
// here I need to insert new double[] { 0.0 } to the
// TrainResults
}
}
}
How can I add items to those arrays dynamically in the for loop? I know that image has 10px width and 10px height so I know the arrays will both have 100 length.
You definitely want to allocate the array before you start looping, you’ll want to use the results after you’re done. And you ought to do something meaningful when the pixel isn’t white or black. Something like this:
Not sure about the lifetime of the bitmap, you ought to call objBitmap.Dispose() somewhere. Leverage the using statement.