Still using getPixels?

Posted Tuesday, March 07, 2006 1:15 AM by Shunjie
I was coding a image processing application using c# today. My task is very simple, for each image, divide it into 8 x 8  pixel block. For each block, gets its DCT, quantized it, and finally the histogram of its YCrCb. It is a very simple for-loop with multiplication and calculations of matrix.

Been a noob in handling in images, I manually loop through the jpeg files, and used getPixel to get the information of the image at pixel level, and do the calculations. A small 500 x 375 picture took...11 seconds....

Googling a while, i realize its the getPixel method. I suppose this is pretty well known, just that most of the time I am coding asp.net so never touch this department before, haha. A few more googling effort reveals this page

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp11152001.asp

Got to use unsafe codes to access the bitmap instead. After changing getPixel to the class's PixelAt, the same calculate takes 0.5708208 seconds.

11 minutes vs 0.57 seconds..what a huge performance difference!


Filed under: ,