# Trying to calculate histogram on Android and find the median. Unsure how to access histogram data from Mat

I'm trying to find the median, which I believe can be done by using the code given here: http://tech.dir.groups.yahoo.com/group/OpenCV/message/23809

What I have so far in java is the histogram calculation working fine (I assume), and at that point, I don't know what to put insude my calcMedianOfHist function. The issue I'm running into is that I don't know how to access the bins of the histogram. The closest I've come to finding out how to do this is looking at this example for C code, but that doesn't apply to the Java. (http://docs.opencv.org/2.4.3rc/doc/tutorials/imgproc/histograms/histogram_calculation/histogram_calculation.html)

The method there says to do hist.at<float>(num), but I cannot do that in java.

I'm also not 100% sure if I should be normalizing the hist like this or not.

Any help is appreciated, thank you.

        ArrayList<Mat> list = new ArrayList<Mat>();

MatOfInt one = new MatOfInt(0);
int median = 0;

hist = new Mat();

MatOfInt histSize = new MatOfInt(25);
MatOfFloat range = new MatOfFloat(0f, 256f);

Imgproc.calcHist(Arrays.asList(mGraySubmat), one, new Mat(), hist, histSize, range);

Core.normalize(hist, hist);

median = calcMedianOfHist(hist, mGraySubmat.cols(), mGraySubmat.rows());

System.out.println("Median is: " + median);

edit retag close merge delete

hist.at<float>(num), is the same as Mat.get I believe. The links in your question are broken otherwise I would try to answer a bit more

( 2014-09-02 09:18:56 -0500 )edit

Sort by ยป oldest newest most voted

Check the dimensions of your hist, it should be one-dimensional.

for( int x=0; x<25; x++ )   // 25 being your histSize
double y = hist.get(x,0)[0];


more

" please update the links you provided." this question was posted in 2012!

( 2018-02-08 07:47:01 -0500 )edit
1

@LBerger Ah, right, didn't see that, sorry.

( 2018-02-08 07:55:45 -0500 )edit

Official site

GitHub

Wiki

Documentation