T
trant
I am scanning an an input image and mapping certain zones of the image by a
pre-defined color map to a Zone class. Based on a certain value in this zone
I assign a new color to a copy of the input image
IT seems like a simple process, but in computer terms it takes forever. A
few solid seconds at least.
What am I doing wrong here?
Example code:
public class Zone
{
public int someValue;
}
Dictionary<Color, Zone> colorMap = new Dictionary<Color, Zone>();
// fill colorMap with data
long start = DateTime.Now.Ticks;
Bitmap input = (Bitmap)Bitmap.FromFile(inputfile);
Bitmap output = new Bitmap(map.Width, map.Height);
for (y = 0; y < input.Height; y++)
{
for (int x = 0; x < input.Width; x++)
{
Color c = input.GetPixel(x, y);
if (colorMap.ContainsKey(c))
{
Zone zone = colorMap[c];
if (zone.someValue > 0)
{
if (zone.someValue > 5000)
output.SetPixel(x, y, Color.Cyan);
else if (zone.someValue >= 1000)
output.SetPixel(x, y, Color.Yellow);
else
output.SetPixel(x, y, Color.Red);
}
else
output.SetPixel(x, y, Color.Black);
}
else
output.SetPixel(x, y, Color.Black);
}
}
Console.WriteLine("Scanned map in " + (DateTime.Now.Ticks - start) /
TimeSpan.TicksPerMillisecond);
This here took me 50795 milliseconds!!
The image is 5616 x 2160 dimensions. Not a small image but I can go into
something like Paint.NET and perform filters on this thing in a split second.
pre-defined color map to a Zone class. Based on a certain value in this zone
I assign a new color to a copy of the input image
IT seems like a simple process, but in computer terms it takes forever. A
few solid seconds at least.
What am I doing wrong here?
Example code:
public class Zone
{
public int someValue;
}
Dictionary<Color, Zone> colorMap = new Dictionary<Color, Zone>();
// fill colorMap with data
long start = DateTime.Now.Ticks;
Bitmap input = (Bitmap)Bitmap.FromFile(inputfile);
Bitmap output = new Bitmap(map.Width, map.Height);
for (y = 0; y < input.Height; y++)
{
for (int x = 0; x < input.Width; x++)
{
Color c = input.GetPixel(x, y);
if (colorMap.ContainsKey(c))
{
Zone zone = colorMap[c];
if (zone.someValue > 0)
{
if (zone.someValue > 5000)
output.SetPixel(x, y, Color.Cyan);
else if (zone.someValue >= 1000)
output.SetPixel(x, y, Color.Yellow);
else
output.SetPixel(x, y, Color.Red);
}
else
output.SetPixel(x, y, Color.Black);
}
else
output.SetPixel(x, y, Color.Black);
}
}
Console.WriteLine("Scanned map in " + (DateTime.Now.Ticks - start) /
TimeSpan.TicksPerMillisecond);
This here took me 50795 milliseconds!!
The image is 5616 x 2160 dimensions. Not a small image but I can go into
something like Paint.NET and perform filters on this thing in a split second.