summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2011-01-25 00:29:35 +0100
committerGuillaume Seguin <guillaume@segu.in>2011-01-25 00:29:35 +0100
commit2b3cb46b117d061982c61616ffd973b18ad6f41b (patch)
tree73f8d3ecad7d141c74d1c5692ced43d317aaf03b
parentf320ecb1c74e75e9a7f41859161a82cb1b81fe21 (diff)
downloadspacetimemanifolds-2b3cb46b117d061982c61616ffd973b18ad6f41b.tar.gz
spacetimemanifolds-2b3cb46b117d061982c61616ffd973b18ad6f41b.tar.bz2
Add other colorspace handling
-rw-r--r--compute.cc4
-rw-r--r--explore.cc9
-rw-r--r--main.cc9
-rw-r--r--utils.cc32
-rw-r--r--utils.h2
5 files changed, 43 insertions, 13 deletions
diff --git a/compute.cc b/compute.cc
index 671756b..d19f236 100644
--- a/compute.cc
+++ b/compute.cc
@@ -306,10 +306,10 @@ Mat compute_mosaic(vector<Mat> & frames,
direction,
&length);
explore_path(downscaled[i], path);
- Mat mosaic = stitch_path(downscaled[i], path);
+ Mat mosaic = cspace4c_to_rgb(stitch_path(downscaled[i], path));
char buf[200];
sprintf(buf, "temp-%d.png", i);
- imwrite(buf, mosaic * 255);
+ imwrite(buf, mosaic);
paths[i] = path;
mosaics[i] = mosaic;
fprintf(stdout, "Length at scale level %d = %.3le\n", i, length);
diff --git a/explore.cc b/explore.cc
index 5784f91..bc932b4 100644
--- a/explore.cc
+++ b/explore.cc
@@ -7,6 +7,7 @@
#include "explore.h"
#include "stitch.h"
#include "compute.h"
+#include "utils.h"
using namespace std;
using namespace cv;
@@ -50,9 +51,8 @@ void mouse_cb(int event, int x, int y, int flags, void* param)
}
fprintf(stderr, "Strip %d taken from frame %d, column %d, cost %f\n",
x, fs.first, fs.second, cost);
- imshow("Frame view", overlay_line(pd->frames[fs.first],
- fs.second,
- 255, 0, 0));
+ Mat frame = cspace4c_to_rgb(pd->frames[fs.first]);
+ imshow("Frame view", overlay_line(frame, fs.second, 255, 0, 0));
}
if (greenline != -1)
{
@@ -70,7 +70,8 @@ void mouse_cb(int event, int x, int y, int flags, void* param)
void explore_path(vector<Mat> & frames, Path p)
{
- Mat mosaic = stitch_path(frames, p);
+ Mat mosaic_base = stitch_path(frames, p);
+ Mat mosaic = cspace4c_to_rgb(mosaic_base);
PathData pd = {frames, path_to_vpath(p), mosaic,
frames[0].size().width,
frames[0].size().height,
diff --git a/main.cc b/main.cc
index fc79c4b..eab058b 100644
--- a/main.cc
+++ b/main.cc
@@ -6,6 +6,7 @@
#include "compute.h"
#include "stitch.h"
#include "explore.h"
+#include "utils.h"
int main(int argc, char** argv)
{
@@ -35,13 +36,7 @@ int main(int argc, char** argv)
{
Mat frame, frame_double;
cap >> frame;
- frame.convertTo(frame_double, CV_32FC3, 1.0/255.);
- Mat aligned (frame_double.rows, frame_double.cols, CV_32FC4);
- Mat channel4 = Mat::ones(frame_double.rows, frame_double.cols, CV_32F);
- Mat in[] = {frame_double, channel4};
- int from_to[] = { 0,0, 1,1, 2,2, 3,3 };
- cv::mixChannels (in, 2, &aligned, 1, from_to, 4);
- frames[i] = aligned.clone();
+ frames[i] = rgb_to_cspace4c(frame).clone();
}
vector<vector<Mat> > downscaled;
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;
+}
diff --git a/utils.h b/utils.h
index 8b75ca3..272e5bb 100644
--- a/utils.h
+++ b/utils.h
@@ -10,5 +10,7 @@ using namespace std;
using namespace cv;
void display_video(vector<Mat> frames);
+Mat rgb_to_cspace4c(Mat src);
+Mat cspace4c_to_rgb(Mat src);
#endif /* UTILS_H */