|
@@ -61,6 +61,33 @@ Stacker::add_frame(unsigned char *data, int width, int height)
|
|
|
Mat
|
|
|
Stacker::postprocess_mat(Mat input)
|
|
|
{
|
|
|
+ stopwatch_start();
|
|
|
+ Mat blur;
|
|
|
+ GaussianBlur(input, blur, Size(0, 0), 1.8);
|
|
|
+ std::vector<cv::Mat> rgb_planes(3);
|
|
|
+ cv::split(blur, rgb_planes);
|
|
|
+ double min_r, max_r, min_g, max_g, min_b, max_b;
|
|
|
+ minMaxIdx(rgb_planes[0], &min_b, &max_b);
|
|
|
+ minMaxIdx(rgb_planes[1], &min_g, &max_g);
|
|
|
+ minMaxIdx(rgb_planes[2], &min_r, &max_r);
|
|
|
+ input = input - Scalar(min_b + 5, min_g + 5, min_r + 5);
|
|
|
+ double scale_r, scale_g, scale_b;
|
|
|
+ scale_r = 255 / (max_r - min_r + 5);
|
|
|
+ scale_g = (255 / (max_g - min_g + 5));
|
|
|
+ scale_b = 255 / (max_b - min_b + 5);
|
|
|
+ multiply(input, Scalar(scale_b, scale_g, scale_r), input);
|
|
|
+ stopwatch_mark("levels");
|
|
|
+
|
|
|
+ stopwatch_start();
|
|
|
+ float gamma = 1 / 0.9;
|
|
|
+ Mat table(1, 256, CV_8U);
|
|
|
+ uchar *p = table.ptr();
|
|
|
+ for (int i = 0; i < 256; ++i) {
|
|
|
+ p[i] = (uchar) (pow(i / 255.0, gamma) * 255);
|
|
|
+ }
|
|
|
+ LUT(input, table, input);
|
|
|
+ stopwatch_mark("gamma");
|
|
|
+
|
|
|
stopwatch_start();
|
|
|
Mat sharpened;
|
|
|
GaussianBlur(input, sharpened, Size(0, 0), 1.7);
|
|
@@ -74,10 +101,11 @@ Stacker::postprocess_mat(Mat input)
|
|
|
cv::split(lab, lab_planes);
|
|
|
stopwatch_mark("to Lab");
|
|
|
|
|
|
- /*
|
|
|
+ /* Disabled CLAHE local contrast, it's a bit to overpronounced and doesn't
|
|
|
+ * seem really necessary at this point
|
|
|
stopwatch_start();
|
|
|
cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE();
|
|
|
- clahe->setClipLimit(2);
|
|
|
+ clahe->setClipLimit(1);
|
|
|
clahe->setTilesGridSize(Size(8, 8));
|
|
|
cv::Mat dst;
|
|
|
clahe->apply(lab_planes[0], dst);
|