Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calcHist() works for ushort but this is not documented #585

Closed
drtimes opened this issue Mar 16, 2016 · 1 comment
Closed

calcHist() works for ushort but this is not documented #585

drtimes opened this issue Mar 16, 2016 · 1 comment
Labels

Comments

@drtimes
Copy link

drtimes commented Mar 16, 2016

Documentation for OpenCV 3.0 states that calcHist() function takes as input arrays of depths CV_8U or CV_32F. But from source code in OpenCV 3.1.0 it seems the function can be used for 16-bit arrays. I tried and it works just fine. It would be great if you documented the feature.

16-bit image sample_image.zip

#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <opencv/cv.h>

using namespace cv;

int main(int argc, char *argv[])
{
        Mat img = imread("out1.tif", IMREAD_UNCHANGED);

        if (img.depth() == CV_16U)
        {
            int histSize = 2048;
            float range[] = {0, histSize};
            const float* histRange = { range };
            bool uniform = true; bool accumulate = false;

            Mat hist;
            calcHist( &img, 1, 0, Mat(), hist, 1, &histSize, &histRange, uniform, accumulate );

            double hmin, hmax;
            minMaxLoc(img, &hmin, &hmax);

            //plot the histogram
            Mat canvas = Mat::zeros(200, histSize, CV_8UC1);
            for (int j = 0, rows = canvas.rows; j < histSize-1; j++)
                line(canvas, Point(j, rows), Point(j, rows - (hist.at<float>(j) * rows/hmax)), Scalar(255,0,0));

            imshow("hist", canvas);
            waitKey(0);
        }
        else
            return 1;

        return 0;
}
@mshabunin
Copy link
Contributor

This issues should be posted to the main repository issue tracker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants