-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Closed
Labels
Description
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;
}