Java Histogram [closed]

asked 2013-04-07 05:55:43 -0500

dewmal gravatar image
    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);
edit retag flag offensive reopen merge delete

Closed for the following reason not a real question by StevenPuttemans
close date 2013-04-07 13:23:58.321286

Comments

1

and what is your question?

Guanta gravatar imageGuanta ( 2013-04-07 12:38:51 -0500 )edit