Color (>2-channel) Histogram, Java API
In short: why would Imgproc.calcHist work on 2, but not on 3 (or more) channels/dimensions? Is this a bug? If so, has it already been reported (someone working on this)? Can we expect a fix any time soon? And if not - or regardless - 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. Hmm, granted, how should hist even look like with 3 dimensions? 256x256x256xCV_32FC1 does not compute. I've never seen a 256x256xCV_32FC256-Mat before... How about (256x256)x256xCV_32FC1 maybe? A list/an array of 256 256x256xCV_32FC1 would sound reasonable, but the methods signature wouldn't fit that any longer? ...
So... what are my options to compute my 3-channel/dimensional histogram? (But ok, if my concern is a "color histogram", I might wanna check out other color spaces...)
Thanks. :)
I have the same problem in java. Did you solve it or you just move to C++ to solve this?