Ask Your Question
2

Histogram for ushort

asked 2016-03-14 10:58:46 -0600

strann gravatar image

Hello,

Documentation for OpenCV 3.0 states that calcHist() function takes as input images of depths CV_8U or CV_32F. But from source code it seems the function can be used for 16-bit images in OpenCV 3.1. Is it undocumented yet or I shouldn't use it?

else if( depth == CV_16U )
    calcHist_<ushort>(ptrs, deltas, imsize, ihist, dims, ranges, _uniranges, uniform )
edit retag flag offensive close merge delete

Comments

2

Have you give it a try? If it is working, please make a pull request to update the doc.

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2016-03-14 11:33:46 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2016-03-16 06:34:36 -0600

strann gravatar image

I've checked again if calcHist() is working fine for 16-bit images and opened the issue https://github.com/Itseez/opencv_cont...

Sample image: out1.tiff

#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.tiff", 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;
}
edit flag offensive delete link more

Comments

hi, imho, opencv_contrib is the wrong place for this issue, it should go to https://github.com/Itseez/opencv instead

(good, that you're doing that, nonetheless !)

berak gravatar imageberak ( 2016-03-16 08:07:52 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-03-14 10:58:46 -0600

Seen: 1,364 times

Last updated: Mar 16 '16