Hi!
I want to calculate the median color (along some other data) of the
pixels of an image from its histogram:
std::vector<int> m_Hist;
// m_Hist[i] contains number of pixels with color i.
using namespace boost::accumulators;
accumulator_set
On 9/1/2010 5:19 AM, Maximilian Matthe wrote:
Hi!
I want to calculate the median color (along some other data) of the pixels of an image from its histogram: <snip> So, what am I doing wrong with accumulators?
I'm the maintainer of the accumulators library, but I had help with the statistical accumulators. In short, I don't know the answer to your question, but I'm routing it appropriately. Matthias? -- Eric Niebler BoostPro Computing http://www.boostpro.com
Hi Maximilian,
The problem with the median seems to be that you are not using Boost.Accumulator in the intended watt. What you do is that you create a histogram of the distribution, and then you want to use the library to calculate statistical properties from this histogram instead of the original sample values. This however introduces correlations into your samples: they are monotonically increasing.
For values like the mean, variance, skewness, ... this will still work. However, since there is no exact method of calculating the median without storing all values the median is approximated in Boost.Accumulator. That approximation will however be bad if you first sort the data as you essentially do.
The short answer is that Boost.Accumulator is not the right library for getting the median from a histogram, and it is also not the most efficient library for the other quantities in your case.
Matthias
Sent from my iPad
On Sep 1, 2010, at 17:19, Maximilian Matthe
Hi!
I want to calculate the median color (along some other data) of the pixels of an image from its histogram:
std::vector<int> m_Hist; // m_Hist[i] contains number of pixels with color i.
using namespace boost::accumulators; accumulator_set
, double> acc;
for(int i = 0; i < 256; i++) acc(i, weight = m_Hist[i]);
float mm = weighted_mean(acc); float stdD = sqrtf(weighted_variance(acc)); float med = weighted_median(acc); float sk = weighted_skewness(acc);
mean und stdD work correctly, but the median is too large. It gives me about 200, but the real value should be around 75 (I checked that manually). The skewness is around 11000 (which also seems quite large to me).
So, what am I doing wrong with accumulators?
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi Matthias, Thanks for your advice! I now tried to insert the actual pixel values into the accumulator. The median is now calculated (almost) correctly. That's sufficient for my application. Maybe it would be good to extend the documentation by mentioning that the median cannot be estimated well, if the inserted data is sorted? Because most people know how to use the median but not, how to estimate it. (maybe there are more such statistical parameters?). You also mentioned, Accumulators is not the best library for my needs, what would you suggest? Thanks, Max Matthias Troyer schrieb:
Hi Maximilian,
The problem with the median seems to be that you are not using Boost.Accumulator in the intended watt. What you do is that you create a histogram of the distribution, and then you want to use the library to calculate statistical properties from this histogram instead of the original sample values. This however introduces correlations into your samples: they are monotonically increasing.
For values like the mean, variance, skewness, ... this will still work. However, since there is no exact method of calculating the median without storing all values the median is approximated in Boost.Accumulator. That approximation will however be bad if you first sort the data as you essentially do.
The short answer is that Boost.Accumulator is not the right library for getting the median from a histogram, and it is also not the most efficient library for the other quantities in your case.
Matthias
Sent from my iPad
participants (3)
-
Eric Niebler
-
Matthias Troyer
-
Maximilian Matthe