huangyuan01 / aforge

Automatically exported from code.google.com/p/aforge
Other
0 stars 0 forks source link

Imagestatistics returns incorrect values. #234

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Load a 1280x1024 grayscale image
2. Use Imagestatistics to find the mean and std dev
3. Both mean and Std dev are incorrect

What is the expected output? What do you see instead?
The mean and standard deviation for larger images (1280x1024 tested) is 
slightly off. I am using the Gray.Mean and Gray.StdDev values.
For the tested images, the correct mean is 45.298, Imagestatistics returns 
46.811. Correct Stddev is 9.3673, Imagestatistics returns 9.3123
If I crop the image to 1024x1024 the values from Imagestatistics are correct.
What version of the product are you using?
2.1.5, downloaded last Friday.

Please provide any additional information below.
I attached the file I am using to test these image statistics.

Original issue reported on code.google.com by carrasm...@gmail.com on 18 Jul 2011 at 5:26

Attachments:

GoogleCodeExporter commented 8 years ago
I have narrowed down the problem to NOT being dependent on image size, but 
rather on the image itself. If you run the Imagestatistics on the attached 
image, then open the image and save it without modification (using Gimp or the 
like), you will get different values for the mean and stdDev with the re-saved 
image. Both images should be identical, so not sure why values are not the same.
Using another program, such as Matlab, both images will return the same 
statistical values.
Perhaps there is something in the .bmp file format that is causing a change in 
the statistics calculation using AForge? Something other than actual pixel data 
that gets changed when re-saved?

Original comment by carrasm...@gmail.com on 18 Jul 2011 at 6:15

GoogleCodeExporter commented 8 years ago
> Perhaps there is something in the .bmp file format that is causing a change 
in the statistics calculation using AForge? 
AForge does not care about the file format at all. File is opened using 
standard .NET's method. AForge just works with bitmap class.

Original comment by andrew.k...@gmail.com on 18 Jul 2011 at 7:40

GoogleCodeExporter commented 8 years ago
Tested the image and the re-saving idea using GIMP. Yes, mean and std.dev. are 
different if we apply ImageStatistics to original image or the re-saved image. 
However, I am not convinced that there is bug in the way image statistics is 
calculated (or maybe not convinced yet) …

Here is the thing. You say that mean value must be 45.298 and std.dev. must be 
9.3673. If we apply image statistics to the re-saved image, then we get exactly 
the same values. Which means the calculations itself are correct.

The fact is that mean and std.dev. are not correct for the original image does 
not mean there is a problem in AForge.NET's calculations. As an example, 
AForge.NET does not care about things like palette - when calculating 
statistics it only cares about pixel values. I am not saying this a cause of 
the problem. I just want to say there may be something wrong with the original 
image itself.

Original comment by andrew.k...@gmail.com on 13 Sep 2011 at 8:09