summaryrefslogtreecommitdiff
path: root/utils.cc
diff options
context:
space:
mode:
Diffstat (limited to 'utils.cc')
-rw-r--r--utils.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/utils.cc b/utils.cc
index 62f5649..0ba9546 100644
--- a/utils.cc
+++ b/utils.cc
@@ -9,3 +9,35 @@ void display_video(vector<Mat> frames)
waitKey(50);
}
}
+
+#define USE_LAB 0
+
+Mat rgb_to_cspace4c(Mat src)
+{
+ Mat src_double, src_cvt = Mat::ones(src.rows, src.cols, CV_8UC3);
+ #if USE_LAB
+ cvtColor(src, src_cvt, CV_RGB2Lab);
+ #else
+ src_cvt = src;
+ #endif
+ src_cvt.convertTo(src_double, CV_32FC3, 1./255);
+ Mat dest (src_double.rows, src_double.cols, CV_32FC4);
+ Mat channel4 = Mat::ones(src_double.rows, src_double.cols, CV_32FC1);
+ Mat in[] = {src_double, channel4};
+ int from_to[] = { 0,0, 1,1, 2,2, 3,3 };
+ cv::mixChannels (in, 2, &dest, 1, from_to, 4);
+ return dest;
+}
+
+Mat cspace4c_to_rgb(Mat src)
+{
+ Mat src_scaled;
+ src.convertTo(src_scaled, CV_8UC4, 255.);
+ Mat dest = Mat::ones(src_scaled.rows, src_scaled.cols, CV_8UC3);
+ int from_to[] = { 0,0, 1,1, 2,2 };
+ cv::mixChannels (&src_scaled, 1, &dest, 1, from_to, 3);
+ #if USE_LAB
+ cvtColor(dest, dest, CV_Lab2RGB);
+ #endif
+ return dest;
+}