I found a similar question: creating histogram using emgu cv c#
and it works well when i passed grayscaled images, but when i use the Matrix, program throws exceptions. my code:
Matrix<double> mat = new Matrix<double>(10, 10);
mat.SetRandUniform(new MCvScalar(0.0), new MCvScalar(20.0));
DenseHistogram histo = new DenseHistogram(5, new RangeF(0.0f, 20.0f));
histo.Calculate(new Matrix<double>[] { mat }, false, null);//<--throws exception here
CvInvoke.cvShowImage("Mat Histogram", histo.GetHistogramImage().Ptr);
CvInvoke.cvWaitKey(0);
and the declaration in emgu doc is:
public void Calculate<TDepth>(
Matrix<TDepth>[] matrices,
bool accumulate,
Matrix<byte> mask
)
where TDepth : new()
i cant figure out what's wrong :(
The problem you are facing off consist on a limitation in DenseHistogram class that when invoking cvCalcArrHist throws an "Unsupported format or combination of formats".
This class compute only on float and not on double.
Matrix<float> mat = new Matrix<float>(10, 10);
mat.SetRandUniform(new MCvScalar(0.0), new MCvScalar(20.0));
DenseHistogram histo = new DenseHistogram(5, new RangeF (0.0f, 20.0f));
histo.Calculate(new Matrix<float>[] { mat }, false, null); //runs fine :)
A better design should also let the user specify also ranges using generics, Range<double>
instead of static RangeF
class.