The basic histogram algorithm is something like.
Up vote 2 down vote favorite 1 share g+ share fb share tw.
This is supposed to calculate the histogram of an 8-bit grayscale image. With a 1024x770 test bitmap, CreateTime ends up at around 890ms. How can I make this go (way, way) faster?
EDIT: I should mention that this doesn't actually compute the histogram yet, it only gets the values out of the bitmap. So I really should have asked, what is the fastest way to retrieve all pixel values from an 8-bit grayscale image? Public class Histogram { private static int, values; public Histogram(Bitmap b) { var sw = Stopwatch.StartNew(); values = new intb.
Width, b. Height; for (int w = 0; w Height; ++h) { valuesw, h = b. GetPixel(w, h).
R; } } sw.Stop(); CreateTime = (sw. ElapsedTicks / (double)Stopwatch. Frequency) * 1000; } public double CreateTime { get; set; } } c# performance histogram link|improve this question edited Jun 18 '09 at 21:10 asked Jun 18 '09 at 21:03Sam Pearson1,2972925 94% accept rate.
– C. Ross Jun 18 '09 at 21:10 Take a look at the link posted by McWafflestix. I used to do this in C++ but when I tried to migrate my lib to C#, it was at that site that I learnt the C# tools to fast pixel access.
– Andres Jun 18 '09 at 21:49.
The basic histogram algorithm is something like: int hist = new hist256; //at this point don't forget to initialize your vector with 0s. For(int I = 0; I I have one version of this algorithm written for C# using unmanaged code (which is fast) I don't know if is faster than your but feel free to take it and test, here is the code: public void Histogram(double histogram, Rectangle roi) { BitmapData data = Util. SetImageToProcess(image, roi); if (image.
PixelFormat! = PixelFormat. Format8bppIndexed) return; if (histogram.
Length GrayLevels) return; histogram.Initialize(); int width = data. Width; int height = data. Height; int offset = data.
Stride - width; unsafe { byte* ptr = (byte*)data. Scan0; for (int y = 0; y = null) return image. LockBits( roi, ImageLockMode.
ReadWrite, image. PixelFormat); return null; } I hope I could help you.
Right about the histogram, and right, that reading the pixels is the thing to optimize. – Mike Dunlavey Jun 18 '09 at 21:24.
You'll want to use the Bitmap. LockBits method to access the pixel data. This is a good reference on the process.
Essentially, you're going to need to use unsafe code to iterate over the bitmap data.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.