|
-
Jan 20th, 2004, 09:04 AM
#1
Thread Starter
Hyperactive Member
image processing
i'm writing an app to process images, some of the image i will be processing are over 16mb in size so the processing takes quite a while. the majority of my processing code is done in 4 for loop (1,2,3 and 4 below).
At the moment i'm trying to think of ways to improve the performance of the code. (depending on the colours in an image it can take over 30 minutes)
One thing i thougth i could do is to make each of the four for loops a thread. (because they don't need access any shared resources) would this be a good thing to do? and if so could someone give me some pointers on how to do it. i've looked at a few tutorials on free threading but i'm still not 100% sure hwo togo about it.
Code:
public void ProcessSelection()
{
//1
for (yIndex = 0; yIndex != beginY; yIndex++)
{
for (xIndex = 0; xIndex != xSize; xIndex++)
{
testCol = myBitmap.GetPixel(xIndex,yIndex);
//fullRGBString = testCol.R.ToString() + testCol.G.ToString() + testCol.B.ToString();
fullRGBString = testCol.ToArgb();
// try setting searched bits to white automatically
myBitmap.SetPixel(xIndex, yIndex, Color.White );
if (backgroundValues.Contains(fullRGBString))
{
//if already n arraylist then do nothing
}
else
{
backgroundValues.Add(fullRGBString);
}
}
}
Console.WriteLine("1 done");
//2
for (yIndex = endY; yIndex != ySize; yIndex++)
{
for (xIndex = 0; xIndex != xSize; xIndex++)
{
testCol = myBitmap.GetPixel(xIndex,yIndex);
//fullRGBString = testCol.R.ToString() + testCol.G.ToString() + testCol.B.ToString();
fullRGBString = testCol.ToArgb();
// try setting searched bits to white automatically
myBitmap.SetPixel(xIndex, yIndex, Color.White );
if (backgroundValues.Contains(fullRGBString))
{
//if already n arraylist then do nothing
}
else
{
backgroundValues.Add(fullRGBString);
}
}
}
Console.WriteLine("2 done");
//3
for (yIndex = beginY; yIndex != endY; yIndex++)
{
for (xIndex = 0; xIndex != beginX; xIndex++)
{
testCol = myBitmap.GetPixel(xIndex,yIndex);
//fullRGBString = testCol.R.ToString() + testCol.G.ToString() + testCol.B.ToString();
fullRGBString = testCol.ToArgb();
// try setting searched bits to white automatically
myBitmap.SetPixel(xIndex, yIndex, Color.White );
if (backgroundValues.Contains(fullRGBString))
{
//if already n arraylist then do nothing
}
else
{
backgroundValues.Add(fullRGBString);
}
}
}
Console.WriteLine("3 done");
//4
for (yIndex = beginY; yIndex != endY; yIndex++)
{
for (xIndex = endX; xIndex != xSize; xIndex++)
{
testCol = myBitmap.GetPixel(xIndex,yIndex);
//fullRGBString = testCol.R.ToString() + testCol.G.ToString() + testCol.B.ToString();
fullRGBString = testCol.ToArgb();
// try setting searched bits to white automatically
myBitmap.SetPixel(xIndex, yIndex, Color.White );
if (backgroundValues.Contains(fullRGBString))
{
//if already n arraylist then do nothing
}
else
{
backgroundValues.Add(fullRGBString);
}
}
}
Console.WriteLine("4 done");
for (xIndex = beginX; xIndex != endX; xIndex++)
{
for (yIndex = beginY; yIndex != endY; yIndex++)
{
testCol = myBitmap.GetPixel(xIndex,yIndex);
//fullRGBString = testCol.R.ToString() + testCol.G.ToString() + testCol.B.ToString();
fullRGBString = testCol.ToArgb();
if (fullRGBString != Color.White.ToArgb())
{
if (backgroundValues.Contains(fullRGBString))
{
myBitmap.SetPixel(xIndex, yIndex, Color.White);
}
}
}
}
Console.WriteLine("Done Selected");
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|