Ask Your Question

dewmal's profile - activity

2016-04-18 07:37:17 -0600 received badge  Notable Question (source)
2015-05-21 04:55:12 -0600 received badge  Popular Question (source)
2013-04-07 05:55:43 -0600 asked a question Java Histogram
    Mat image = Highgui.imread("lena.png");

    Mat src = new Mat(image.height(), image.width(), CvType.CV_8UC2);

    Imgproc.cvtColor(image, src, Imgproc.COLOR_RGB2GRAY);



    Vector<Mat> bgr_planes = new Vector<>();
    Core.split(src, bgr_planes);

    MatOfInt histSize = new MatOfInt(256);


    final MatOfFloat histRange = new MatOfFloat(0f, 256f);

    boolean accumulate = false;

    Mat b_hist = new  Mat();

    Imgproc.calcHist(bgr_planes, new MatOfInt(0),new Mat(), b_hist, histSize, histRange, accumulate);

    int hist_w = 512;
    int hist_h = 600;
    long bin_w;
    bin_w = Math.round((double) (hist_w / 256));

    Mat histImage = new Mat(hist_h, hist_w, CvType.CV_8UC1);

    Core.normalize(b_hist, b_hist, 3, histImage.rows(), Core.NORM_MINMAX);



    for (int i = 1; i < 256; i++) {         


        Core.line(histImage, new Point(bin_w * (i - 1),hist_h- Math.round(b_hist.get( i-1,0)[0])), 
                new Point(bin_w * (i), hist_h-Math.round(Math.round(b_hist.get(i, 0)[0]))),
                new  Scalar(255, 0, 0), 2, 8, 0);

    }


    ImageViwer.viewImage(histImage);
2013-04-06 08:37:28 -0600 commented question *java* api Histogram calculation

How did you fix it.

2013-04-06 08:36:30 -0600 answered a question *java* api Histogram calculation

How did you fix it.