Threads and Images

Published 2009-07-22 on Farid Zakaria's Blog

So trying to learn a bit about concurrent programming prior to my class next semester and thought a good way to learn would be to write a simple application. Kinda odd how simple apps seem to grow so quickly into something that is beyond my scope of knowledge.

I wanted to originally write a simple image manipulation tool, as I thought it would be neat to look into really basic manipulatoin and try and perform them on separate threads. I had initially thought of doing it somewhat similar to what I head learned in CS370 of breaking the image into smaller images and offloading the processing onto small threads. There seemed a pretty good class offered in the .NET framework for this sort of thing; the threadpool class.

However nothing turned out as I had expected and trying to use the threadPool class was nightmarish. I think partially the reason may be is that I am not setting up the image object properly so that multiple threads can access it. I guess the two approaches were either:

  1. Manipulate the actual image file and refresh the component with the new image every time a thread is done executing
  2. Manipulate the pixels that are actually being displayed.

Either or it didn’t seem to work.

Scaling Back

Decided to scale back my attempts and just decided to go for a 1 thread (backgroundworker) approach. I had succesffuly done grey scaling (which was neat to learn on how something so simple can actually be pretty intense if you want to make the greyscale perfect). I had chosen to use the values :


private const RED_FACTOR = 0.299;
private const GREEN_FACTOR = 0.587
private const BLUE_FACTOR = 0.114

            
Color currPixelColor =originalImage.GetPixel(i, j);
double red = RED_FACTOR* currPixelColor.R;
double blue = BLUE_FACTOR * currPixelColor.B;
double green=GREEN_FACTOR*currPixelColor.G;
double grey = red + blue + green;
changedImage.setPixel(i , j , grey , grey , grey);

I then tried to put RGB sliders, however I seemed to have hit a wall in making the sliders feel really responsive. I guess I would appreciate help from anyone if they have any ideas on how to do it.
[caption id="attachment_71" align="alignleft" width="395" caption="Here is the application with an image greyscaled."]Here is the application with an image greyscaled.[/caption]