Ask Your Question

How to access 3D histogram data - OpenCV Java

asked 2014-04-25 14:34:40 -0500

Unni gravatar image

I am writing a java program to calculate a 3-Dimensional histogram of R,G,B channels. I am unable to find out how to access the resulting 3 dimensional histogram (the Mat object which represents the histogram). My code is like below -

        Mat sourceMat = Highgui.imread(args[0]);        
        List<Mat> sourceImages = new Vector<Mat>();         
        Mat histogram = new Mat();              
        MatOfInt histSizes = new MatOfInt(10,10,10);        
        MatOfFloat histRanges = new MatOfFloat(0,256,0,256,0,256);  
        MatOfInt channels = new MatOfInt(0,1,2);
        Imgproc.calcHist(sourceImages,channels,new Mat(), histogram, histSizes, histRanges);

the above calcHist method runs and returns the histogram (which is basically a Mat object) which has 3 dimensions and 1000 (10x10x10) total values.

The question is how to access this histogram? Rows and Colums return -1 (as expected for a 3D Mat). Can someone help?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-07-16 10:29:21 -0500

sao gravatar image

I encountered the same problem. I don't think Java API support 3D Mat element visit. My solution is move to C++ and do it. For more information, you can see:

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2014-04-25 14:34:40 -0500

Seen: 575 times

Last updated: Jul 16 '14