Histogram size

asked 2018-03-28 02:33:44 -0600

Hi there! I'm trying to make a histogram of a picture preview from the camera of an android in Portrait mode 1080x1440. The problem is that where i want to show the histogram is ImageView with size 1080x115. The result histogram now is 1080x1440 and if i scale it to fit 1080x115, the lower part of the hist is barely observed. How can i make the proper histogram preview to my desired size?

edit retag flag offensive close merge delete



please show (code), what you're doing here.

berak gravatar imageberak ( 2018-03-28 02:37:17 -0600 )edit

private void drawHistogram(Bitmap bitmap) { try { Mat rgba = new Mat(); Utils.bitmapToMat(bitmap, rgba);

        org.opencv.core.Size rgbaSize = rgba.size();

// org.opencv.core.Size rgbaSize = new org.opencv.core.Size(histogramView.getWidth(), histogramView.getHeight()); int histSize = 256; MatOfInt histogramSize = new MatOfInt(histSize);

        int histogramHeight = (int) rgbaSize.height;
        int binWidth = 5;

        MatOfFloat histogramRange = new MatOfFloat(0f, 256f);

        Scalar[] colorsRgb = new Scalar[]{new Scalar(200, 0, 0, 255), new Scalar(0, 200, 0, 255),
                new Scalar(0, 0, 200, 255)};
        MatOfInt[] channels = new MatOfInt[]{new MatOfInt(0), new MatOfInt(1), new MatOfInt(2)};

        Mat[] histograms = new Mat[]{new Mat(), new Mat(), new Mat()};
        Mat histMatBitmap = new Mat(rgbaSize, rgba.type());

        for (int i = 0; i < channels.length; i++) {
            Imgproc.calcHist(Collections.singletonList(rgba), channels[i], new Mat(), histograms[i], histogramSize, histogramRange);
            Core.normalize(histograms[i], histograms[i], histogramHeight, 0, Core.NORM_INF);
            for (int j = 0; j < histSize; j++) {
                org ...
stevie_p gravatar imagestevie_p ( 2018-03-28 05:46:48 -0600 )edit