Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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>();
        list.add(mGraySubmat);

        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);

Trying to calculate histogram on Android and find the median. Unsure how to access histogram datadata 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>();
        list.add(mGraySubmat);

        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);