In short: why would Imgproc.calcHist work on 2, but not on 3 (or more) channels/dimensions? Is this a bug? If so, is it already reported, maybe even worked on? Can we expect a fix any time soon? And if not - or in any way - what are my options to deal with this? Any suggestions/workarounds?
In full; the following code:
public class Histogram3D {
private List<Mat> images;
private MatOfInt channels;
private Mat mask;
private Mat hist;
private MatOfInt histSize;
private MatOfFloat ranges;
public Histogram3D() {
histSize = new MatOfInt(256, 256, 256);
ranges = new MatOfFloat(0.0f, 255.0f,
0.0f, 255.0f,
0.0f, 255.0f);
channels = new MatOfInt(0, 1, 2);
mask = new Mat();
hist = new Mat();
}
public void computeHistogram(Mat image) {
images = new ArrayList<>();
images.add(image);
Imgproc.calcHist(images, channels, mask, hist, histSize, ranges);
}
// ...
...results with a hist of type -1x-1xCV_32FC1. While I don't get an error or anything, this is just garbage. :(
But then, on the other hand, the following code:
public class Histogram3D {
private List<Mat> images;
private MatOfInt channels;
private Mat mask;
private Mat hist;
private MatOfInt histSize;
private MatOfFloat ranges;
public Histogram3D() {
histSize = new MatOfInt(256, 256);
ranges = new MatOfFloat(0.0f, 255.0f,
//0.0f, 255.0f,
0.0f, 255.0f);
channels = new MatOfInt(0, 1);
mask = new Mat();
hist = new Mat();
}
public void computeHistogram(Mat image) {
images = new ArrayList<>();
images.add(image);
Imgproc.calcHist(images, channels, mask, hist, histSize, ranges);
}
// ...
...ends up with a flawless histogram of type 256x256xCV_32FC1. Wait, what?
What kind of bug/mess is this? While it's nice to get a histogram for only 2 channels, have a second/closer look at the returned Mat. A single-channel(!) 256x256 matrix? Really? Wouldn't you've expected to get a 256x1xCV_32FC2 or something?
I mean... I have a weird feeling as to why the above code fails to compute a histogram for 3 channels. Or have you ever seen a 256x256x256 matrix around here? ;)
So... what are my options to compute my 3-channel/dimensional histogram? :/
Thanks. :)