From 554299503aa2ae4d7896d59bf35f8eff169f02b9 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Wed, 3 Jan 2007 23:37:46 +0100 Subject: use WGS84 elipsoid --- src/Panorama.H | 2 +- src/Panorama.cxx | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Panorama.H b/src/Panorama.H index 651fe8e..cb7dff7 100644 --- a/src/Panorama.H +++ b/src/Panorama.H @@ -41,7 +41,7 @@ class Panorama { double alpha(double phi, double lam); - double nick(double dist, double height); + double nick(Hill *m); double comp_center_angle(double alph_a, double alph_b, double d1, double d2); diff --git a/src/Panorama.cxx b/src/Panorama.cxx index 38cbd8c..fbbdac3 100644 --- a/src/Panorama.cxx +++ b/src/Panorama.cxx @@ -327,7 +327,7 @@ Panorama::update_angles() { if (m->phi != view_phi || m->lam != view_lam) { m->alph = alpha(m->phi, m->lam); - m->a_nick = nick(m->dist, m->height); + m->a_nick = nick(m); } } @@ -393,7 +393,7 @@ Panorama::update_close_mountains() { if (m->flags & Hill::TRACK_POINT || ((m->phi != view_phi || m->lam != view_lam) && - (m->height / (m->dist * get_earth_radius(m->phi)) + (m->height / (m->dist * EARTH_RADIUS) > height_dist_ratio))) { close_mountains->add(m); @@ -455,29 +455,39 @@ Panorama::alpha(double phi, double lam) { double -Panorama::nick(double dist, double height) { +Panorama::nick(Hill *m) { double a, b, c; double beta; - b = height + get_earth_radius(view_phi); + b = m->height + get_earth_radius(m->phi); c = view_height + get_earth_radius(view_phi); - a = pow(((b * (b - (2.0 * c * cos(dist)))) + (c * c)), (1.0 / 2.0)); + a = pow(((b * (b - (2.0 * c * cos(m->dist)))) + (c * c)), (1.0 / 2.0)); beta = acos((-(b*b) + (a*a) + (c*c))/(2 * a * c)); return beta - pi_d / 2.0; } double -Panorama::get_earth_radius(double latitude) { - return EARTH_RADIUS; +Panorama::get_earth_radius(double phi) { + double a = 6378137.000; + double b = 6356752.315; + double x, y, r; + + x = a*b*pow(pow(a,2)*pow(tan(phi),2)+pow(b,2),-1.0/2.0); + y = a*b*tan(phi)*pow(pow(a,2)*pow(tan(phi),2)+pow(b,2),-1.0/2.0); + + r = sqrt(pow(x, 2) + pow(y, 2)); + + fprintf(stderr, "==> %f %f %f %f\n", phi, x, y, r); + return r; } double Panorama::get_real_distance(Hill *m) { double a, b, c, gam; - a = view_height + get_earth_radius(m->phi); + a = view_height + get_earth_radius(view_phi); b = m->height + get_earth_radius(m->phi); gam = m->dist; -- cgit v1.2.3 From d5f04f65ca793753ed8dc5ad31c99b30dee863f8 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Tue, 16 Jan 2007 15:30:02 +0100 Subject: add comment --- src/Panorama.cxx | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/Panorama.cxx b/src/Panorama.cxx index fbbdac3..27e4ab0 100644 --- a/src/Panorama.cxx +++ b/src/Panorama.cxx @@ -468,6 +468,7 @@ Panorama::nick(Hill *m) { return beta - pi_d / 2.0; } +// return local distance to center of WGS84 ellipsoid double Panorama::get_earth_radius(double phi) { double a = 6378137.000; -- cgit v1.2.3 From 469983dbc81c46c552a460e82c5c2443fef0658a Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Tue, 16 Jan 2007 19:39:28 +0100 Subject: simplify get_earth_radius() --- src/Panorama.cxx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Panorama.cxx b/src/Panorama.cxx index b1d42d3..cfdfb22 100644 --- a/src/Panorama.cxx +++ b/src/Panorama.cxx @@ -35,6 +35,9 @@ Panorama::Panorama() { view_height = 0.0; proj = NULL; set_projection(ProjectionLSQ::RECTILINEAR); + + +fprintf(stderr, "=> %f, %f\n", get_earth_radius(0.0), get_earth_radius(pi_d/2.0)); } Panorama::~Panorama() { @@ -474,14 +477,11 @@ double Panorama::get_earth_radius(double phi) { double a = 6378137.000; double b = 6356752.315; - double x, y, r; - - x = a*b*pow(pow(a,2)*pow(tan(phi),2)+pow(b,2),-1.0/2.0); - y = a*b*tan(phi)*pow(pow(a,2)*pow(tan(phi),2)+pow(b,2),-1.0/2.0); + double r; + double ata = tan(phi); - r = sqrt(pow(x, 2) + pow(y, 2)); + r = a*pow(pow(ata,2)+1,1.0/2.0)*fabs(b)*pow(pow(b,2)+pow(a,2)*pow(ata,2),-1.0/2.0); - fprintf(stderr, "==> %f %f %f %f\n", phi, x, y, r); return r; } -- cgit v1.2.3 From c972f4a2023f94cd837c001e34715ab924745eb6 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Tue, 16 Jan 2007 19:40:14 +0100 Subject: remove unused Panorama::get_value() method --- src/Panorama.H | 2 -- src/Panorama.cxx | 28 ---------------------------- 2 files changed, 30 deletions(-) (limited to 'src') diff --git a/src/Panorama.H b/src/Panorama.H index cb7dff7..3d5b260 100644 --- a/src/Panorama.H +++ b/src/Panorama.H @@ -51,8 +51,6 @@ class Panorama { int optimize(Hill *m1, Hill *m2); - double get_value(Hills *p); - int is_visible(double a_alph); double pi_d, deg2rad; diff --git a/src/Panorama.cxx b/src/Panorama.cxx index cfdfb22..bcf42b1 100644 --- a/src/Panorama.cxx +++ b/src/Panorama.cxx @@ -132,34 +132,6 @@ Panorama::get_visible_mountains() { return visible_mountains; } -double -Panorama::get_value(Hills *p) { - int i, j; - double v = 0.0, d_min, d; - - if (isnan(parms.scale) || isnan(parms.a_center) || isnan(parms.a_tilt) || isnan(parms.a_nick) || - parms.scale < 500.0 || parms.scale > 100000.0 || - parms.a_nick > pi_d/4.0 || parms.a_nick < - pi_d/4.0 || - parms.a_tilt > pi_d/16.0 || parms.a_tilt < - pi_d/16.0) { - return 10000000.0; - } - - - for (i=0; iget_num(); i++) { - d_min = 1000.0; - for (j=0; jget_num(); j++) { - d = pow(p->get(i)->x - visible_mountains->get(j)->x, 2.0) + - pow(p->get(i)->y - visible_mountains->get(j)->y, 2.0); - if (d < d_min) { - d_min = d; - } - } - v = v + d_min; - } - - return v; -} - int Panorama::comp_params(Hills *h) { int ret; -- cgit v1.2.3 From 0a3622f770ab24251bfb0e9f6d7927429323d07f Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Wed, 17 Jan 2007 10:01:34 +0100 Subject: whitespace --- src/Panorama.cxx | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/Panorama.cxx b/src/Panorama.cxx index bcf42b1..839d70c 100644 --- a/src/Panorama.cxx +++ b/src/Panorama.cxx @@ -483,8 +483,6 @@ Panorama::is_visible(double a_alph) { int Panorama::get_coordinates(double a_alph, double a_nick, double *x, double *y) { - - if (is_visible(a_alph)) { proj->get_coordinates(a_alph, a_nick, &parms, x, y); return 0; -- cgit v1.2.3 From 4671827b2408eccd6e457660b5817b5f9ae81569 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Tue, 6 Mar 2007 19:19:46 +0100 Subject: implement initial main point adjustment (x-axis only) --- src/GipfelWidget.cxx | 2 ++ src/ProjectionCylindrical.H | 2 +- src/ProjectionLSQ.H | 4 +++- src/ProjectionLSQ.cxx | 27 +++++++++++++++++++-------- src/ProjectionRectilinear.H | 4 +++- src/ProjectionRectilinear.cxx | 1 - src/ViewParams.H | 1 + src/lsq_cylindrical.mac | 2 +- src/lsq_rectilinear.mac | 6 ++++-- 9 files changed, 34 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index a8efa97..53fc25b 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -802,6 +802,7 @@ GipfelWidget::load_distortion_params(const char *prof_name) { Fl_Preferences prof(dist_prefs, prof_name); ret += prof.get("k0", pan->parms.k0, pan->parms.k0); ret += prof.get("k1", pan->parms.k1, pan->parms.k1); + ret += prof.get("x0", pan->parms.k1, pan->parms.x0); return !ret; } @@ -812,6 +813,7 @@ GipfelWidget::save_distortion_params(const char *prof_name) { Fl_Preferences prof(dist_prefs, prof_name); prof.set("k0", pan->parms.k0); prof.set("k1", pan->parms.k1); + prof.set("x0", pan->parms.x0); return 0; } diff --git a/src/ProjectionCylindrical.H b/src/ProjectionCylindrical.H index 432d868..2cb9687 100644 --- a/src/ProjectionCylindrical.H +++ b/src/ProjectionCylindrical.H @@ -14,7 +14,7 @@ class ProjectionCylindrical : public ProjectionLSQ { virtual double get_view_angle() {return 6.2831853;}; /* 360 deg */ -#define ARGS double c_view, double c_nick, double c_tilt, double scale, double k0, double k1, double m_view, double m_nick +#define ARGS double c_view, double c_nick, double c_tilt, double scale, double k0, double k1, double x0, double m_view, double m_nick virtual double mac_x(ARGS); virtual double mac_y(ARGS); virtual double mac_x_dc_view(ARGS); diff --git a/src/ProjectionLSQ.H b/src/ProjectionLSQ.H index 54ab641..273585f 100644 --- a/src/ProjectionLSQ.H +++ b/src/ProjectionLSQ.H @@ -34,7 +34,7 @@ class ProjectionLSQ { virtual double get_view_angle(); -#define ARGS double c_view, double c_nick, double c_tilt, double scale, double k0, double k1, double m_view, double m_nick +#define ARGS double c_view, double c_nick, double c_tilt, double scale, double k0, double k1, double x0, double m_view, double m_nick virtual double mac_x(ARGS); virtual double mac_y(ARGS); virtual double mac_x_dc_view(ARGS); @@ -43,12 +43,14 @@ class ProjectionLSQ { virtual double mac_x_dscale(ARGS); virtual double mac_x_dk0(ARGS); virtual double mac_x_dk1(ARGS); + virtual double mac_x_dx0(ARGS); virtual double mac_y_dc_view(ARGS); virtual double mac_y_dc_nick(ARGS); virtual double mac_y_dc_tilt(ARGS); virtual double mac_y_dscale(ARGS); virtual double mac_y_dk0(ARGS); virtual double mac_y_dk1(ARGS); + virtual double mac_y_dx0(ARGS); #undef ARGS }; diff --git a/src/ProjectionLSQ.cxx b/src/ProjectionLSQ.cxx index 077641b..da5b3da 100644 --- a/src/ProjectionLSQ.cxx +++ b/src/ProjectionLSQ.cxx @@ -45,6 +45,7 @@ ProjectionLSQ::comp_params(const Hills *h, ViewParams *parms) { distortion_correct = 1; parms->k0 = 0.0; parms->k1 = 0.0; + parms->x0 = 0.0; } m1 = h->get(0); @@ -68,7 +69,7 @@ ProjectionLSQ::comp_params(const Hills *h, ViewParams *parms) { if (distortion_correct) { lsq(h, parms, 1); } - +fprintf(stderr, "===> x0 %f\n", parms->x0); return 0; } @@ -79,12 +80,12 @@ struct data { const ViewParams *old_params; }; -#define CALL(A) dat->p->A(c_view, c_nick, c_tilt, scale, k0, k1, m->alph, m->a_nick) +#define CALL(A) dat->p->A(c_view, c_nick, c_tilt, scale, k0, k1, x0, m->alph, m->a_nick) static int lsq_f (const gsl_vector * x, void *data, gsl_vector * f) { struct data *dat = (struct data *) data; - double c_view, c_nick, c_tilt, scale, k0, k1; + double c_view, c_nick, c_tilt, scale, k0, k1, x0; c_view = gsl_vector_get (x, 0); c_nick = gsl_vector_get (x, 1); @@ -93,9 +94,11 @@ lsq_f (const gsl_vector * x, void *data, gsl_vector * f) { if (dat->distortion_correct) { k0 = gsl_vector_get (x, 4); k1 = gsl_vector_get (x, 5); + x0 = gsl_vector_get (x, 6); } else { k0 = dat->old_params->k0; k1 = dat->old_params->k1; + x0 = dat->old_params->x0; } for (int i=0; ih->get_num(); i++) { @@ -115,7 +118,7 @@ lsq_f (const gsl_vector * x, void *data, gsl_vector * f) { static int lsq_df (const gsl_vector * x, void *data, gsl_matrix * J) { struct data *dat = (struct data *) data; - double c_view, c_nick, c_tilt, scale, k0, k1; + double c_view, c_nick, c_tilt, scale, k0, k1, x0; c_view = gsl_vector_get (x, 0); c_nick = gsl_vector_get (x, 1); @@ -124,9 +127,11 @@ lsq_df (const gsl_vector * x, void *data, gsl_matrix * J) { if (dat->distortion_correct) { k0 = gsl_vector_get (x, 4); k1 = gsl_vector_get (x, 5); + x0 = gsl_vector_get (x, 6); } else { k0 = dat->old_params->k0; k1 = dat->old_params->k1; + x0 = dat->old_params->x0; } for (int i=0; ih->get_num(); i++) { @@ -139,6 +144,7 @@ lsq_df (const gsl_vector * x, void *data, gsl_matrix * J) { if (dat->distortion_correct) { gsl_matrix_set (J, 2*i, 4, CALL(mac_x_dk0)); gsl_matrix_set (J, 2*i, 5, CALL(mac_x_dk1)); + gsl_matrix_set (J, 2*i, 6, CALL(mac_x_dx0)); } gsl_matrix_set (J, 2*i+1, 0, CALL(mac_y_dc_view)); @@ -148,6 +154,7 @@ lsq_df (const gsl_vector * x, void *data, gsl_matrix * J) { if (dat->distortion_correct) { gsl_matrix_set (J, 2*i+1, 4, CALL(mac_y_dk0)); gsl_matrix_set (J, 2*i+1, 5, CALL(mac_y_dk1)); + gsl_matrix_set (J, 2*i+1, 6, CALL(mac_y_dx0)); } } @@ -173,7 +180,7 @@ ProjectionLSQ::lsq(const Hills *h, ViewParams *parms, double x_init[8]; gsl_vector_view x; int status; - int num_params = distortion_correct?6:4; + int num_params = distortion_correct?7:4; dat.p = this; dat.distortion_correct = distortion_correct; @@ -186,6 +193,7 @@ ProjectionLSQ::lsq(const Hills *h, ViewParams *parms, x_init[3] = parms->scale; x_init[4] = parms->k0; x_init[5] = parms->k1; + x_init[6] = parms->x0; x = gsl_vector_view_array (x_init, num_params); @@ -216,6 +224,7 @@ ProjectionLSQ::lsq(const Hills *h, ViewParams *parms, if (distortion_correct) { parms->k0 = gsl_vector_get(s->x, 4); parms->k1 = gsl_vector_get(s->x, 5); + parms->x0 = gsl_vector_get(s->x, 6); } gsl_multifit_fdfsolver_free (s); @@ -228,9 +237,9 @@ ProjectionLSQ::get_coordinates(double alph, double a_nick, const ViewParams *parms, double *x, double *y) { *x = mac_x(parms->a_center, parms->a_nick, parms->a_tilt, parms->scale, - parms->k0, parms->k1, alph, a_nick); + parms->k0, parms->k1, parms->x0, alph, a_nick); *y = mac_y(parms->a_center, parms->a_nick, parms->a_tilt, parms->scale, - parms->k0, parms->k1, alph, a_nick); + parms->k0, parms->k1, parms->x0, alph, a_nick); } double @@ -238,7 +247,7 @@ ProjectionLSQ::comp_scale(double a1, double a2, double d1, double d2) { return (fabs(d1 - d2) / fabs(a1 - a2)); } -#define ARGS double c_view, double c_nick, double c_tilt, double scale, double k0, double k1, double m_view, double m_nick +#define ARGS double c_view, double c_nick, double c_tilt, double scale, double k0, double k1, double x0, double m_view, double m_nick double ProjectionLSQ::mac_x(ARGS) {return NAN;} double ProjectionLSQ::mac_y(ARGS) {return NAN;} @@ -248,9 +257,11 @@ double ProjectionLSQ::mac_x_dc_tilt(ARGS) {return NAN;} double ProjectionLSQ::mac_x_dscale(ARGS) {return NAN;} double ProjectionLSQ::mac_x_dk0(ARGS) {return NAN;} double ProjectionLSQ::mac_x_dk1(ARGS) {return NAN;} +double ProjectionLSQ::mac_x_dx0(ARGS) {return NAN;} double ProjectionLSQ::mac_y_dc_view(ARGS) {return NAN;} double ProjectionLSQ::mac_y_dc_nick(ARGS) {return NAN;} double ProjectionLSQ::mac_y_dc_tilt(ARGS) {return NAN;} double ProjectionLSQ::mac_y_dscale(ARGS) {return NAN;} double ProjectionLSQ::mac_y_dk0(ARGS) {return NAN;} double ProjectionLSQ::mac_y_dk1(ARGS) {return NAN;} +double ProjectionLSQ::mac_y_dx0(ARGS) {return NAN;} diff --git a/src/ProjectionRectilinear.H b/src/ProjectionRectilinear.H index e68851e..f3f16bb 100644 --- a/src/ProjectionRectilinear.H +++ b/src/ProjectionRectilinear.H @@ -14,7 +14,7 @@ class ProjectionRectilinear : public ProjectionLSQ { virtual double get_view_angle() {return 1.0471976;}; /* 60 deg */ -#define ARGS double c_view, double c_nick, double c_tilt, double scale, double k0, double k1, double m_view, double m_nick +#define ARGS double c_view, double c_nick, double c_tilt, double scale, double k0, double k1, double x0, double m_view, double m_nick virtual double mac_x(ARGS); virtual double mac_y(ARGS); virtual double mac_x_dc_view(ARGS); @@ -23,12 +23,14 @@ class ProjectionRectilinear : public ProjectionLSQ { virtual double mac_x_dscale(ARGS); virtual double mac_x_dk0(ARGS); virtual double mac_x_dk1(ARGS); + virtual double mac_x_dx0(ARGS); virtual double mac_y_dc_view(ARGS); virtual double mac_y_dc_nick(ARGS); virtual double mac_y_dc_tilt(ARGS); virtual double mac_y_dscale(ARGS); virtual double mac_y_dk0(ARGS); virtual double mac_y_dk1(ARGS); + virtual double mac_y_dx0(ARGS); #undef ARGS }; diff --git a/src/ProjectionRectilinear.cxx b/src/ProjectionRectilinear.cxx index fd64b7c..a6ec6d1 100644 --- a/src/ProjectionRectilinear.cxx +++ b/src/ProjectionRectilinear.cxx @@ -10,4 +10,3 @@ #include "ProjectionRectilinear.H" #include "ProjectionRectilinear_funcs.cxx" - diff --git a/src/ViewParams.H b/src/ViewParams.H index 2048fe2..44462c0 100644 --- a/src/ViewParams.H +++ b/src/ViewParams.H @@ -15,6 +15,7 @@ class ViewParams { double a_tilt; double k0; double k1; + double x0; }; #endif diff --git a/src/lsq_cylindrical.mac b/src/lsq_cylindrical.mac index 0bf9499..a88a2e2 100644 --- a/src/lsq_cylindrical.mac +++ b/src/lsq_cylindrical.mac @@ -18,7 +18,7 @@ load("expr2c.mac")$ x_expand : trigexpand(x_scale)$ y_expand : trigexpand(y_scale)$ -args: "double c_view, double c_nick, double c_tilt, double scale, double k0, double k1, double m_view, double m_nick"$ +args: "double c_view, double c_nick, double c_tilt, double scale, double k0, double k1, double x0, double m_view, double m_nick"$ expr2c("ProjectionCylindrical::mac_x", args, x_expand)$ expr2c("ProjectionCylindrical::mac_y", args, y_expand)$ diff --git a/src/lsq_rectilinear.mac b/src/lsq_rectilinear.mac index 69980c0..5bd7ac9 100644 --- a/src/lsq_rectilinear.mac +++ b/src/lsq_rectilinear.mac @@ -4,7 +4,7 @@ x : tan(m_view - c_view)$ y : tan(c_nick - m_nick)$ -x_rot : y * sin(c_tilt) + x * cos(c_tilt)$ +x_rot : y * sin(c_tilt) + x * cos(c_tilt)+x0$ y_rot : y * cos(c_tilt) - x * sin(c_tilt)$ d : x_rot ^ 2 + y_rot ^ 2$ dist_fact : d ^ 2 * k1 + d * k0$ @@ -20,7 +20,7 @@ load("expr2c.mac")$ x_expand : trigexpand(x_dist)$ y_expand : trigexpand(y_dist)$ -args: "double c_view, double c_nick, double c_tilt, double scale, double k0, double k1, double m_view, double m_nick"$ +args: "double c_view, double c_nick, double c_tilt, double scale, double k0, double k1, double x0, double m_view, double m_nick"$ expr2c("ProjectionRectilinear::mac_x", args, x_expand)$ expr2c("ProjectionRectilinear::mac_y", args, y_expand)$ @@ -31,9 +31,11 @@ expr2c("ProjectionRectilinear::mac_x_dc_tilt", args, diff(x_expand, c_tilt))$ expr2c("ProjectionRectilinear::mac_x_dscale", args, diff(x_expand, scale))$ expr2c("ProjectionRectilinear::mac_x_dk0", args, diff(x_expand, k0))$ expr2c("ProjectionRectilinear::mac_x_dk1", args, diff(x_expand, k1))$ +expr2c("ProjectionRectilinear::mac_x_dx0", args, diff(x_expand, x0))$ expr2c("ProjectionRectilinear::mac_y_dc_view", args, diff(y_expand, c_view))$ expr2c("ProjectionRectilinear::mac_y_dc_nick", args, diff(y_expand, c_nick))$ expr2c("ProjectionRectilinear::mac_y_dc_tilt", args, diff(y_expand, c_tilt))$ expr2c("ProjectionRectilinear::mac_y_dscale", args, diff(y_expand, scale))$ expr2c("ProjectionRectilinear::mac_y_dk0", args, diff(y_expand, k0))$ expr2c("ProjectionRectilinear::mac_y_dk1", args, diff(y_expand, k1))$ +expr2c("ProjectionRectilinear::mac_y_dx0", args, diff(y_expand, x0))$ -- cgit v1.2.3 From c00e603b4bfe336683c713cca80cbba47e639678 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Wed, 7 Mar 2007 22:25:03 +0100 Subject: add GUI stuff for x0 --- src/GipfelWidget.H | 4 ++-- src/GipfelWidget.cxx | 14 +++++++------- src/ImageMetaData.H | 5 +++-- src/ImageMetaData.cxx | 14 +++++++++----- src/Panorama.H | 4 ++-- src/Panorama.cxx | 8 +++++--- src/gipfel.cxx | 51 ++++++++++++++++++++++++++++++++++----------------- 7 files changed, 62 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index 3671a87..a17009a 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -115,9 +115,9 @@ class GipfelWidget : public Fl_Widget { void set_projection(ProjectionLSQ::Projection_t p); - void get_distortion_params(double *k0, double *k1); + void get_distortion_params(double *k0, double *k1i, double *x0); - void set_distortion_params(double k0, double k1); + void set_distortion_params(double k0, double k1, double x0); Hills *get_mountains(); diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index 53fc25b..eb40590 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -99,7 +99,7 @@ GipfelWidget::load_image(char *file) { // 1. gipfel data in JPEG comment // 2. matching distortion profile // 3. set the to 0.0, 0.0 - md->get_distortion_params(&pan->parms.k0, &pan->parms.k1); + md->get_distortion_params(&pan->parms.k0, &pan->parms.k1, &pan->parms.x0); if (isnan(pan->parms.k0)) { char buf[1024]; get_distortion_profile_name(buf, sizeof(buf)); @@ -138,7 +138,7 @@ GipfelWidget::save_image(char *file) { md->set_tilt(get_tilt_angle()); md->set_focal_length_35mm(get_focal_length_35mm()); md->set_projection_type((int) get_projection()); - md->set_distortion_params(pan->parms.k0, pan->parms.k1); + md->set_distortion_params(pan->parms.k0, pan->parms.k1, pan->parms.x0); ret = md->save_image(img_file, file); delete md; @@ -473,13 +473,13 @@ GipfelWidget::set_projection(ProjectionLSQ::Projection_t p) { } void -GipfelWidget::get_distortion_params(double *k0, double *k1) { - pan->get_distortion_params(k0, k1); +GipfelWidget::get_distortion_params(double *k0, double *k1, double *x0) { + pan->get_distortion_params(k0, k1, x0); } void -GipfelWidget::set_distortion_params(double k0, double k1) { - pan->set_distortion_params(k0, k1); +GipfelWidget::set_distortion_params(double k0, double k1, double x0) { + pan->set_distortion_params(k0, k1, x0); redraw(); } @@ -802,7 +802,7 @@ GipfelWidget::load_distortion_params(const char *prof_name) { Fl_Preferences prof(dist_prefs, prof_name); ret += prof.get("k0", pan->parms.k0, pan->parms.k0); ret += prof.get("k1", pan->parms.k1, pan->parms.k1); - ret += prof.get("x0", pan->parms.k1, pan->parms.x0); + ret += prof.get("x0", pan->parms.x0, pan->parms.x0); return !ret; } diff --git a/src/ImageMetaData.H b/src/ImageMetaData.H index 27cbbd8..b7a5959 100644 --- a/src/ImageMetaData.H +++ b/src/ImageMetaData.H @@ -19,6 +19,7 @@ class ImageMetaData { double tilt; double k0; double k1; + double x0; double focal_length; double focal_length_35mm; double scale; @@ -47,7 +48,7 @@ class ImageMetaData { double get_focal_length(); double get_focal_length_35mm(); int get_projection_type(); - void get_distortion_params(double *_k0, double *_k1); + void get_distortion_params(double *_k0, double *_k1, double *_x0); void set_longitude(double v); void set_latitude(double v); @@ -57,6 +58,6 @@ class ImageMetaData { void set_tilt(double v); void set_focal_length_35mm(double v); void set_projection_type(int v); - void set_distortion_params(double _k0, double _k1); + void set_distortion_params(double _k0, double _k1, double _x0); }; #endif diff --git a/src/ImageMetaData.cxx b/src/ImageMetaData.cxx index e9a1241..368a9ba 100644 --- a/src/ImageMetaData.cxx +++ b/src/ImageMetaData.cxx @@ -38,6 +38,7 @@ ImageMetaData::clear() { tilt = NAN; k0 = NAN; k1 = NAN; + x0 = NAN; focal_length = NAN; focal_length_35mm = NAN; scale = NAN; @@ -159,7 +160,7 @@ ImageMetaData::load_image_exif(char *name) { #define GIPFEL_FORMAT_1 "gipfel: longitude %lf, latitude %lf, height %lf, direction %lf, nick %lf, tilt %lf, scale %lf, projection type %d" -#define GIPFEL_FORMAT_2 "gipfel: longitude %lf, latitude %lf, height %lf, direction %lf, nick %lf, tilt %lf, focal_length_35mm %lf, projection type %d, k0 %lf, k1 %lf" +#define GIPFEL_FORMAT_2 "gipfel: longitude %lf, latitude %lf, height %lf, direction %lf, nick %lf, tilt %lf, focal_length_35mm %lf, projection type %d, k0 %lf, k1 %lf, x0 %lf" int ImageMetaData::load_image_jpgcom(char *name) { @@ -168,7 +169,7 @@ ImageMetaData::load_image_jpgcom(char *name) { pid_t pid; int status; char buf[1024]; - double lo, la, he, dir, ni, ti, fr, _k0, _k1; + double lo, la, he, dir, ni, ti, fr, _k0, _k1, _x0 = 0.0; int pt = 0; int n, ret = 1; @@ -181,7 +182,7 @@ ImageMetaData::load_image_jpgcom(char *name) { if (p) { while (fgets(buf, sizeof(buf), p) != NULL) { if ((n = sscanf(buf, GIPFEL_FORMAT_2, - &lo, &la, &he, &dir, &ni, &ti, &fr, &pt, &_k0, &_k1)) >= 8) { + &lo, &la, &he, &dir, &ni, &ti, &fr, &pt, &_k0, &_k1, &_x0)) >= 8) { longitude = lo; latitude = la; @@ -195,6 +196,7 @@ ImageMetaData::load_image_jpgcom(char *name) { if (n >= 10) { k0 = _k0; k1 = _k1; + x0 = _x0; } ret = 0; @@ -395,13 +397,15 @@ ImageMetaData::set_projection_type(int v) { } void -ImageMetaData::get_distortion_params(double *_k0, double *_k1) { +ImageMetaData::get_distortion_params(double *_k0, double *_k1, double *_x0) { *_k0 = k0; *_k1 = k1; + *_x0 = x0; } void -ImageMetaData::set_distortion_params(double _k0, double _k1) { +ImageMetaData::set_distortion_params(double _k0, double _k1, double _x0) { k0 = _k0; k1 = _k1; + x0 = _x0; } diff --git a/src/Panorama.H b/src/Panorama.H index 3d5b260..d5ebb37 100644 --- a/src/Panorama.H +++ b/src/Panorama.H @@ -124,9 +124,9 @@ class Panorama { void set_projection(ProjectionLSQ::Projection_t p); - void get_distortion_params(double *k0, double *k1); + void get_distortion_params(double *k0, double *k1, double *x0); - void set_distortion_params(double k0, double k1); + void set_distortion_params(double k0, double k1, double x0); int get_coordinates(double a_alph, double a_nick, double *x, double *y); }; diff --git a/src/Panorama.cxx b/src/Panorama.cxx index 839d70c..7b1529b 100644 --- a/src/Panorama.cxx +++ b/src/Panorama.cxx @@ -166,15 +166,17 @@ Panorama::set_scale(double s) { } void -Panorama::get_distortion_params(double *k0, double *k1) { +Panorama::get_distortion_params(double *k0, double *k1, double *x0) { *k0 = parms.k0; *k1 = parms.k1; + *x0 = parms.x0; } void -Panorama::set_distortion_params(double k0, double k1) { +Panorama::set_distortion_params(double k0, double k1, double x0) { parms.k0 = k0; parms.k1 = k1; + parms.x0 = x0; update_coordinates(); } @@ -451,7 +453,7 @@ Panorama::get_earth_radius(double phi) { double b = 6356752.315; double r; double ata = tan(phi); - +return EARTH_RADIUS; r = a*pow(pow(ata,2)+1,1.0/2.0)*fabs(b)*pow(pow(b,2)+pow(a,2)*pow(ata,2),-1.0/2.0); return r; diff --git a/src/gipfel.cxx b/src/gipfel.cxx index bb58586..5807ae5 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -46,7 +46,7 @@ Fl_Window *control_win, *view_win; Fl_Dial *s_center = NULL; Fl_Slider *s_nick, *s_focal_length, *s_tilt, *s_height_dist, *s_track_width; Fl_Value_Input *i_view_lat, *i_view_long, *i_view_height; -Fl_Value_Input *i_distortion_k0, *i_distortion_k1; +Fl_Value_Input *i_distortion_k0, *i_distortion_k1, *i_distortion_x0; Fl_Box *b_viewpoint; Fl_Menu_Bar *mb; @@ -58,7 +58,7 @@ static int stitch(GipfelWidget::sample_mode_t m ,int stitch_w, int stitch_h, double from, double to, int type, const char *path, int argc, char **argv); void set_values() { - double k0 = 0.0, k1 = 0.0; + double k0 = 0.0, k1 = 0.0, x0 = 0.0; s_center->value(gipf->get_center_angle()); s_nick->value(gipf->get_nick_angle()); @@ -77,9 +77,10 @@ void set_values() { mb->mode(8, FL_MENU_RADIO); } - gipf->get_distortion_params(&k0, &k1); + gipf->get_distortion_params(&k0, &k1, &x0); i_distortion_k0->value(k0); i_distortion_k1->value(k1); + i_distortion_x0->value(x0); } void quit_cb() { @@ -174,12 +175,12 @@ void comp_cb(Fl_Widget *, void *) { void save_distortion_cb(Fl_Widget *, void *) { char buf[1024]; const char * prof_name; - double k0, k1; + double k0, k1, x0; - gipf->get_distortion_params(&k0, &k1); + gipf->get_distortion_params(&k0, &k1, &x0); gipf->get_distortion_profile_name(buf, sizeof(buf)); - prof_name = fl_input("Save Distortion Profile (k0=%f, k1=%f)", - buf, k0, k1); + prof_name = fl_input("Save Distortion Profile (k0=%f, k1=%f, x0=%f)", + buf, k0, k1, x0); if (prof_name == NULL) { return; @@ -208,8 +209,10 @@ void load_distortion_cb(Fl_Widget *, void *) { } void distortion_cb(Fl_Value_Input*, void*) { - gipf->set_distortion_params(i_distortion_k0->value(), - i_distortion_k1->value()); + gipf->set_distortion_params( + i_distortion_k0->value(), + i_distortion_k1->value(), + i_distortion_x0->value()); } void about_cb() { @@ -355,23 +358,31 @@ create_control_window() { i_view_height->when(FL_WHEN_ENTER_KEY); i_view_height->callback((Fl_Callback*)view_height_cb); - i_distortion_k0 = new Fl_Value_Input(235, 220, 80, 20, "Distortion (k0)"); + i_distortion_k0 = new Fl_Value_Input(250, 200, 80, 20, "k0"); i_distortion_k0->labelsize(10); i_distortion_k0->textsize(10); - i_distortion_k0->align(FL_ALIGN_TOP); + i_distortion_k0->align(FL_ALIGN_LEFT); i_distortion_k0->when(FL_WHEN_ENTER_KEY); i_distortion_k0->callback((Fl_Callback*)distortion_cb); - i_distortion_k1 = new Fl_Value_Input(315, 220, 80, 20, "Distortion (k1)"); + i_distortion_k1 = new Fl_Value_Input(250, 225, 80, 20, "k1"); i_distortion_k1->labelsize(10); i_distortion_k1->textsize(10); - i_distortion_k1->align(FL_ALIGN_TOP); + i_distortion_k1->align(FL_ALIGN_LEFT); i_distortion_k1->when(FL_WHEN_ENTER_KEY); i_distortion_k1->callback((Fl_Callback*)distortion_cb); + i_distortion_x0 = new Fl_Value_Input(250, 250, 80, 20, "x0"); + i_distortion_x0->labelsize(10); + i_distortion_x0->textsize(10); + i_distortion_x0->align(FL_ALIGN_LEFT); + i_distortion_x0->when(FL_WHEN_ENTER_KEY); + i_distortion_x0->callback((Fl_Callback*)distortion_cb); + + // Buttons - Fl_Button *b = new Fl_Button(260, 260, 100, 20, "comp"); + Fl_Button *b = new Fl_Button(280, 280, 100, 20, "comp"); b->color(FL_RED); b->tooltip("compute view parameter from given mountains"); b->callback(comp_cb); @@ -388,7 +399,7 @@ int main(int argc, char** argv) { int jpeg_flag = 0, tiff_flag = 0, distortion_flag = 0; int bilinear_flag = 0; double stitch_from = 0.0, stitch_to = 380.0; - double dist_k0 = 0.0, dist_k1 = 0.0; + double dist_k0 = 0.0, dist_k1 = 0.0, dist_x0 = 0.0; char *outpath = "/tmp"; Fl_Scroll *scroll; @@ -419,11 +430,17 @@ int main(int argc, char** argv) { } break; case 'u': + char *c; distortion_flag++; if (optarg && strcmp(optarg, ":")) { dist_k0 = atof(optarg); - if (strchr(optarg, ',')) { + c = strchr(optarg, ','); + if (c) { dist_k1 = atof(strchr(optarg, ',') + 1); + c = strchr(c + 1, ','); + if (c) { + dist_x0 = atof(strchr(optarg, ',') + 1); + } } } break; @@ -501,7 +518,7 @@ int main(int argc, char** argv) { } if (distortion_flag) { - gipf->set_distortion_params(dist_k0, dist_k1); + gipf->set_distortion_params(dist_k0, dist_k1, dist_x0); } view_win->size(gipf->w(), gipf->h()); -- cgit v1.2.3 From 508490f69a9f5e0023deda70b04b785aa041b8e3 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 12 Mar 2007 17:26:10 +0100 Subject: fix saving of x0 --- src/ImageMetaData.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ImageMetaData.cxx b/src/ImageMetaData.cxx index 368a9ba..5f619d2 100644 --- a/src/ImageMetaData.cxx +++ b/src/ImageMetaData.cxx @@ -269,7 +269,7 @@ ImageMetaData::save_image_jpgcom(char *in_img, char *out_img) { tilt, focal_length_35mm, projection_type, - k0, k1); + k0, k1, x0); // try to save gipfel data in JPEG comment section args[0] = "wrjpgcom"; -- cgit v1.2.3 From 3d907fd76ca23d69bcd7d25367c9c94063490d38 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Tue, 13 Mar 2007 18:29:45 +0100 Subject: add devignetting infrastructure --- src/GipfelWidget.H | 2 ++ src/GipfelWidget.cxx | 31 +++++++++++++++-- src/Stitch.H | 3 ++ src/Stitch.cxx | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++-- src/gipfel.cxx | 20 ++++++++--- 5 files changed, 141 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index a17009a..f5254e7 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -126,6 +126,8 @@ class GipfelWidget : public Fl_Widget { int get_pixel(GipfelWidget::sample_mode_t, double a_alph, double a_nick, uchar *r, uchar *g, uchar *b); + double get_angle_off(double view, double nick); + int get_distortion_profile_name(char *buf, int buflen); int save_distortion_params(const char *prof_name); diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index eb40590..e88c0cb 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -31,6 +31,7 @@ #define MAX(A,B) ((A)>(B)?(A):(B)) +#define MIN(A,B) ((A)<(B)?(A):(B)) static double pi_d, deg2rad; @@ -671,6 +672,8 @@ int GipfelWidget::get_pixel(GipfelWidget::sample_mode_t m, double a_alph, double a_nick, uchar *r, uchar *g, uchar *b) { double px, py; + uchar r_tmp, g_tmp, b_tmp; + int ret; if (img == NULL) { return 1; @@ -681,12 +684,36 @@ GipfelWidget::get_pixel(GipfelWidget::sample_mode_t m, } if (m == GipfelWidget::BILINEAR) { - return get_pixel_bilinear(img, px + ((double) img->w()) / 2.0, + ret = get_pixel_bilinear(img, px + ((double) img->w()) / 2.0, py + ((double) img->h()) / 2.0, r, g, b); } else { - return get_pixel_nearest(img, px + ((double) img->w()) / 2.0, + ret = get_pixel_nearest(img, px + ((double) img->w()) / 2.0, py + ((double) img->h()) / 2.0, r, g, b); } + +#if 0 + if (ret == 0) { +fprintf(stderr, "===> %d\n", ret); + double angle = atan(pow(pow(tan(a_alph - pan->parms.a_center), 2.0) + + pow(tan(a_nick - pan->parms.a_nick), 2.0), 0.5)); + double devign = 1.0 / pow(cos(angle), 1.5); + fprintf(stderr, "===> %lf\n", devign); + + *r = (uchar) MIN(rint((double) r_tmp * devign), 255); + *g = (uchar) MIN(rint((double) g_tmp * devign), 255); + *b = (uchar) MIN(rint((double) b_tmp * devign), 255); + } +#endif + + return ret; +} + +double +GipfelWidget::get_angle_off(double a_alph, double a_nick) { + double angle = atan(pow(pow(tan(a_alph - pan->parms.a_center), 2.0) + + pow(tan(a_nick - pan->parms.a_nick), 2.0), 0.5)); + + return angle; } int diff --git a/src/Stitch.H b/src/Stitch.H index dcfc691..13e7bc0 100644 --- a/src/Stitch.H +++ b/src/Stitch.H @@ -33,6 +33,9 @@ class Stitch { int resample(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end); + + int vignette_calib(GipfelWidget::sample_mode_t m, + int w, int h, double view_start, double view_end); }; #endif diff --git a/src/Stitch.cxx b/src/Stitch.cxx index f21c140..35c8c99 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -9,11 +9,16 @@ #include #include +#include + #include #include "OutputImage.H" #include "Stitch.H" +#define MIN(A,B) ((A)<(B)?(A):(B)) + + static double pi_d = asin(1.0) * 2.0; static double deg2rad = pi_d / 180.0; @@ -77,6 +82,78 @@ Stitch::set_output(const char *file, OutputImage *img) { return ret; } +int +Stitch::vignette_calib(GipfelWidget::sample_mode_t m, + int w, int h, double view_start, double view_end) { + + view_start = view_start * deg2rad; + view_end = view_end * deg2rad; + + double step_view = (view_end - view_start) / w; + uchar r, g, b; + int y_off = h / 2; + int merged_pixel_set; + double radius = (double) w / (view_end -view_start); + + double V1 = 6.220359, V2 = -13.874930, V3 = 9.992582; + int max_samples = 10000, n_samples = 0; + gsl_matrix *X, *cov; + gsl_vector *yv, *c; + double chisq; + + + + X = gsl_matrix_alloc(max_samples, 3); + yv = gsl_vector_alloc(max_samples); + c = gsl_vector_alloc(3); + cov = gsl_matrix_alloc (3, 3); + + for (int y=0; yget_pixel(m, a_view, a_nick, + &r, &g, &b) == 0) { + l2 = (double) r + g + b; + a2 = fabs(gipf[i]->get_angle_off(a_view, a_nick)); + + if (l1 > 0.0 && n_samples < max_samples) { + gsl_matrix_set(X, n_samples, 0, l1 * a1 - l2 * a2); + gsl_matrix_set(X, n_samples, 1, l1 * a1 * a1 - l2 * a2 * a2); + gsl_matrix_set(X, n_samples, 2, l1 * a1 * a1 * a1 - l2 * a2 * a2 * a2); + gsl_vector_set(yv, n_samples, l1 - l2); + n_samples++; + } + + l1 = l2; + a1 = a2; + } + } + } + } + + gsl_multifit_linear_workspace * work + = gsl_multifit_linear_alloc (n_samples, 3); + + gsl_multifit_linear (X, yv, c, cov, &chisq, work); + gsl_multifit_linear_free (work); + + fprintf(stderr, "===> v1 %lf, v2 %lf, v3 %lf (i %d)\n", + gsl_vector_get(c,0), gsl_vector_get(c,1), gsl_vector_get(c,2), n_samples); + + return 0; +} + + int Stitch::resample(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end) { @@ -89,6 +166,7 @@ Stitch::resample(GipfelWidget::sample_mode_t m, int y_off = h / 2; int merged_pixel_set; double radius = (double) w / (view_end -view_start); + double V1 = 6.220359, V2 = -13.874930; if (merged_image) { merged_image->init(w, h); @@ -111,11 +189,22 @@ Stitch::resample(GipfelWidget::sample_mode_t m, break; } else if (gipf[i]->get_pixel(m, a_view, a_nick, &r, &g, &b) == 0) { + double l2 = (double) r + g + b; + double a2 = fabs(gipf[i]->get_angle_off(a_view, a_nick)); + double devign = ( 1 + a2 * V1 + a2 * a2 * V2); + +fprintf(stderr, "==> %lf\n", devign); + r = (uchar) MIN(rint((double) r * devign), 255); + g = (uchar) MIN(rint((double) g * devign), 255); + b = (uchar) MIN(rint((double) b * devign), 255); + if (single_images[i]) { - single_images[i]->set_pixel(x, r, g, b); + single_images[i]->set_pixel(x, r + , g, b); } if (!merged_pixel_set && merged_image) { - merged_image->set_pixel(x, r, g, b); + merged_image->set_pixel(x, r, g, + b); merged_pixel_set++; } } @@ -142,3 +231,4 @@ Stitch::resample(GipfelWidget::sample_mode_t m, return 0; } + diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 5807ae5..3862761 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -50,9 +50,10 @@ Fl_Value_Input *i_distortion_k0, *i_distortion_k1, *i_distortion_x0; Fl_Box *b_viewpoint; Fl_Menu_Bar *mb; -#define STITCH_PREVIEW 1 -#define STITCH_JPEG 2 -#define STITCH_TIFF 4 +#define STITCH_PREVIEW 1 +#define STITCH_JPEG 2 +#define STITCH_TIFF 4 +#define STITCH_VIGNETTE_CALIB 8 static int stitch(GipfelWidget::sample_mode_t m ,int stitch_w, int stitch_h, double from, double to, int type, const char *path, int argc, char **argv); @@ -397,7 +398,7 @@ int main(int argc, char** argv) { int err, my_argc; int stitch_flag = 0, stitch_w = 2000, stitch_h = 500; int jpeg_flag = 0, tiff_flag = 0, distortion_flag = 0; - int bilinear_flag = 0; + int bilinear_flag = 0, vignette_flag = 0; double stitch_from = 0.0, stitch_to = 380.0; double dist_k0 = 0.0, dist_k1 = 0.0, dist_x0 = 0.0; char *outpath = "/tmp"; @@ -405,7 +406,7 @@ int main(int argc, char** argv) { err = 0; - while ((c = getopt(argc, argv, ":?d:v:sw:h:j:t:u:br:")) != EOF) { + while ((c = getopt(argc, argv, ":?d:v:sw:h:j:t:u:br:V")) != EOF) { switch (c) { case '?': usage(); @@ -420,6 +421,9 @@ int main(int argc, char** argv) { case 's': stitch_flag++; break; + case 'V': + vignette_flag++; + break; case 'r': stitch_flag++; if (optarg && strcmp(optarg, ":")) { @@ -485,6 +489,8 @@ int main(int argc, char** argv) { type = STITCH_JPEG; } else if (tiff_flag) { type = STITCH_TIFF; + } else if (vignette_flag) { + type = STITCH_VIGNETTE_CALIB; } stitch(bilinear_flag?GipfelWidget::BILINEAR:GipfelWidget::NEAREST, @@ -579,6 +585,10 @@ stitch(GipfelWidget::sample_mode_t m, st->resample(m, stitch_w, stitch_h, from, to); + } else if (type = STITCH_VIGNETTE_CALIB) { + + st->vignette_calib(m, stitch_w, stitch_h, from, to); + } else { win = new Fl_Window(0,0, stitch_w, stitch_h); scroll = new Fl_Scroll(0, 0, win->w(), win->h()); -- cgit v1.2.3 From d47080e941184c48e76f535111a4657639d1a428 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Tue, 13 Mar 2007 20:12:51 +0100 Subject: gsl based version --- src/Stitch.cxx | 73 ++++++++++++++++++++++++++++++++++++++++++++-------------- src/gipfel.cxx | 12 ++++++---- 2 files changed, 63 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 35c8c99..e41af91 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -101,12 +101,14 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, gsl_vector *yv, *c; double chisq; - - - X = gsl_matrix_alloc(max_samples, 3); + X = gsl_matrix_alloc(max_samples, 1); yv = gsl_vector_alloc(max_samples); - c = gsl_vector_alloc(3); - cov = gsl_matrix_alloc (3, 3); + c = gsl_vector_alloc(1); + cov = gsl_matrix_alloc (1, 1); + + if (merged_image) { + merged_image->init(w, h); + } for (int y=0; yget_pixel(m, a_view, a_nick, - &r, &g, &b) == 0) { - l2 = (double) r + g + b; + &c2[0], &c2[1], &c2[2]) == 0) { + l2 = (double) c2[0] + c2[1] + c2[2]; a2 = fabs(gipf[i]->get_angle_off(a_view, a_nick)); - if (l1 > 0.0 && n_samples < max_samples) { - gsl_matrix_set(X, n_samples, 0, l1 * a1 - l2 * a2); - gsl_matrix_set(X, n_samples, 1, l1 * a1 * a1 - l2 * a2 * a2); - gsl_matrix_set(X, n_samples, 2, l1 * a1 * a1 * a1 - l2 * a2 * a2 * a2); - gsl_vector_set(yv, n_samples, l1 - l2); + if (l1 > 0.0 && n_samples < max_samples && + fabs(a1 - a2) > 0.1 && + fabs(((double) c1[1]) / ((double) c1[0]) - + ((double) c2[1]) / ((double) c2[0])) < 0.2 && + fabs(((double) c1[2]) / ((double) c1[0]) - + ((double) c2[2]) / ((double) c2[0])) < 0.2) { + + gsl_matrix_set(X, n_samples, 0, l1 * a1 * a1 - l2 * a2 * a2); + gsl_vector_set(yv, n_samples, l2 - l1); n_samples++; + + if (merged_image) { + merged_image->set_pixel(x, 255, 0, 0); + merged_pixel_set++; + } } l1 = l2; a1 = a2; + c1[0] = c2[0]; + c1[1] = c2[1]; + c1[2] = c2[2]; + + if (!merged_pixel_set && merged_image) { + merged_image->set_pixel(x, r, g, b); + } } } } + if (merged_image) { + merged_image->next_line(); + } + } + + if (merged_image) { + merged_image->done(); } gsl_multifit_linear_workspace * work - = gsl_multifit_linear_alloc (n_samples, 3); + = gsl_multifit_linear_alloc (n_samples, 1); gsl_multifit_linear (X, yv, c, cov, &chisq, work); gsl_multifit_linear_free (work); - fprintf(stderr, "===> v1 %lf, v2 %lf, v3 %lf (i %d)\n", - gsl_vector_get(c,0), gsl_vector_get(c,1), gsl_vector_get(c,2), n_samples); + fprintf(stderr, "===> v2 %lf, (i %d)\n", + gsl_vector_get(c,0), n_samples); return 0; } @@ -166,7 +193,7 @@ Stitch::resample(GipfelWidget::sample_mode_t m, int y_off = h / 2; int merged_pixel_set; double radius = (double) w / (view_end -view_start); - double V1 = 6.220359, V2 = -13.874930; + double V1 = 0.0, V2 = 0.16435; if (merged_image) { merged_image->init(w, h); @@ -179,6 +206,7 @@ Stitch::resample(GipfelWidget::sample_mode_t m, for (int y=0; yget_angle_off(a_view, a_nick)); double devign = ( 1 + a2 * V1 + a2 * a2 * V2); +if (a2 > a_max) { +fprintf(stderr, "==> %lf %lf\n", devign, a2); +a_max = a2; +} -fprintf(stderr, "==> %lf\n", devign); +#if 1 r = (uchar) MIN(rint((double) r * devign), 255); g = (uchar) MIN(rint((double) g * devign), 255); b = (uchar) MIN(rint((double) b * devign), 255); +#else + + r = (uchar) MIN(rint((double) 250 * devign), 255); + g = (uchar) MIN(rint((double) 250 * devign), 255); + b = (uchar) MIN(rint((double) 250 * devign), 255); +#endif + if (single_images[i]) { single_images[i]->set_pixel(x, r diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 3862761..584ae15 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -585,10 +585,6 @@ stitch(GipfelWidget::sample_mode_t m, st->resample(m, stitch_w, stitch_h, from, to); - } else if (type = STITCH_VIGNETTE_CALIB) { - - st->vignette_calib(m, stitch_w, stitch_h, from, to); - } else { win = new Fl_Window(0,0, stitch_w, stitch_h); scroll = new Fl_Scroll(0, 0, win->w(), win->h()); @@ -598,7 +594,13 @@ stitch(GipfelWidget::sample_mode_t m, win->resizable(scroll); win->show(0, argv); st->set_output((OutputImage*) img); - st->resample(m, stitch_w, stitch_h, from, to); + + if (type == STITCH_VIGNETTE_CALIB) { + st->vignette_calib(m, stitch_w, stitch_h, from, to); + } else { + st->resample(m, stitch_w, stitch_h, from, to); + } + img->redraw(); Fl::run(); } -- cgit v1.2.3 From 8a59c4f63a5c0309e403ea5896ad6d3bbdac16bc Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Wed, 14 Mar 2007 16:30:33 +0100 Subject: devign stuff --- src/Stitch.cxx | 83 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index e41af91..54d2272 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -95,16 +95,15 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int merged_pixel_set; double radius = (double) w / (view_end -view_start); - double V1 = 6.220359, V2 = -13.874930, V3 = 9.992582; int max_samples = 10000, n_samples = 0; gsl_matrix *X, *cov; gsl_vector *yv, *c; double chisq; - X = gsl_matrix_alloc(max_samples, 1); + X = gsl_matrix_alloc(max_samples, 2); yv = gsl_vector_alloc(max_samples); - c = gsl_vector_alloc(1); - cov = gsl_matrix_alloc (1, 1); + c = gsl_vector_alloc(2); + cov = gsl_matrix_alloc (2, 2); if (merged_image) { merged_image->init(w, h); @@ -127,23 +126,34 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, break; } else if (gipf[i]->get_pixel(m, a_view, a_nick, &c2[0], &c2[1], &c2[2]) == 0) { - l2 = (double) c2[0] + c2[1] + c2[2]; - a2 = fabs(gipf[i]->get_angle_off(a_view, a_nick)); - - if (l1 > 0.0 && n_samples < max_samples && - fabs(a1 - a2) > 0.1 && - fabs(((double) c1[1]) / ((double) c1[0]) - - ((double) c2[1]) / ((double) c2[0])) < 0.2 && - fabs(((double) c1[2]) / ((double) c1[0]) - - ((double) c2[2]) / ((double) c2[0])) < 0.2) { - - gsl_matrix_set(X, n_samples, 0, l1 * a1 * a1 - l2 * a2 * a2); - gsl_vector_set(yv, n_samples, l2 - l1); - n_samples++; - - if (merged_image) { - merged_image->set_pixel(x, 255, 0, 0); - merged_pixel_set++; + l2 = (double) c2[0] + (double) c2[1] + (double) c2[2]; + a2 = gipf[i]->get_angle_off(a_view, a_nick); + + if (l1 > 0.0) { + + if (n_samples < max_samples && + fabs(a1 - a2) > 0.02 && + c1[0] < 200 && c1[1] < 200 && c1[2] < 200 && + c2[0] < 200 && c2[1] < 200 && c2[2] < 200 && + fabs(((double) c1[1]) / ((double) c1[0]) - + ((double) c2[1]) / ((double) c2[0])) < 0.02 && + fabs(((double) c1[2]) / ((double) c1[0]) - + ((double) c2[2]) / ((double) c2[0])) < 0.02) { + + gsl_matrix_set(X, n_samples, 0, l2 * a2 * a2 *a2 * a2 - l1 * a1 *a1 *a1 * a1); + gsl_matrix_set(X, n_samples, 1, l2 * a2 * a2 - l1 * a1 * a1); + gsl_vector_set(yv, n_samples, l1 - l2); + n_samples++; + + if (merged_image) { + double V1 = -0.57301, V2 = 0.85233; + double d = fabs(V2 * (l2 * a2 * a2 - l1 * a1 * a1) + V1 * (l2 * a2 * a2 *a2 - l1 * a1 * a1 *a1) - (l1 -l2)); + + merged_image->set_pixel(x, (uchar) rint(d * 2), 0, 0); + merged_pixel_set++; + } + + } } @@ -154,7 +164,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, c1[2] = c2[2]; if (!merged_pixel_set && merged_image) { - merged_image->set_pixel(x, r, g, b); + merged_image->set_pixel(x, c1[0], c1[1], c1[2]); } } } @@ -169,13 +179,13 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, } gsl_multifit_linear_workspace * work - = gsl_multifit_linear_alloc (n_samples, 1); + = gsl_multifit_linear_alloc (n_samples, 2); gsl_multifit_linear (X, yv, c, cov, &chisq, work); gsl_multifit_linear_free (work); - fprintf(stderr, "===> v2 %lf, (i %d)\n", - gsl_vector_get(c,0), n_samples); + fprintf(stderr, "===> v1 %lf v2 %lf, (i %d)\n", + gsl_vector_get(c,0),gsl_vector_get(c,1), n_samples); return 0; } @@ -193,7 +203,7 @@ Stitch::resample(GipfelWidget::sample_mode_t m, int y_off = h / 2; int merged_pixel_set; double radius = (double) w / (view_end -view_start); - double V1 = 0.0, V2 = 0.16435; + double V1 = 0.213895, V2 = 0.089561; if (merged_image) { merged_image->init(w, h); @@ -217,13 +227,8 @@ Stitch::resample(GipfelWidget::sample_mode_t m, break; } else if (gipf[i]->get_pixel(m, a_view, a_nick, &r, &g, &b) == 0) { - double l2 = (double) r + g + b; - double a2 = fabs(gipf[i]->get_angle_off(a_view, a_nick)); - double devign = ( 1 + a2 * V1 + a2 * a2 * V2); -if (a2 > a_max) { -fprintf(stderr, "==> %lf %lf\n", devign, a2); -a_max = a2; -} + double a2 = gipf[i]->get_angle_off(a_view, a_nick); + double devign = ( 1 + a2 * a2 * V2 + a2*a2*a2*a2 * V1); #if 1 r = (uchar) MIN(rint((double) r * devign), 255); @@ -231,19 +236,17 @@ a_max = a2; b = (uchar) MIN(rint((double) b * devign), 255); #else - r = (uchar) MIN(rint((double) 250 * devign), 255); - g = (uchar) MIN(rint((double) 250 * devign), 255); - b = (uchar) MIN(rint((double) 250 * devign), 255); + r = (uchar) MIN(rint((double) 100 * devign), 255); + g = (uchar) MIN(rint((double) 100 * devign), 255); + b = (uchar) MIN(rint((double) 100 * devign), 255); #endif if (single_images[i]) { - single_images[i]->set_pixel(x, r - , g, b); + single_images[i]->set_pixel(x, r, g, b); } if (!merged_pixel_set && merged_image) { - merged_image->set_pixel(x, r, g, - b); + merged_image->set_pixel(x, r, g, b); merged_pixel_set++; } } -- cgit v1.2.3 From 905cd5600e604aa1f9fe256ab3b4d7125695951e Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Thu, 15 Mar 2007 00:25:29 +0100 Subject: add color and brightness adjustment --- src/Stitch.H | 7 +- src/Stitch.cxx | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- src/gipfel.cxx | 4 +- 3 files changed, 201 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/Stitch.H b/src/Stitch.H index 13e7bc0..62175be 100644 --- a/src/Stitch.H +++ b/src/Stitch.H @@ -13,13 +13,15 @@ #define MAX_PICS 256 + class Stitch { private: GipfelWidget *gipf[MAX_PICS]; + double color_adjust[MAX_PICS][3]; + double V1, V2; OutputImage *single_images[MAX_PICS]; OutputImage *merged_image; - public: Stitch(); @@ -34,6 +36,9 @@ class Stitch { int resample(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end); + int color_calib(GipfelWidget::sample_mode_t m, + int w, int h, double view_start, double view_end); + int vignette_calib(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end); }; diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 54d2272..dbd0d53 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -28,6 +28,9 @@ Stitch::Stitch() { single_images[i] = NULL; } merged_image = NULL; + V1 = 0.213895; + V2 = 0.089561; + } Stitch::~Stitch() { @@ -82,6 +85,183 @@ Stitch::set_output(const char *file, OutputImage *img) { return ret; } +typedef struct { + int c1[3]; + int c2[3]; +} sample_t; + +static int +get_color_adjust(const sample_t *samples, int n_samples, + const double *color_adjust_1, double *color_adjust_2) { + + gsl_matrix *X, *cov; + gsl_vector *yv, *r; + double chisq; + + X = gsl_matrix_alloc(n_samples, 1); + yv = gsl_vector_alloc(n_samples); + r = gsl_vector_alloc(1); + cov = gsl_matrix_alloc (1, 1); + + for (int c = 0; c<3; c++) { + for (int i = 0; i< n_samples; i++) { + gsl_matrix_set(X, i, 0, samples[i].c2[c]); + gsl_vector_set(yv, i, samples[i].c1[c] * color_adjust_1[c]); + } + + + gsl_multifit_linear_workspace * work + = gsl_multifit_linear_alloc (n_samples, 1); + + gsl_multifit_linear (X, yv, r, cov, &chisq, work); + gsl_multifit_linear_free (work); + + color_adjust_2[c] = gsl_vector_get(r,0); + } + + return 0; + +} + + + +int +Stitch::color_calib(GipfelWidget::sample_mode_t m, + int w, int h, double view_start, double view_end) { + + sample_t * sample_points[MAX_PICS][MAX_PICS]; + + memset(sample_points, 0, sizeof(sample_points)); + + view_start = view_start * deg2rad; + view_end = view_end * deg2rad; + + double step_view = (view_end - view_start) / w; + uchar r, g, b; + int y_off = h / 2; + int merged_pixel_set; + double radius = (double) w / (view_end -view_start); + + if (merged_image) { + merged_image->init(w, h); + } + + for(int j=0; j<3; j++) { + color_adjust[0][j] = 1.0; + } + + for (int i=1; iget_pixel(m, a_view, a_nick, + &c1[0], &c1[1], &c1[2]) == 0) { + + double a1 = gipf[p1]->get_angle_off(a_view, a_nick); + double devign = ( 1 + a1 * a1 * V2 + a1*a1*a1*a1 * V1); + for (int l=0; l<3;l++) { + c1[l]=((uchar)MIN(rint((double) c1[l] * devign), 255)); + } + + for (int p2=0; p2get_pixel(m, a_view, a_nick, + &c2[0], &c2[1], &c2[2]) == 0) { + double a2 = gipf[p2]->get_angle_off(a_view, a_nick); + devign = ( 1 + a2 * a2 * V2 + a2*a2*a2*a2 * V1); + for (int l=0; l<3;l++) { + c2[l]=((uchar)MIN(rint((double) c2[l] * devign), 255)); + } + + if (fabs(a1-a2) < 0.02 && + fabs(((double) c1[1]) / ((double) c1[0]) - + ((double) c2[1]) / ((double) c2[0])) < 1.0 && + fabs(((double) c1[2]) / ((double) c1[0]) - + ((double) c2[2]) / ((double) c2[0])) < 1.0) { + + if (sample_points[p1][p2] == NULL) { + fprintf(stderr, "allocated sample_points [%d][%d]\n", p1, p2); + sample_points[p1][p2] = (sample_t*) + calloc(500, sizeof(sample_t)); + } + + for (int k=0; k < 500; k++) { + if (sample_points[p1][p2][k].c1[0] == 0) { + for (int l=0; l < 3; l++) { + sample_points[p1][p2][k].c1[l] = c1[l]; + sample_points[p1][p2][k].c2[l] = c2[l]; + } + break; + } + + } + + if (merged_image) { + merged_image->set_pixel(x, 255, 0, 0); + merged_pixel_set++; + } + + + } + } + } + + + if (!merged_pixel_set && merged_image) { + merged_image->set_pixel(x, c1[0], c1[1], c1[2]); + } + } + } + } + if (merged_image) { + merged_image->next_line(); + } + } + + if (merged_image) { + merged_image->done(); + } + + for (int n=0; n<20; n++) { + for (int i=0; i 0.0) { + for (int j=1; j Adjust %d: %lf %lf %lf\n", j, color_adjust[j][0], color_adjust[j][1], color_adjust[j][2]); + } + } + + } + } + } + + + return 0; +} + + int Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end) { @@ -126,7 +306,9 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, break; } else if (gipf[i]->get_pixel(m, a_view, a_nick, &c2[0], &c2[1], &c2[2]) == 0) { - l2 = (double) c2[0] + (double) c2[1] + (double) c2[2]; + l2 = (double) c2[0] * color_adjust[i][0] + + (double) c2[1] * color_adjust[i][1] + + (double) c2[2] * color_adjust[i][2]; a2 = gipf[i]->get_angle_off(a_view, a_nick); if (l1 > 0.0) { @@ -136,9 +318,9 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, c1[0] < 200 && c1[1] < 200 && c1[2] < 200 && c2[0] < 200 && c2[1] < 200 && c2[2] < 200 && fabs(((double) c1[1]) / ((double) c1[0]) - - ((double) c2[1]) / ((double) c2[0])) < 0.02 && + ((double) c2[1]) / ((double) c2[0])) < 0.05 && fabs(((double) c1[2]) / ((double) c1[0]) - - ((double) c2[2]) / ((double) c2[0])) < 0.02) { + ((double) c2[2]) / ((double) c2[0])) < 0.05) { gsl_matrix_set(X, n_samples, 0, l2 * a2 * a2 *a2 * a2 - l1 * a1 *a1 *a1 * a1); gsl_matrix_set(X, n_samples, 1, l2 * a2 * a2 - l1 * a1 * a1); @@ -146,7 +328,6 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, n_samples++; if (merged_image) { - double V1 = -0.57301, V2 = 0.85233; double d = fabs(V2 * (l2 * a2 * a2 - l1 * a1 * a1) + V1 * (l2 * a2 * a2 *a2 - l1 * a1 * a1 *a1) - (l1 -l2)); merged_image->set_pixel(x, (uchar) rint(d * 2), 0, 0); @@ -184,8 +365,11 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, gsl_multifit_linear (X, yv, c, cov, &chisq, work); gsl_multifit_linear_free (work); + V1 = gsl_vector_get(c,0); + V2 = gsl_vector_get(c,1); + fprintf(stderr, "===> v1 %lf v2 %lf, (i %d)\n", - gsl_vector_get(c,0),gsl_vector_get(c,1), n_samples); + V1, V2, n_samples); return 0; } @@ -203,7 +387,6 @@ Stitch::resample(GipfelWidget::sample_mode_t m, int y_off = h / 2; int merged_pixel_set; double radius = (double) w / (view_end -view_start); - double V1 = 0.213895, V2 = 0.089561; if (merged_image) { merged_image->init(w, h); @@ -231,9 +414,9 @@ Stitch::resample(GipfelWidget::sample_mode_t m, double devign = ( 1 + a2 * a2 * V2 + a2*a2*a2*a2 * V1); #if 1 - r = (uchar) MIN(rint((double) r * devign), 255); - g = (uchar) MIN(rint((double) g * devign), 255); - b = (uchar) MIN(rint((double) b * devign), 255); + r = (uchar) MIN(rint(((double) r) * devign * color_adjust[i][0]), 255); + g = (uchar) MIN(rint(((double) g) * devign * color_adjust[i][1]), 255); + b = (uchar) MIN(rint(((double) b) * devign * color_adjust[i][2]), 255); #else r = (uchar) MIN(rint((double) 100 * devign), 255); diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 584ae15..7aad38f 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -596,7 +596,9 @@ stitch(GipfelWidget::sample_mode_t m, st->set_output((OutputImage*) img); if (type == STITCH_VIGNETTE_CALIB) { - st->vignette_calib(m, stitch_w, stitch_h, from, to); + st->color_calib(m, stitch_w, stitch_h, from, to); + //st->vignette_calib(m, stitch_w, stitch_h, from, to); + st->resample(m, stitch_w, stitch_h, from, to); } else { st->resample(m, stitch_w, stitch_h, from, to); } -- cgit v1.2.3 From c7a40505652adc10d29b2049bb4553cf91cec823 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Thu, 15 Mar 2007 15:58:00 +0100 Subject: make it work with fixed vignetting params --- src/Stitch.cxx | 2 +- src/gipfel.cxx | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index dbd0d53..1391fff 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -192,7 +192,7 @@ Stitch::color_calib(GipfelWidget::sample_mode_t m, c2[l]=((uchar)MIN(rint((double) c2[l] * devign), 255)); } - if (fabs(a1-a2) < 0.02 && + if (fabs(a1-a2) < 0.01 && fabs(((double) c1[1]) / ((double) c1[0]) - ((double) c2[1]) / ((double) c2[0])) < 1.0 && fabs(((double) c1[2]) / ((double) c1[0]) - diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 7aad38f..23a5c5f 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -484,13 +484,17 @@ int main(int argc, char** argv) { } if (stitch_flag) { - int type = STITCH_PREVIEW; + int type = 0; if (jpeg_flag) { type = STITCH_JPEG; } else if (tiff_flag) { type = STITCH_TIFF; - } else if (vignette_flag) { - type = STITCH_VIGNETTE_CALIB; + } else { + type = STITCH_PREVIEW; + } + + if (vignette_flag) { + type |= STITCH_VIGNETTE_CALIB; } stitch(bilinear_flag?GipfelWidget::BILINEAR:GipfelWidget::NEAREST, @@ -564,12 +568,17 @@ stitch(GipfelWidget::sample_mode_t m, st->load_image(argv[i]); } - if (type == STITCH_JPEG) { + if (type & STITCH_VIGNETTE_CALIB) { + st->color_calib(m, stitch_w, stitch_h, from, to); + //st->vignette_calib(m, stitch_w, stitch_h, from, to); + } + + if (type & STITCH_JPEG) { st->set_output((OutputImage*) new JPEGOutputImage(path, 90)); st->resample(m, stitch_w, stitch_h, from, to); - } else if (type == STITCH_TIFF) { + } else if (type & STITCH_TIFF) { for (int i=0; ishow(0, argv); st->set_output((OutputImage*) img); - if (type == STITCH_VIGNETTE_CALIB) { - st->color_calib(m, stitch_w, stitch_h, from, to); - //st->vignette_calib(m, stitch_w, stitch_h, from, to); - st->resample(m, stitch_w, stitch_h, from, to); - } else { - st->resample(m, stitch_w, stitch_h, from, to); - } + st->resample(m, stitch_w, stitch_h, from, to); img->redraw(); Fl::run(); -- cgit v1.2.3 From 5fd1230803fddcfb8e3cfb38608221ef52c0f104 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 16 Mar 2007 15:20:43 +0100 Subject: try linear version - does not work yet --- src/Stitch.H | 9 +- src/Stitch.cxx | 321 +++++++++++++++++---------------------------------------- src/gipfel.cxx | 7 +- 3 files changed, 99 insertions(+), 238 deletions(-) (limited to 'src') diff --git a/src/Stitch.H b/src/Stitch.H index 62175be..29f0ef3 100644 --- a/src/Stitch.H +++ b/src/Stitch.H @@ -17,11 +17,13 @@ class Stitch { private: GipfelWidget *gipf[MAX_PICS]; - double color_adjust[MAX_PICS][3]; - double V1, V2; + int num_pics; + double color_adjust[MAX_PICS][3][3]; OutputImage *single_images[MAX_PICS]; OutputImage *merged_image; + uchar color_correct(uchar c, double a, int pic, int color); + public: Stitch(); @@ -36,9 +38,6 @@ class Stitch { int resample(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end); - int color_calib(GipfelWidget::sample_mode_t m, - int w, int h, double view_start, double view_end); - int vignette_calib(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end); }; diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 1391fff..113dc62 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -28,8 +28,7 @@ Stitch::Stitch() { single_images[i] = NULL; } merged_image = NULL; - V1 = 0.213895; - V2 = 0.089561; + num_pics = 0; } @@ -52,6 +51,8 @@ Stitch::load_image(char *file) { if (gipf[i]->load_image(file) != 0) { delete gipf[i]; gipf[i] = NULL; + } else { + num_pics++; } break; } @@ -85,54 +86,11 @@ Stitch::set_output(const char *file, OutputImage *img) { return ret; } -typedef struct { - int c1[3]; - int c2[3]; -} sample_t; - -static int -get_color_adjust(const sample_t *samples, int n_samples, - const double *color_adjust_1, double *color_adjust_2) { - - gsl_matrix *X, *cov; - gsl_vector *yv, *r; - double chisq; - - X = gsl_matrix_alloc(n_samples, 1); - yv = gsl_vector_alloc(n_samples); - r = gsl_vector_alloc(1); - cov = gsl_matrix_alloc (1, 1); - - for (int c = 0; c<3; c++) { - for (int i = 0; i< n_samples; i++) { - gsl_matrix_set(X, i, 0, samples[i].c2[c]); - gsl_vector_set(yv, i, samples[i].c1[c] * color_adjust_1[c]); - } - - - gsl_multifit_linear_workspace * work - = gsl_multifit_linear_alloc (n_samples, 1); - - gsl_multifit_linear (X, yv, r, cov, &chisq, work); - gsl_multifit_linear_free (work); - - color_adjust_2[c] = gsl_vector_get(r,0); - } - - return 0; - -} - - int -Stitch::color_calib(GipfelWidget::sample_mode_t m, +Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end) { - sample_t * sample_points[MAX_PICS][MAX_PICS]; - - memset(sample_points, 0, sizeof(sample_points)); - view_start = view_start * deg2rad; view_end = view_end * deg2rad; @@ -142,18 +100,20 @@ Stitch::color_calib(GipfelWidget::sample_mode_t m, int merged_pixel_set; double radius = (double) w / (view_end -view_start); - if (merged_image) { - merged_image->init(w, h); - } + int max_samples = 10 * 3, n_samples = 0; + int ret; + int n_vars = (num_pics-1) * 9; + gsl_matrix *X, *cov; + gsl_vector *yv, *c; + double chisq; - for(int j=0; j<3; j++) { - color_adjust[0][j] = 1.0; - } + X = gsl_matrix_alloc(max_samples, n_vars); + yv = gsl_vector_alloc(max_samples); + c = gsl_vector_alloc(n_vars); + cov = gsl_matrix_alloc (n_vars, n_vars); - for (int i=1; iinit(w, h); } for (int y=0; yget_pixel(m, a_view, a_nick, &c1[0], &c1[1], &c1[2]) == 0) { - double a1 = gipf[p1]->get_angle_off(a_view, a_nick); - double devign = ( 1 + a1 * a1 * V2 + a1*a1*a1*a1 * V1); - for (int l=0; l<3;l++) { - c1[l]=((uchar)MIN(rint((double) c1[l] * devign), 255)); + for (int l = 0; l<3; l++) { + c1d[l] = (double) c1[l]; } - for (int p2=0; p2get_angle_off(a_view, a_nick); + for (int p2=1; p2get_pixel(m, a_view, a_nick, &c2[0], &c2[1], &c2[2]) == 0) { - double a2 = gipf[p2]->get_angle_off(a_view, a_nick); - devign = ( 1 + a2 * a2 * V2 + a2*a2*a2*a2 * V1); - for (int l=0; l<3;l++) { - c2[l]=((uchar)MIN(rint((double) c2[l] * devign), 255)); - } - if (fabs(a1-a2) < 0.01 && - fabs(((double) c1[1]) / ((double) c1[0]) - - ((double) c2[1]) / ((double) c2[0])) < 1.0 && - fabs(((double) c1[2]) / ((double) c1[0]) - - ((double) c2[2]) / ((double) c2[0])) < 1.0) { - - if (sample_points[p1][p2] == NULL) { - fprintf(stderr, "allocated sample_points [%d][%d]\n", p1, p2); - sample_points[p1][p2] = (sample_t*) - calloc(500, sizeof(sample_t)); - } + for (int l = 0; l<3; l++) { + c2d[l] = (double) c2[l]; + } - for (int k=0; k < 500; k++) { - if (sample_points[p1][p2][k].c1[0] == 0) { - for (int l=0; l < 3; l++) { - sample_points[p1][p2][k].c1[l] = c1[l]; - sample_points[p1][p2][k].c2[l] = c2[l]; - } - break; + a2 = gipf[p2]->get_angle_off(a_view, a_nick); + + if (n_samples < max_samples && + c1[0] < 200 && c1[1] < 200 && c1[2] < 200 && + c2[0] < 200 && c2[1] < 200 && c2[2] < 200 && + c1[0] > 20 && c1[1] > 20 && c1[2] > 20 && + c2[0] > 20 && c2[1] > 20 && c2[2] > 20 && + fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.01 && + fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.01 ) { + + for (int l = 0; l<3; l++) { + gsl_matrix_set_zero(X); + if (p1 == 0) { +fprintf(stderr, "==> p1 = 0 p2 = %d\n", p2); + // gsl_matrix_set(X, n_samples, (p2-1) * 9 + 3 * l + 2, c2d[l] * a2 *a2 * a2 * a2); + // gsl_matrix_set(X, n_samples, (p2-1) * 9 + 3 * l + 1, c2d[l] * a2 * a2); + gsl_matrix_set(X, n_samples, (p2-1) * 9 + 3 * l + 0, c2d[l]); + gsl_vector_set(yv, n_samples, c1d[l]); + } else { + // gsl_matrix_set(X, n_samples, (p1-1) * 9 + 3 * l + 2, - c1d[l] * a1 *a1 * a1 * a1); + // gsl_matrix_set(X, n_samples, (p2-1) * 9 + 3 * l + 2, c2d[l] * a2 * a2 * a2 * a2); + // gsl_matrix_set(X, n_samples, (p1-1) * 9 + 3 * l + 1, - c1d[l] * a1 * a1); + // gsl_matrix_set(X, n_samples, (p2-1) * 9 + 3 * l + 1, c2d[l] * a2 * a2); + gsl_matrix_set(X, n_samples, (p1-1) * 9 + 3 * l + 0, - c1d[l]); + gsl_matrix_set(X, n_samples, (p2-1) * 9 + 3 * l + 0, c2d[l]); + gsl_vector_set(yv, n_samples, 0.0); } - + n_samples++; } - + if (merged_image) { merged_image->set_pixel(x, 255, 0, 0); merged_pixel_set++; } - - } + } } - if (!merged_pixel_set && merged_image) { merged_image->set_pixel(x, c1[0], c1[1], c1[2]); + merged_pixel_set++; } + } } } @@ -240,141 +206,47 @@ Stitch::color_calib(GipfelWidget::sample_mode_t m, if (merged_image) { merged_image->done(); } - - for (int n=0; n<20; n++) { - for (int i=0; i 0.0) { - for (int j=1; j Adjust %d: %lf %lf %lf\n", j, color_adjust[j][0], color_adjust[j][1], color_adjust[j][2]); - } +gsl_vector_fprintf(stderr, yv, "%f"); + gsl_multifit_linear_workspace * work + = gsl_multifit_linear_alloc (n_samples, n_vars); + + ret = gsl_multifit_linear (X, yv, c, cov, &chisq, work); + gsl_multifit_linear_free (work); + + fprintf(stderr, "gsl_multifit_linear returned %d\n", ret); + + for (int p1=0; p1 < num_pics; p1++) { + for (int l = 0; l<3; l++) { + if (p1 == 0) { + color_adjust[p1][l][0] = 1.0; + color_adjust[p1][l][1] = 0.0; + color_adjust[p1][l][2] = 0.0; + } else { + for (int k = 0; k<3; k++) { + color_adjust[p1][l][k] = gsl_vector_get(c, (p1-1) * 9 + 3 * l + k); } - + color_adjust[p1][l][1] = 0.0; + color_adjust[p1][l][2] = 0.0; } } - } - +fprintf(stderr, "==> color_adjust(%d) %f %f %f\n", p1, color_adjust[p1][0][0], color_adjust[p1][1][0],color_adjust[p1][2][0]); + } return 0; } +uchar +Stitch::color_correct(uchar c, double a, int pic, int color) { + double cd = (double) c; + + cd = cd * ( + color_adjust[pic][color][0] + + color_adjust[pic][color][1] * a * a + + color_adjust[pic][color][2] * a * a * a * a); -int -Stitch::vignette_calib(GipfelWidget::sample_mode_t m, - int w, int h, double view_start, double view_end) { - - view_start = view_start * deg2rad; - view_end = view_end * deg2rad; - - double step_view = (view_end - view_start) / w; - uchar r, g, b; - int y_off = h / 2; - int merged_pixel_set; - double radius = (double) w / (view_end -view_start); - - int max_samples = 10000, n_samples = 0; - gsl_matrix *X, *cov; - gsl_vector *yv, *c; - double chisq; - - X = gsl_matrix_alloc(max_samples, 2); - yv = gsl_vector_alloc(max_samples); - c = gsl_vector_alloc(2); - cov = gsl_matrix_alloc (2, 2); - - if (merged_image) { - merged_image->init(w, h); - } - - for (int y=0; yget_pixel(m, a_view, a_nick, - &c2[0], &c2[1], &c2[2]) == 0) { - l2 = (double) c2[0] * color_adjust[i][0] + - (double) c2[1] * color_adjust[i][1] + - (double) c2[2] * color_adjust[i][2]; - a2 = gipf[i]->get_angle_off(a_view, a_nick); - - if (l1 > 0.0) { - - if (n_samples < max_samples && - fabs(a1 - a2) > 0.02 && - c1[0] < 200 && c1[1] < 200 && c1[2] < 200 && - c2[0] < 200 && c2[1] < 200 && c2[2] < 200 && - fabs(((double) c1[1]) / ((double) c1[0]) - - ((double) c2[1]) / ((double) c2[0])) < 0.05 && - fabs(((double) c1[2]) / ((double) c1[0]) - - ((double) c2[2]) / ((double) c2[0])) < 0.05) { - - gsl_matrix_set(X, n_samples, 0, l2 * a2 * a2 *a2 * a2 - l1 * a1 *a1 *a1 * a1); - gsl_matrix_set(X, n_samples, 1, l2 * a2 * a2 - l1 * a1 * a1); - gsl_vector_set(yv, n_samples, l1 - l2); - n_samples++; - - if (merged_image) { - double d = fabs(V2 * (l2 * a2 * a2 - l1 * a1 * a1) + V1 * (l2 * a2 * a2 *a2 - l1 * a1 * a1 *a1) - (l1 -l2)); - - merged_image->set_pixel(x, (uchar) rint(d * 2), 0, 0); - merged_pixel_set++; - } - - - } - } - - l1 = l2; - a1 = a2; - c1[0] = c2[0]; - c1[1] = c2[1]; - c1[2] = c2[2]; - - if (!merged_pixel_set && merged_image) { - merged_image->set_pixel(x, c1[0], c1[1], c1[2]); - } - } - } - } - if (merged_image) { - merged_image->next_line(); - } - } - - if (merged_image) { - merged_image->done(); - } - - gsl_multifit_linear_workspace * work - = gsl_multifit_linear_alloc (n_samples, 2); - - gsl_multifit_linear (X, yv, c, cov, &chisq, work); - gsl_multifit_linear_free (work); - - V1 = gsl_vector_get(c,0); - V2 = gsl_vector_get(c,1); - - fprintf(stderr, "===> v1 %lf v2 %lf, (i %d)\n", - V1, V2, n_samples); - - return 0; + return (uchar) MIN(rint(cd), 255.0); } - int Stitch::resample(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end) { @@ -410,20 +282,11 @@ Stitch::resample(GipfelWidget::sample_mode_t m, break; } else if (gipf[i]->get_pixel(m, a_view, a_nick, &r, &g, &b) == 0) { - double a2 = gipf[i]->get_angle_off(a_view, a_nick); - double devign = ( 1 + a2 * a2 * V2 + a2*a2*a2*a2 * V1); - -#if 1 - r = (uchar) MIN(rint(((double) r) * devign * color_adjust[i][0]), 255); - g = (uchar) MIN(rint(((double) g) * devign * color_adjust[i][1]), 255); - b = (uchar) MIN(rint(((double) b) * devign * color_adjust[i][2]), 255); -#else - - r = (uchar) MIN(rint((double) 100 * devign), 255); - g = (uchar) MIN(rint((double) 100 * devign), 255); - b = (uchar) MIN(rint((double) 100 * devign), 255); -#endif + double a = gipf[i]->get_angle_off(a_view, a_nick); + r = color_correct(r, a, i, 0); + g = color_correct(g, a, i, 1); + b = color_correct(b, a, i, 2); if (single_images[i]) { single_images[i]->set_pixel(x, r, g, b); diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 23a5c5f..e9743d8 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -568,10 +568,6 @@ stitch(GipfelWidget::sample_mode_t m, st->load_image(argv[i]); } - if (type & STITCH_VIGNETTE_CALIB) { - st->color_calib(m, stitch_w, stitch_h, from, to); - //st->vignette_calib(m, stitch_w, stitch_h, from, to); - } if (type & STITCH_JPEG) { @@ -604,6 +600,9 @@ stitch(GipfelWidget::sample_mode_t m, win->show(0, argv); st->set_output((OutputImage*) img); + if (type & STITCH_VIGNETTE_CALIB) { + st->vignette_calib(m, stitch_w, stitch_h, from, to); + } st->resample(m, stitch_w, stitch_h, from, to); img->redraw(); -- cgit v1.2.3 From be9c6d740796edbb097b56ca3fdb181687d5dd47 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 16 Mar 2007 16:49:18 +0100 Subject: make things work somehow --- src/Stitch.cxx | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 113dc62..3bb39e9 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -86,6 +86,10 @@ Stitch::set_output(const char *file, OutputImage *img) { return ret; } +static int +var_offset(int pic, int color, int pow) { + return 9 * (pic - 1) + 3 * color + pow; +} int Stitch::vignette_calib(GipfelWidget::sample_mode_t m, @@ -100,7 +104,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int merged_pixel_set; double radius = (double) w / (view_end -view_start); - int max_samples = 10 * 3, n_samples = 0; + int max_samples = 10000 * 3, n_samples = 0; int ret; int n_vars = (num_pics-1) * 9; gsl_matrix *X, *cov; @@ -108,6 +112,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, double chisq; X = gsl_matrix_alloc(max_samples, n_vars); + gsl_matrix_set_zero(X); yv = gsl_vector_alloc(max_samples); c = gsl_vector_alloc(n_vars); cov = gsl_matrix_alloc (n_vars, n_vars); @@ -157,25 +162,23 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, c1[0] < 200 && c1[1] < 200 && c1[2] < 200 && c2[0] < 200 && c2[1] < 200 && c2[2] < 200 && c1[0] > 20 && c1[1] > 20 && c1[2] > 20 && - c2[0] > 20 && c2[1] > 20 && c2[2] > 20 && - fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.01 && - fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.01 ) { + c2[0] > 20 && c2[1] > 20 && c2[2] > 20) { + // fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.01 && + // fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.01 ) { for (int l = 0; l<3; l++) { - gsl_matrix_set_zero(X); if (p1 == 0) { -fprintf(stderr, "==> p1 = 0 p2 = %d\n", p2); - // gsl_matrix_set(X, n_samples, (p2-1) * 9 + 3 * l + 2, c2d[l] * a2 *a2 * a2 * a2); - // gsl_matrix_set(X, n_samples, (p2-1) * 9 + 3 * l + 1, c2d[l] * a2 * a2); - gsl_matrix_set(X, n_samples, (p2-1) * 9 + 3 * l + 0, c2d[l]); + gsl_matrix_set(X, n_samples, var_offset(p2, l, 2), c2d[l] * a2 *a2 * a2 * a2); + gsl_matrix_set(X, n_samples, var_offset(p2, l, 1), c2d[l] * a2 * a2); + gsl_matrix_set(X, n_samples, var_offset(p2, l, 0), c2d[l]); gsl_vector_set(yv, n_samples, c1d[l]); } else { - // gsl_matrix_set(X, n_samples, (p1-1) * 9 + 3 * l + 2, - c1d[l] * a1 *a1 * a1 * a1); - // gsl_matrix_set(X, n_samples, (p2-1) * 9 + 3 * l + 2, c2d[l] * a2 * a2 * a2 * a2); - // gsl_matrix_set(X, n_samples, (p1-1) * 9 + 3 * l + 1, - c1d[l] * a1 * a1); - // gsl_matrix_set(X, n_samples, (p2-1) * 9 + 3 * l + 1, c2d[l] * a2 * a2); - gsl_matrix_set(X, n_samples, (p1-1) * 9 + 3 * l + 0, - c1d[l]); - gsl_matrix_set(X, n_samples, (p2-1) * 9 + 3 * l + 0, c2d[l]); + gsl_matrix_set(X, n_samples, var_offset(p1, l, 2), - c1d[l] * a1 *a1 * a1 * a1); + gsl_matrix_set(X, n_samples, var_offset(p2, l, 2), c2d[l] * a2 * a2 * a2 * a2); + gsl_matrix_set(X, n_samples, var_offset(p1, l, 1), - c1d[l] * a1 * a1); + gsl_matrix_set(X, n_samples, var_offset(p2, l, 1), c2d[l] * a2 * a2); + gsl_matrix_set(X, n_samples, var_offset(p1, l, 0), - c1d[l]); + gsl_matrix_set(X, n_samples, var_offset(p2, l, 0), c2d[l]); gsl_vector_set(yv, n_samples, 0.0); } n_samples++; @@ -206,7 +209,7 @@ fprintf(stderr, "==> p1 = 0 p2 = %d\n", p2); if (merged_image) { merged_image->done(); } -gsl_vector_fprintf(stderr, yv, "%f"); + gsl_multifit_linear_workspace * work = gsl_multifit_linear_alloc (n_samples, n_vars); @@ -223,10 +226,8 @@ gsl_vector_fprintf(stderr, yv, "%f"); color_adjust[p1][l][2] = 0.0; } else { for (int k = 0; k<3; k++) { - color_adjust[p1][l][k] = gsl_vector_get(c, (p1-1) * 9 + 3 * l + k); + color_adjust[p1][l][k] = gsl_vector_get(c, var_offset(p1, l, k)); } - color_adjust[p1][l][1] = 0.0; - color_adjust[p1][l][2] = 0.0; } } fprintf(stderr, "==> color_adjust(%d) %f %f %f\n", p1, color_adjust[p1][0][0], color_adjust[p1][1][0],color_adjust[p1][2][0]); -- cgit v1.2.3 From 8cba58d9aa6b4f92fe90231966f58ad0435f1d3f Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 16 Mar 2007 17:13:56 +0100 Subject: try other model --- src/Stitch.H | 3 ++- src/Stitch.cxx | 50 +++++++++++++++++++++++--------------------------- 2 files changed, 25 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/Stitch.H b/src/Stitch.H index 29f0ef3..9fe3c15 100644 --- a/src/Stitch.H +++ b/src/Stitch.H @@ -18,7 +18,8 @@ class Stitch { private: GipfelWidget *gipf[MAX_PICS]; int num_pics; - double color_adjust[MAX_PICS][3][3]; + double color_adjust[MAX_PICS][3]; + double V1, V2; OutputImage *single_images[MAX_PICS]; OutputImage *merged_image; diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 3bb39e9..b2053fe 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -87,8 +87,8 @@ Stitch::set_output(const char *file, OutputImage *img) { } static int -var_offset(int pic, int color, int pow) { - return 9 * (pic - 1) + 3 * color + pow; +var_offset(int pic, int color) { + return 2 + (pic - 1) * 3 + color; } int @@ -104,9 +104,9 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int merged_pixel_set; double radius = (double) w / (view_end -view_start); - int max_samples = 10000 * 3, n_samples = 0; + int max_samples = 5000 * 3, n_samples = 0; int ret; - int n_vars = (num_pics-1) * 9; + int n_vars = 2 + (num_pics-1) * 3 ; gsl_matrix *X, *cov; gsl_vector *yv, *c; double chisq; @@ -162,23 +162,23 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, c1[0] < 200 && c1[1] < 200 && c1[2] < 200 && c2[0] < 200 && c2[1] < 200 && c2[2] < 200 && c1[0] > 20 && c1[1] > 20 && c1[2] > 20 && - c2[0] > 20 && c2[1] > 20 && c2[2] > 20) { - // fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.01 && - // fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.01 ) { + c2[0] > 20 && c2[1] > 20 && c2[2] > 20 && + fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.02 && + fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.02 ) { for (int l = 0; l<3; l++) { - if (p1 == 0) { - gsl_matrix_set(X, n_samples, var_offset(p2, l, 2), c2d[l] * a2 *a2 * a2 * a2); - gsl_matrix_set(X, n_samples, var_offset(p2, l, 1), c2d[l] * a2 * a2); - gsl_matrix_set(X, n_samples, var_offset(p2, l, 0), c2d[l]); + if ( p1 == 0) { + gsl_matrix_set(X, n_samples, 0, c2d[l] * a2 * a2); + gsl_matrix_set(X, n_samples, 1, c2d[l] * a2 *a2 * a2 * a2); + gsl_matrix_set(X, n_samples, var_offset(p2, l), c2d[l]); gsl_vector_set(yv, n_samples, c1d[l]); } else { - gsl_matrix_set(X, n_samples, var_offset(p1, l, 2), - c1d[l] * a1 *a1 * a1 * a1); - gsl_matrix_set(X, n_samples, var_offset(p2, l, 2), c2d[l] * a2 * a2 * a2 * a2); - gsl_matrix_set(X, n_samples, var_offset(p1, l, 1), - c1d[l] * a1 * a1); - gsl_matrix_set(X, n_samples, var_offset(p2, l, 1), c2d[l] * a2 * a2); - gsl_matrix_set(X, n_samples, var_offset(p1, l, 0), - c1d[l]); - gsl_matrix_set(X, n_samples, var_offset(p2, l, 0), c2d[l]); + gsl_matrix_set(X, n_samples, 0, - c1d[l] * a1 * a1); + gsl_matrix_set(X, n_samples, 0, c2d[l] * a2 * a2); + gsl_matrix_set(X, n_samples, 1, - c1d[l] * a1 *a1 * a1 * a1); + gsl_matrix_set(X, n_samples, 1, c2d[l] * a2 * a2 * a2 * a2); + gsl_matrix_set(X, n_samples, var_offset(p1, l), - c1d[l]); + gsl_matrix_set(X, n_samples, var_offset(p2, l), c2d[l]); gsl_vector_set(yv, n_samples, 0.0); } n_samples++; @@ -221,16 +221,12 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, for (int p1=0; p1 < num_pics; p1++) { for (int l = 0; l<3; l++) { if (p1 == 0) { - color_adjust[p1][l][0] = 1.0; - color_adjust[p1][l][1] = 0.0; - color_adjust[p1][l][2] = 0.0; + color_adjust[p1][l] = 1.0; } else { - for (int k = 0; k<3; k++) { - color_adjust[p1][l][k] = gsl_vector_get(c, var_offset(p1, l, k)); - } + color_adjust[p1][l] = gsl_vector_get(c, var_offset(p1, l)); } } -fprintf(stderr, "==> color_adjust(%d) %f %f %f\n", p1, color_adjust[p1][0][0], color_adjust[p1][1][0],color_adjust[p1][2][0]); +fprintf(stderr, "==> color_adjust(%d) %f %f %f\n", p1, color_adjust[p1][0], color_adjust[p1][1],color_adjust[p1][2]); } return 0; @@ -241,9 +237,9 @@ Stitch::color_correct(uchar c, double a, int pic, int color) { double cd = (double) c; cd = cd * ( - color_adjust[pic][color][0] + - color_adjust[pic][color][1] * a * a + - color_adjust[pic][color][2] * a * a * a * a); + color_adjust[pic][color] + + V1 * a * a + + V2 * a * a * a * a); return (uchar) MIN(rint(cd), 255.0); } -- cgit v1.2.3 From 79dc410663f418ab36acd61fe53aeba8d5942705 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 16 Mar 2007 17:36:59 +0100 Subject: simple linear solution --- src/Stitch.cxx | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index b2053fe..3876e77 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -88,7 +88,7 @@ Stitch::set_output(const char *file, OutputImage *img) { static int var_offset(int pic, int color) { - return 2 + (pic - 1) * 3 + color; + return 2 + pic* 3 + color; } int @@ -106,7 +106,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int max_samples = 5000 * 3, n_samples = 0; int ret; - int n_vars = 2 + (num_pics-1) * 3 ; + int n_vars = 2 + num_pics * 3 ; gsl_matrix *X, *cov; gsl_vector *yv, *c; double chisq; @@ -167,20 +167,21 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.02 ) { for (int l = 0; l<3; l++) { - if ( p1 == 0) { - gsl_matrix_set(X, n_samples, 0, c2d[l] * a2 * a2); - gsl_matrix_set(X, n_samples, 1, c2d[l] * a2 *a2 * a2 * a2); - gsl_matrix_set(X, n_samples, var_offset(p2, l), c2d[l]); + if (p1 == 0) { + gsl_matrix_set(X, n_samples, 0, c1d[l] * a1 * a1); + gsl_matrix_set(X, n_samples, 1, c1d[l] * a1 *a1 * a1 * a1); + gsl_matrix_set(X, n_samples, var_offset(p1, l), c1d[l]); gsl_vector_set(yv, n_samples, c1d[l]); - } else { - gsl_matrix_set(X, n_samples, 0, - c1d[l] * a1 * a1); - gsl_matrix_set(X, n_samples, 0, c2d[l] * a2 * a2); - gsl_matrix_set(X, n_samples, 1, - c1d[l] * a1 *a1 * a1 * a1); - gsl_matrix_set(X, n_samples, 1, c2d[l] * a2 * a2 * a2 * a2); - gsl_matrix_set(X, n_samples, var_offset(p1, l), - c1d[l]); - gsl_matrix_set(X, n_samples, var_offset(p2, l), c2d[l]); - gsl_vector_set(yv, n_samples, 0.0); + n_samples++; } + + gsl_matrix_set(X, n_samples, 0, c1d[l] * a1 * a1); + gsl_matrix_set(X, n_samples, 0, - c2d[l] * a2 * a2); + gsl_matrix_set(X, n_samples, 1, c1d[l] * a1 *a1 * a1 * a1); + gsl_matrix_set(X, n_samples, 1, - c2d[l] * a2 * a2 * a2 * a2); + gsl_matrix_set(X, n_samples, var_offset(p1, l), c1d[l]); + gsl_matrix_set(X, n_samples, var_offset(p2, l), - c2d[l]); + gsl_vector_set(yv, n_samples, 0.0); n_samples++; } @@ -220,14 +221,14 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, for (int p1=0; p1 < num_pics; p1++) { for (int l = 0; l<3; l++) { - if (p1 == 0) { - color_adjust[p1][l] = 1.0; - } else { - color_adjust[p1][l] = gsl_vector_get(c, var_offset(p1, l)); - } + color_adjust[p1][l] = gsl_vector_get(c, var_offset(p1, l)); } fprintf(stderr, "==> color_adjust(%d) %f %f %f\n", p1, color_adjust[p1][0], color_adjust[p1][1],color_adjust[p1][2]); - } + } + + V1 = gsl_vector_get(c, 0); + V2 = gsl_vector_get(c, 1); +fprintf(stderr, "==> V1 %f V2 %f\n", V1, V2); return 0; } @@ -236,8 +237,7 @@ uchar Stitch::color_correct(uchar c, double a, int pic, int color) { double cd = (double) c; - cd = cd * ( - color_adjust[pic][color] + + cd = cd * (color_adjust[pic][color] + V1 * a * a + V2 * a * a * a * a); -- cgit v1.2.3 From d09316016e4e0b782d784785641fec91de7d58a6 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 16 Mar 2007 18:35:35 +0100 Subject: switch to 16 bit color depth internally --- src/GipfelWidget.H | 8 ++++---- src/GipfelWidget.cxx | 49 ++++++++++++++++++---------------------------- src/JPEGOutputImage.H | 2 +- src/JPEGOutputImage.cxx | 8 ++++---- src/OutputImage.H | 4 ++-- src/OutputImage.cxx | 4 ++-- src/PreviewOutputImage.H | 2 +- src/PreviewOutputImage.cxx | 8 ++++---- src/Stitch.H | 2 +- src/Stitch.cxx | 39 +++++++++++++++++++++--------------- src/TIFFOutputImage.H | 2 +- src/TIFFOutputImage.cxx | 8 ++++---- 12 files changed, 66 insertions(+), 70 deletions(-) (limited to 'src') diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index f5254e7..8cb6d3f 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -39,13 +39,13 @@ class GipfelWidget : public Fl_Widget { int get_rel_track_width(Hill *m); static int get_pixel_nearest(Fl_Image *img, double x, double y, - uchar *r, uchar *g, uchar *b); + int *r, int *g, int *b); static int get_pixel_bilinear(Fl_Image *img, double x, double y, - uchar *r, uchar *g, uchar *b); + int *r, int *g, int *b); static int get_pixel(Fl_Image *img, int x, int y, - uchar *r, uchar *g, uchar *b); + int *r, int *g, int *b); public: typedef enum { @@ -124,7 +124,7 @@ class GipfelWidget : public Fl_Widget { int comp_params(); int get_pixel(GipfelWidget::sample_mode_t, - double a_alph, double a_nick, uchar *r, uchar *g, uchar *b); + double a_alph, double a_nick, int *r, int *g, int *b); double get_angle_off(double view, double nick); diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index e88c0cb..1eb8866 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -670,9 +670,9 @@ GipfelWidget::handle(int event) { int GipfelWidget::get_pixel(GipfelWidget::sample_mode_t m, - double a_alph, double a_nick, uchar *r, uchar *g, uchar *b) { + double a_alph, double a_nick, int *r, int *g, int *b) { double px, py; - uchar r_tmp, g_tmp, b_tmp; + int r_tmp, g_tmp, b_tmp; int ret; if (img == NULL) { @@ -691,20 +691,6 @@ GipfelWidget::get_pixel(GipfelWidget::sample_mode_t m, py + ((double) img->h()) / 2.0, r, g, b); } -#if 0 - if (ret == 0) { -fprintf(stderr, "===> %d\n", ret); - double angle = atan(pow(pow(tan(a_alph - pan->parms.a_center), 2.0) + - pow(tan(a_nick - pan->parms.a_nick), 2.0), 0.5)); - double devign = 1.0 / pow(cos(angle), 1.5); - fprintf(stderr, "===> %lf\n", devign); - - *r = (uchar) MIN(rint((double) r_tmp * devign), 255); - *g = (uchar) MIN(rint((double) g_tmp * devign), 255); - *b = (uchar) MIN(rint((double) b_tmp * devign), 255); - } -#endif - return ret; } @@ -718,7 +704,7 @@ GipfelWidget::get_angle_off(double a_alph, double a_nick) { int GipfelWidget::get_pixel_nearest(Fl_Image *img, double x, double y, - uchar *r, uchar *g, uchar *b) { + int *r, int *g, int *b) { if (isnan(x) || isnan(y)) { return 1; } else { @@ -728,10 +714,10 @@ GipfelWidget::get_pixel_nearest(Fl_Image *img, double x, double y, int GipfelWidget::get_pixel_bilinear(Fl_Image *img, double x, double y, - uchar *r, uchar *g, uchar *b) { - uchar a_r[4] = {0, 0, 0, 0}; - uchar a_g[4] = {0, 0, 0, 0}; - uchar a_b[4] = {0, 0, 0, 0}; + int *r, int *g, int *b) { + int a_r[4] = {0, 0, 0, 0}; + int a_g[4] = {0, 0, 0, 0}; + int a_b[4] = {0, 0, 0, 0}; float v0 , v1; int fl_x = (int) floor(x); int fl_y = (int) floor(y); @@ -748,15 +734,15 @@ GipfelWidget::get_pixel_bilinear(Fl_Image *img, double x, double y, v0 = a_r[0] * (1 - (x - fl_x)) + a_r[1] * (x - fl_x); v1 = a_r[2] * (1 - (x - fl_x)) + a_r[3] * (x - fl_x); - *r = (uchar) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y)); + *r = (int) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y)); v0 = a_g[0] * (1 - (x - fl_x)) + a_g[1] * (x - fl_x); v1 = a_g[2] * (1 - (x - fl_x)) + a_g[3] * (x - fl_x); - *g = (uchar) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y)); + *g = (int) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y)); v0 = a_b[0] * (1 - (x - fl_x)) + a_b[1] * (x - fl_x); v1 = a_b[2] * (1 - (x - fl_x)) + a_b[3] * (x - fl_x); - *b = (uchar) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y)); + *b = (int) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y)); if (n >= 1) { return 1; @@ -767,7 +753,7 @@ GipfelWidget::get_pixel_bilinear(Fl_Image *img, double x, double y, int GipfelWidget::get_pixel(Fl_Image *img, int x, int y, - uchar *r, uchar *g, uchar *b) { + int *r, int *g, int *b) { if ( img->d() == 0 ) { return 1; } @@ -779,16 +765,16 @@ GipfelWidget::get_pixel(Fl_Image *img, int x, int y, switch (img->count()) { case 1: { // bitmap - const char *buf = img->data()[0]; + const unsigned char *buf = (const unsigned char*) img->data()[0]; switch (img->d()) { case 1: *r = *g = *b = *(buf+index); break; case 3: // 24bit - *r = *(buf+index+0); - *g = *(buf+index+1); - *b = *(buf+index+2); + *r = (int) *(buf+index+0); + *g = (int) *(buf+index+1); + *b = (int) *(buf+index+2); break; default: // ?? printf("Not supported: chans=%d\n", img->d()); @@ -801,8 +787,11 @@ GipfelWidget::get_pixel(Fl_Image *img, int x, int y, return 1; } - return 0; + *r = *r * 255; + *g = *g * 255; + *b = *b * 255; + return 0; } int diff --git a/src/JPEGOutputImage.H b/src/JPEGOutputImage.H index b3554c8..a4b8f47 100644 --- a/src/JPEGOutputImage.H +++ b/src/JPEGOutputImage.H @@ -32,7 +32,7 @@ class JPEGOutputImage : OutputImage { protected: int init_internal(int w, int h); - int set_pixel_internal(int x, char r, char g, char b); + int set_pixel_internal(int x, int r, int g, int b); int next_line_internal(); diff --git a/src/JPEGOutputImage.cxx b/src/JPEGOutputImage.cxx index 6e685d0..bfe4595 100644 --- a/src/JPEGOutputImage.cxx +++ b/src/JPEGOutputImage.cxx @@ -68,10 +68,10 @@ JPEGOutputImage::init_internal(int w1, int h1) { } int -JPEGOutputImage::set_pixel_internal(int x, char r, char g, char b) { - row[x*3+0] = r; - row[x*3+1] = g; - row[x*3+2] = b; +JPEGOutputImage::set_pixel_internal(int x, int r, int g, int b) { + row[x*3+0] = (unsigned char) r; + row[x*3+1] = (unsigned char) g; + row[x*3+2] = (unsigned char) b; return 0; } diff --git a/src/OutputImage.H b/src/OutputImage.H index 7c9f0fd..17955b9 100644 --- a/src/OutputImage.H +++ b/src/OutputImage.H @@ -19,7 +19,7 @@ class OutputImage { virtual int init(int w1, int h1); - int set_pixel(int x, char r, char g, char b); + int set_pixel(int x, int r, int g, int b); int next_line(); @@ -30,7 +30,7 @@ class OutputImage { virtual int init_internal(int w1, int h1); - virtual int set_pixel_internal(int x, char r, char g, char b); + virtual int set_pixel_internal(int x, int r, int g, int b); virtual int next_line_internal(); diff --git a/src/OutputImage.cxx b/src/OutputImage.cxx index ddf8e14..f981f18 100644 --- a/src/OutputImage.cxx +++ b/src/OutputImage.cxx @@ -35,7 +35,7 @@ OutputImage::init_internal(int w1, int h1) { } int -OutputImage::set_pixel(int x, char r, char g, char b) { +OutputImage::set_pixel(int x, int r, int g, int b) { if (!initialized || x < 0 || x >= W) { return 1; } else { @@ -44,7 +44,7 @@ OutputImage::set_pixel(int x, char r, char g, char b) { } int -OutputImage::set_pixel_internal(int x, char r, char g, char b) { +OutputImage::set_pixel_internal(int x, int r, int g, int b) { return 0; } diff --git a/src/PreviewOutputImage.H b/src/PreviewOutputImage.H index 8b41684..cbd55a6 100644 --- a/src/PreviewOutputImage.H +++ b/src/PreviewOutputImage.H @@ -29,7 +29,7 @@ class PreviewOutputImage : OutputImage , public Fl_Widget { protected: int init_internal(int w, int h); - int set_pixel_internal(int x, char r, char g, char b); + int set_pixel_internal(int x, int r, int g, int b); int next_line_internal(); diff --git a/src/PreviewOutputImage.cxx b/src/PreviewOutputImage.cxx index 86dadee..0ae182e 100644 --- a/src/PreviewOutputImage.cxx +++ b/src/PreviewOutputImage.cxx @@ -35,15 +35,15 @@ PreviewOutputImage::init_internal(int w, int h) { int -PreviewOutputImage::set_pixel_internal(int x, char r, char g, char b) { +PreviewOutputImage::set_pixel_internal(int x, int r, int g, int b) { if (!data) { return 1; } long index = (line * w() * d + (x * d)); - *(data+index+0) = r; - *(data+index+1) = g; - *(data+index+2) = b; + *(data+index+0) = (unsigned char) (r / 255); + *(data+index+1) = (unsigned char) (g / 255); + *(data+index+2) = (unsigned char) (b / 255); return 0; } diff --git a/src/Stitch.H b/src/Stitch.H index 9fe3c15..b5fb6fd 100644 --- a/src/Stitch.H +++ b/src/Stitch.H @@ -23,7 +23,7 @@ class Stitch { OutputImage *single_images[MAX_PICS]; OutputImage *merged_image; - uchar color_correct(uchar c, double a, int pic, int color); + int color_correct(int c, double a, int pic, int color); public: Stitch(); diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 3876e77..af0df91 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -17,7 +17,7 @@ #include "Stitch.H" #define MIN(A,B) ((A)<(B)?(A):(B)) - +#define MAX_VALUE 65025 static double pi_d = asin(1.0) * 2.0; static double deg2rad = pi_d / 180.0; @@ -99,12 +99,12 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, view_end = view_end * deg2rad; double step_view = (view_end - view_start) / w; - uchar r, g, b; + int r, g, b; int y_off = h / 2; int merged_pixel_set; double radius = (double) w / (view_end -view_start); - int max_samples = 5000 * 3, n_samples = 0; + int max_samples = 50000 * 3, n_samples = 0; int ret; int n_vars = 2 + num_pics * 3 ; gsl_matrix *X, *cov; @@ -129,7 +129,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, a_view = view_start + x * step_view; merged_pixel_set = 0; double a1, a2; - uchar c1[3], c2[3]; + int c1[3], c2[3]; double c1d[3], c2d[3]; for (int p1=0; p1get_pixel(m, a_view, a_nick, &c1[0], &c1[1], &c1[2]) == 0) { - for (int l = 0; l<3; l++) { c1d[l] = (double) c1[l]; } @@ -159,12 +158,20 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, a2 = gipf[p2]->get_angle_off(a_view, a_nick); if (n_samples < max_samples && - c1[0] < 200 && c1[1] < 200 && c1[2] < 200 && - c2[0] < 200 && c2[1] < 200 && c2[2] < 200 && - c1[0] > 20 && c1[1] > 20 && c1[2] > 20 && - c2[0] > 20 && c2[1] > 20 && c2[2] > 20 && - fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.02 && - fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.02 ) { + c1[0] < MAX_VALUE * 0.8 && + c1[1] < MAX_VALUE * 0.8 && + c1[2] < MAX_VALUE * 0.8 && + c2[0] < MAX_VALUE * 0.8 && + c2[1] < MAX_VALUE * 0.8 && + c2[2] < MAX_VALUE * 0.8 && + c1[0] > MAX_VALUE * 0.2 && + c1[1] > MAX_VALUE * 0.2 && + c1[2] > MAX_VALUE * 0.2 && + c2[0] > MAX_VALUE * 0.2 && + c2[1] > MAX_VALUE * 0.2 && + c2[2] > MAX_VALUE * 0.2) { +// fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.2 && +// fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.2 ) { for (int l = 0; l<3; l++) { if (p1 == 0) { @@ -186,7 +193,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, } if (merged_image) { - merged_image->set_pixel(x, 255, 0, 0); + merged_image->set_pixel(x, 65025, 0, 0); merged_pixel_set++; } } @@ -233,15 +240,15 @@ fprintf(stderr, "==> V1 %f V2 %f\n", V1, V2); return 0; } -uchar -Stitch::color_correct(uchar c, double a, int pic, int color) { +int +Stitch::color_correct(int c, double a, int pic, int color) { double cd = (double) c; cd = cd * (color_adjust[pic][color] + V1 * a * a + V2 * a * a * a * a); - return (uchar) MIN(rint(cd), 255.0); + return (int) MIN(rint(cd), 65025.0); } int @@ -252,7 +259,7 @@ Stitch::resample(GipfelWidget::sample_mode_t m, view_end = view_end * deg2rad; double step_view = (view_end - view_start) / w; - uchar r, g, b; + int r, g, b; int y_off = h / 2; int merged_pixel_set; double radius = (double) w / (view_end -view_start); diff --git a/src/TIFFOutputImage.H b/src/TIFFOutputImage.H index 820a281..ce61462 100644 --- a/src/TIFFOutputImage.H +++ b/src/TIFFOutputImage.H @@ -26,7 +26,7 @@ class TIFFOutputImage : OutputImage { protected: int init_internal(int w, int h); - int set_pixel_internal(int x, char r, char g, char b); + int set_pixel_internal(int x, int r, int g, int b); int next_line_internal(); diff --git a/src/TIFFOutputImage.cxx b/src/TIFFOutputImage.cxx index 397caac..4034c97 100644 --- a/src/TIFFOutputImage.cxx +++ b/src/TIFFOutputImage.cxx @@ -61,10 +61,10 @@ TIFFOutputImage::init_internal(int w1, int h1) { } int -TIFFOutputImage::set_pixel_internal(int x, char r, char g, char b) { - row[x*4+0] = r; - row[x*4+1] = g; - row[x*4+2] = b; +TIFFOutputImage::set_pixel_internal(int x, int r, int g, int b) { + row[x*4+0] = (unsigned char) r; + row[x*4+1] = (unsigned char) g; + row[x*4+2] = (unsigned char) b; row[x*4+3] = 255; return 0; -- cgit v1.2.3 From 000be35edac2639dcf16f245ac120c5937813139 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 16 Mar 2007 18:52:53 +0100 Subject: only vignetting correction for first image --- src/Stitch.cxx | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index af0df91..1635dd0 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -104,7 +104,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int merged_pixel_set; double radius = (double) w / (view_end -view_start); - int max_samples = 50000 * 3, n_samples = 0; + int max_samples = 10000 * 3, n_samples = 0; int ret; int n_vars = 2 + num_pics * 3 ; gsl_matrix *X, *cov; @@ -143,7 +143,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, a1 = gipf[p1]->get_angle_off(a_view, a_nick); - for (int p2=1; p2 MAX_VALUE * 0.2 && c2[0] > MAX_VALUE * 0.2 && c2[1] > MAX_VALUE * 0.2 && - c2[2] > MAX_VALUE * 0.2) { -// fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.2 && -// fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.2 ) { + c2[2] > MAX_VALUE * 0.2 && + fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.2 && + fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.2 ) { for (int l = 0; l<3; l++) { if (p1 == 0) { + // no color correction for first image + gsl_matrix_set(X, n_samples, 0, c1d[l] * a1 * a1); + gsl_matrix_set(X, n_samples, 1, c1d[l] * a1 *a1 * a1 * a1); + gsl_vector_set(yv, n_samples, -c1d[l]); + } else { gsl_matrix_set(X, n_samples, 0, c1d[l] * a1 * a1); gsl_matrix_set(X, n_samples, 1, c1d[l] * a1 *a1 * a1 * a1); gsl_matrix_set(X, n_samples, var_offset(p1, l), c1d[l]); - gsl_vector_set(yv, n_samples, c1d[l]); - n_samples++; + gsl_vector_set(yv, n_samples, 0.0); + } + if (p2 == 0) { + // no color correction for first image + gsl_matrix_set(X, n_samples, 0, -c2d[l] * a1 * a1); + gsl_matrix_set(X, n_samples, 1, -c2d[l] * a1 *a1 * a1 * a1); + gsl_vector_set(yv, n_samples, c2d[l]); + } else { + gsl_matrix_set(X, n_samples, 0, - c2d[l] * a2 * a2); + gsl_matrix_set(X, n_samples, 1, - c2d[l] * a2 * a2 * a2 * a2); + gsl_matrix_set(X, n_samples, var_offset(p2, l), - c2d[l]); } - - gsl_matrix_set(X, n_samples, 0, c1d[l] * a1 * a1); - gsl_matrix_set(X, n_samples, 0, - c2d[l] * a2 * a2); - gsl_matrix_set(X, n_samples, 1, c1d[l] * a1 *a1 * a1 * a1); - gsl_matrix_set(X, n_samples, 1, - c2d[l] * a2 * a2 * a2 * a2); - gsl_matrix_set(X, n_samples, var_offset(p1, l), c1d[l]); - gsl_matrix_set(X, n_samples, var_offset(p2, l), - c2d[l]); - gsl_vector_set(yv, n_samples, 0.0); n_samples++; } @@ -228,7 +234,11 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, for (int p1=0; p1 < num_pics; p1++) { for (int l = 0; l<3; l++) { - color_adjust[p1][l] = gsl_vector_get(c, var_offset(p1, l)); + if (p1 == 0) { + color_adjust[p1][l] = 1.0; + } else { + color_adjust[p1][l] = gsl_vector_get(c, var_offset(p1, l)); + } } fprintf(stderr, "==> color_adjust(%d) %f %f %f\n", p1, color_adjust[p1][0], color_adjust[p1][1],color_adjust[p1][2]); } -- cgit v1.2.3 From a3b7f7b06583d0e38db3cfc72386da7f48e4cdbf Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 16 Mar 2007 20:22:19 +0100 Subject: fix size of calibration image --- src/Stitch.cxx | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 1635dd0..db5d396 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -95,6 +95,9 @@ int Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end) { + w = 1500; + h = 400; + view_start = view_start * deg2rad; view_end = view_end * deg2rad; @@ -108,20 +111,20 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int ret; int n_vars = 2 + num_pics * 3 ; gsl_matrix *X, *cov; - gsl_vector *yv, *c; + gsl_vector *yv, *c, *wv; double chisq; - X = gsl_matrix_alloc(max_samples, n_vars); - gsl_matrix_set_zero(X); - yv = gsl_vector_alloc(max_samples); - c = gsl_vector_alloc(n_vars); - cov = gsl_matrix_alloc (n_vars, n_vars); + X = gsl_matrix_calloc(max_samples, n_vars); + yv = gsl_vector_calloc(max_samples); + wv = gsl_vector_calloc(max_samples); + c = gsl_vector_calloc(n_vars); + cov = gsl_matrix_calloc (n_vars, n_vars); if (merged_image) { merged_image->init(w, h); } - for (int y=0; yget_angle_off(a_view, a_nick); if (n_samples < max_samples && - c1[0] < MAX_VALUE * 0.8 && - c1[1] < MAX_VALUE * 0.8 && - c1[2] < MAX_VALUE * 0.8 && - c2[0] < MAX_VALUE * 0.8 && - c2[1] < MAX_VALUE * 0.8 && - c2[2] < MAX_VALUE * 0.8 && - c1[0] > MAX_VALUE * 0.2 && - c1[1] > MAX_VALUE * 0.2 && - c1[2] > MAX_VALUE * 0.2 && - c2[0] > MAX_VALUE * 0.2 && - c2[1] > MAX_VALUE * 0.2 && - c2[2] > MAX_VALUE * 0.2 && - fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.2 && - fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.2 ) { + c1[0] < MAX_VALUE * 0.9 && + c1[1] < MAX_VALUE * 0.9 && + c1[2] < MAX_VALUE * 0.9 && + c2[0] < MAX_VALUE * 0.9 && + c2[1] < MAX_VALUE * 0.9 && + c2[2] < MAX_VALUE * 0.9 && + c1[0] > MAX_VALUE * 0.1 && + c1[1] > MAX_VALUE * 0.1 && + c1[2] > MAX_VALUE * 0.1 && + c2[0] > MAX_VALUE * 0.1 && + c2[1] > MAX_VALUE * 0.1 && + c2[2] > MAX_VALUE * 0.1 && + fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.02 && + fabs(c1d[1] / c1d[2] - c2d[1] / c2d[2]) < 0.02 && + fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.02 ) { for (int l = 0; l<3; l++) { + gsl_vector_set(wv, n_samples, 1.0); if (p1 == 0) { // no color correction for first image gsl_matrix_set(X, n_samples, 0, c1d[l] * a1 * a1); @@ -225,9 +230,9 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, } gsl_multifit_linear_workspace * work - = gsl_multifit_linear_alloc (n_samples, n_vars); + = gsl_multifit_linear_alloc (max_samples, n_vars); - ret = gsl_multifit_linear (X, yv, c, cov, &chisq, work); + ret = gsl_multifit_wlinear (X, wv, yv, c, cov, &chisq, work); gsl_multifit_linear_free (work); fprintf(stderr, "gsl_multifit_linear returned %d\n", ret); -- cgit v1.2.3 From 40b830740a3670625b58ab2c64d4093e7b1d95d7 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 16 Mar 2007 20:35:48 +0100 Subject: adjust TIFF and JPEG output --- src/JPEGOutputImage.cxx | 6 +++--- src/TIFFOutputImage.cxx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/JPEGOutputImage.cxx b/src/JPEGOutputImage.cxx index bfe4595..0a5eb00 100644 --- a/src/JPEGOutputImage.cxx +++ b/src/JPEGOutputImage.cxx @@ -69,9 +69,9 @@ JPEGOutputImage::init_internal(int w1, int h1) { int JPEGOutputImage::set_pixel_internal(int x, int r, int g, int b) { - row[x*3+0] = (unsigned char) r; - row[x*3+1] = (unsigned char) g; - row[x*3+2] = (unsigned char) b; + row[x*3+0] = (unsigned char) (r / 255); + row[x*3+1] = (unsigned char) (g / 255); + row[x*3+2] = (unsigned char) (b / 255); return 0; } diff --git a/src/TIFFOutputImage.cxx b/src/TIFFOutputImage.cxx index 4034c97..156079c 100644 --- a/src/TIFFOutputImage.cxx +++ b/src/TIFFOutputImage.cxx @@ -62,9 +62,9 @@ TIFFOutputImage::init_internal(int w1, int h1) { int TIFFOutputImage::set_pixel_internal(int x, int r, int g, int b) { - row[x*4+0] = (unsigned char) r; - row[x*4+1] = (unsigned char) g; - row[x*4+2] = (unsigned char) b; + row[x*4+0] = (unsigned char) (r / 255); + row[x*4+1] = (unsigned char) (g / 255); + row[x*4+2] = (unsigned char) (b / 255); row[x*4+3] = 255; return 0; -- cgit v1.2.3 From 759799defe3e388bc9ec7255c79895138194e4fa Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sat, 17 Mar 2007 21:47:58 +0100 Subject: show sample points in separate window --- src/Stitch.cxx | 8 ++++---- src/gipfel.cxx | 14 +++++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index db5d396..7ed97a0 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -107,7 +107,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int merged_pixel_set; double radius = (double) w / (view_end -view_start); - int max_samples = 10000 * 3, n_samples = 0; + int max_samples = 20000 * 3, n_samples = 0; int ret; int n_vars = 2 + num_pics * 3 ; gsl_matrix *X, *cov; @@ -173,9 +173,9 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, c2[0] > MAX_VALUE * 0.1 && c2[1] > MAX_VALUE * 0.1 && c2[2] > MAX_VALUE * 0.1 && - fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.02 && - fabs(c1d[1] / c1d[2] - c2d[1] / c2d[2]) < 0.02 && - fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.02 ) { + fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.05 && + fabs(c1d[1] / c1d[2] - c2d[1] / c2d[2]) < 0.05 && + fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.05 ) { for (int l = 0; l<3; l++) { gsl_vector_set(wv, n_samples, 1.0); diff --git a/src/gipfel.cxx b/src/gipfel.cxx index e9743d8..410471d 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -569,6 +569,17 @@ stitch(GipfelWidget::sample_mode_t m, } + if (type & STITCH_VIGNETTE_CALIB) { + win = new Fl_Window(0,0, 1000, 400); + scroll = new Fl_Scroll(0, 0, win->w(), win->h()); + PreviewOutputImage *img = + new PreviewOutputImage(0, 0, 1000, 400); + + win->resizable(scroll); + win->show(0, argv); + st->set_output((OutputImage*) img); + st->vignette_calib(m, stitch_w, stitch_h, from, to); + } if (type & STITCH_JPEG) { st->set_output((OutputImage*) new JPEGOutputImage(path, 90)); @@ -600,9 +611,6 @@ stitch(GipfelWidget::sample_mode_t m, win->show(0, argv); st->set_output((OutputImage*) img); - if (type & STITCH_VIGNETTE_CALIB) { - st->vignette_calib(m, stitch_w, stitch_h, from, to); - } st->resample(m, stitch_w, stitch_h, from, to); img->redraw(); -- cgit v1.2.3 From e7eae5d58bff3d3339ce7ffcec59570590830fb9 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sat, 17 Mar 2007 21:52:54 +0100 Subject: vignetting correction only --- src/Stitch.cxx | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 7ed97a0..69d72be 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -109,7 +109,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int max_samples = 20000 * 3, n_samples = 0; int ret; - int n_vars = 2 + num_pics * 3 ; + int n_vars = 2 ; gsl_matrix *X, *cov; gsl_vector *yv, *c, *wv; double chisq; @@ -179,27 +179,12 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, for (int l = 0; l<3; l++) { gsl_vector_set(wv, n_samples, 1.0); - if (p1 == 0) { - // no color correction for first image - gsl_matrix_set(X, n_samples, 0, c1d[l] * a1 * a1); - gsl_matrix_set(X, n_samples, 1, c1d[l] * a1 *a1 * a1 * a1); - gsl_vector_set(yv, n_samples, -c1d[l]); - } else { - gsl_matrix_set(X, n_samples, 0, c1d[l] * a1 * a1); - gsl_matrix_set(X, n_samples, 1, c1d[l] * a1 *a1 * a1 * a1); - gsl_matrix_set(X, n_samples, var_offset(p1, l), c1d[l]); - gsl_vector_set(yv, n_samples, 0.0); - } - if (p2 == 0) { - // no color correction for first image - gsl_matrix_set(X, n_samples, 0, -c2d[l] * a1 * a1); - gsl_matrix_set(X, n_samples, 1, -c2d[l] * a1 *a1 * a1 * a1); - gsl_vector_set(yv, n_samples, c2d[l]); - } else { - gsl_matrix_set(X, n_samples, 0, - c2d[l] * a2 * a2); - gsl_matrix_set(X, n_samples, 1, - c2d[l] * a2 * a2 * a2 * a2); - gsl_matrix_set(X, n_samples, var_offset(p2, l), - c2d[l]); - } + gsl_matrix_set(X, n_samples, 0, c1d[l] * a1 * a1); + gsl_matrix_set(X, n_samples, 1, c1d[l] * a1 *a1 * a1 * a1); + gsl_matrix_set(X, n_samples, 0, -c2d[l] * a2 * a2); + gsl_matrix_set(X, n_samples, 1, -c2d[l] * a2 *a2 * a2 * a2); + + gsl_vector_set(yv, n_samples, c2d[l]-c1d[l]); n_samples++; } @@ -239,11 +224,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, for (int p1=0; p1 < num_pics; p1++) { for (int l = 0; l<3; l++) { - if (p1 == 0) { - color_adjust[p1][l] = 1.0; - } else { - color_adjust[p1][l] = gsl_vector_get(c, var_offset(p1, l)); - } + color_adjust[p1][l] = 1.0; } fprintf(stderr, "==> color_adjust(%d) %f %f %f\n", p1, color_adjust[p1][0], color_adjust[p1][1],color_adjust[p1][2]); } -- cgit v1.2.3 From 18ace785b31de59e5d60eb4507e4e991027ec795 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sat, 17 Mar 2007 21:54:28 +0100 Subject: correct vignetting + color correction case --- src/Stitch.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 7ed97a0..2ed72fe 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -192,8 +192,8 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, } if (p2 == 0) { // no color correction for first image - gsl_matrix_set(X, n_samples, 0, -c2d[l] * a1 * a1); - gsl_matrix_set(X, n_samples, 1, -c2d[l] * a1 *a1 * a1 * a1); + gsl_matrix_set(X, n_samples, 0, -c2d[l] * a2 * a2); + gsl_matrix_set(X, n_samples, 1, -c2d[l] * a2 *a2 * a2 * a2); gsl_vector_set(yv, n_samples, c2d[l]); } else { gsl_matrix_set(X, n_samples, 0, - c2d[l] * a2 * a2); -- cgit v1.2.3 From ad1abce7a41bdb5f6d2005ac63f6e8b5599ec244 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sun, 18 Mar 2007 12:21:29 +0100 Subject: remove color adjust stuff --- src/Stitch.H | 1 - src/Stitch.cxx | 11 +---------- 2 files changed, 1 insertion(+), 11 deletions(-) (limited to 'src') diff --git a/src/Stitch.H b/src/Stitch.H index b5fb6fd..7a47cf6 100644 --- a/src/Stitch.H +++ b/src/Stitch.H @@ -18,7 +18,6 @@ class Stitch { private: GipfelWidget *gipf[MAX_PICS]; int num_pics; - double color_adjust[MAX_PICS][3]; double V1, V2; OutputImage *single_images[MAX_PICS]; OutputImage *merged_image; diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 69d72be..c0a770b 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -220,15 +220,6 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, ret = gsl_multifit_wlinear (X, wv, yv, c, cov, &chisq, work); gsl_multifit_linear_free (work); - fprintf(stderr, "gsl_multifit_linear returned %d\n", ret); - - for (int p1=0; p1 < num_pics; p1++) { - for (int l = 0; l<3; l++) { - color_adjust[p1][l] = 1.0; - } -fprintf(stderr, "==> color_adjust(%d) %f %f %f\n", p1, color_adjust[p1][0], color_adjust[p1][1],color_adjust[p1][2]); - } - V1 = gsl_vector_get(c, 0); V2 = gsl_vector_get(c, 1); fprintf(stderr, "==> V1 %f V2 %f\n", V1, V2); @@ -240,7 +231,7 @@ int Stitch::color_correct(int c, double a, int pic, int color) { double cd = (double) c; - cd = cd * (color_adjust[pic][color] + + cd = cd * (1.0 + V1 * a * a + V2 * a * a * a * a); -- cgit v1.2.3 From 5432343cc8bd34a77a1584be33abbd53cdd6e373 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sun, 18 Mar 2007 12:22:50 +0100 Subject: implement bicubic interpolation --- src/GipfelWidget.H | 6 +++++- src/GipfelWidget.cxx | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/gipfel.cxx | 2 +- 3 files changed, 56 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index 8cb6d3f..ed251ef 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -44,13 +44,17 @@ class GipfelWidget : public Fl_Widget { static int get_pixel_bilinear(Fl_Image *img, double x, double y, int *r, int *g, int *b); + static int get_pixel_bicubic(Fl_Image *img, double x, double y, + int *r, int *g, int *b); + static int get_pixel(Fl_Image *img, int x, int y, int *r, int *g, int *b); public: typedef enum { NEAREST = 0, - BILINEAR = 1 + BILINEAR = 1, + BICUBIC = 2 } sample_mode_t; GipfelWidget(int X,int Y,int W, int H); diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index 1eb8866..2daea2a 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -686,6 +686,9 @@ GipfelWidget::get_pixel(GipfelWidget::sample_mode_t m, if (m == GipfelWidget::BILINEAR) { ret = get_pixel_bilinear(img, px + ((double) img->w()) / 2.0, py + ((double) img->h()) / 2.0, r, g, b); + } else if (m == GipfelWidget::BICUBIC) { + ret = get_pixel_bicubic(img, px + ((double) img->w()) / 2.0, + py + ((double) img->h()) / 2.0, r, g, b); } else { ret = get_pixel_nearest(img, px + ((double) img->w()) / 2.0, py + ((double) img->h()) / 2.0, r, g, b); @@ -751,6 +754,53 @@ GipfelWidget::get_pixel_bilinear(Fl_Image *img, double x, double y, } } +static double +interp_cubic(double x, double *v) { + double a0, a1, a2, a3; + double x2 = x * x; + + a0 = v[3] - v[2] - v[0] + v[1]; + a1 = v[0] - v[1] - a0; + a2 = v[2] - v[0]; + a3 = v[1]; + + return a0 * x * x2 +a1 * x2 + a2 * x + a3; +} + +int +GipfelWidget::get_pixel_bicubic(Fl_Image *img, double x, double y, + int *r, int *g, int *b) { + + int fl_x = (int) rint(x); + int fl_y = (int) rint(y); + int ic[3]; + double c[3][4]; + double c1[3][4]; + + for (int iy = 0; iy < 4; iy++) { + for (int ix = 0; ix < 4; ix++) { + if (get_pixel(img, fl_x + ix - 2, fl_y + iy - 2, + &ic[0], &ic[1], &ic[2]) != 0) { + return 1; + } + + for (int l = 0; l < 3; l++) { + c[l][ix] = (double) ic[l]; + } + } + + for (int l = 0; l < 3; l++) { + c1[l][iy] = interp_cubic(x - fl_x, c[l]); + } + } + + *r = (int) rint(interp_cubic(x - fl_x, c1[0])); + *g = (int) rint(interp_cubic(x - fl_x, c1[1])); + *b = (int) rint(interp_cubic(x - fl_x, c1[2])); + + return 0; +} + int GipfelWidget::get_pixel(Fl_Image *img, int x, int y, int *r, int *g, int *b) { diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 410471d..8620641 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -497,7 +497,7 @@ int main(int argc, char** argv) { type |= STITCH_VIGNETTE_CALIB; } - stitch(bilinear_flag?GipfelWidget::BILINEAR:GipfelWidget::NEAREST, + stitch(bilinear_flag?GipfelWidget::BICUBIC:GipfelWidget::NEAREST, stitch_w, stitch_h, stitch_from, stitch_to, type, outpath, my_argc, my_argv); -- cgit v1.2.3 From eba7fcd8f7f91f7076ee291438d86545fdb9856d Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sun, 18 Mar 2007 13:15:43 +0100 Subject: remove bilinear interpolation --- src/GipfelWidget.H | 6 +---- src/GipfelWidget.cxx | 67 ++++++++++------------------------------------------ 2 files changed, 14 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index ed251ef..0ddfbef 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -41,9 +41,6 @@ class GipfelWidget : public Fl_Widget { static int get_pixel_nearest(Fl_Image *img, double x, double y, int *r, int *g, int *b); - static int get_pixel_bilinear(Fl_Image *img, double x, double y, - int *r, int *g, int *b); - static int get_pixel_bicubic(Fl_Image *img, double x, double y, int *r, int *g, int *b); @@ -53,8 +50,7 @@ class GipfelWidget : public Fl_Widget { public: typedef enum { NEAREST = 0, - BILINEAR = 1, - BICUBIC = 2 + BICUBIC = 1 } sample_mode_t; GipfelWidget(int X,int Y,int W, int H); diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index 2daea2a..73be7e2 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -683,10 +683,7 @@ GipfelWidget::get_pixel(GipfelWidget::sample_mode_t m, return 1; } - if (m == GipfelWidget::BILINEAR) { - ret = get_pixel_bilinear(img, px + ((double) img->w()) / 2.0, - py + ((double) img->h()) / 2.0, r, g, b); - } else if (m == GipfelWidget::BICUBIC) { + if (m == GipfelWidget::BICUBIC) { ret = get_pixel_bicubic(img, px + ((double) img->w()) / 2.0, py + ((double) img->h()) / 2.0, r, g, b); } else { @@ -715,71 +712,33 @@ GipfelWidget::get_pixel_nearest(Fl_Image *img, double x, double y, } } -int -GipfelWidget::get_pixel_bilinear(Fl_Image *img, double x, double y, - int *r, int *g, int *b) { - int a_r[4] = {0, 0, 0, 0}; - int a_g[4] = {0, 0, 0, 0}; - int a_b[4] = {0, 0, 0, 0}; - float v0 , v1; - int fl_x = (int) floor(x); - int fl_y = (int) floor(y); - int i, n; - - i = 0; - n = 0; - for (int iy = 0; iy <= 1; iy++) { - for (int ix = 0; ix <= 1; ix++) { - n += get_pixel(img, fl_x + ix, fl_y + iy, &(a_r[i]), &(a_g[i]), &(a_b[i])); - i++; - } - } - - v0 = a_r[0] * (1 - (x - fl_x)) + a_r[1] * (x - fl_x); - v1 = a_r[2] * (1 - (x - fl_x)) + a_r[3] * (x - fl_x); - *r = (int) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y)); - - v0 = a_g[0] * (1 - (x - fl_x)) + a_g[1] * (x - fl_x); - v1 = a_g[2] * (1 - (x - fl_x)) + a_g[3] * (x - fl_x); - *g = (int) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y)); - - v0 = a_b[0] * (1 - (x - fl_x)) + a_b[1] * (x - fl_x); - v1 = a_b[2] * (1 - (x - fl_x)) + a_b[3] * (x - fl_x); - *b = (int) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y)); - - if (n >= 1) { - return 1; - } else { - return 0; - } -} - -static double -interp_cubic(double x, double *v) { +static inline double +interp_cubic(double x, double x2, double x3, double *v) { double a0, a1, a2, a3; - double x2 = x * x; a0 = v[3] - v[2] - v[0] + v[1]; a1 = v[0] - v[1] - a0; a2 = v[2] - v[0]; a3 = v[1]; - return a0 * x * x2 +a1 * x2 + a2 * x + a3; + return a0 * x3 + a1 * x2 + a2 * x + a3; } int GipfelWidget::get_pixel_bicubic(Fl_Image *img, double x, double y, int *r, int *g, int *b) { - int fl_x = (int) rint(x); - int fl_y = (int) rint(y); + double fl_x = floor(x); + double fl_y = floor(y); + double dx = x - fl_x, dx2 = dx * dx, dx3 = dx2 * dx; + double dy = y - fl_y, dy2 = dy * dy, dy3 = dy2 * dy; int ic[3]; double c[3][4]; double c1[3][4]; for (int iy = 0; iy < 4; iy++) { for (int ix = 0; ix < 4; ix++) { - if (get_pixel(img, fl_x + ix - 2, fl_y + iy - 2, + if (get_pixel(img, (int) fl_x + ix, (int) fl_y + iy, &ic[0], &ic[1], &ic[2]) != 0) { return 1; } @@ -790,13 +749,13 @@ GipfelWidget::get_pixel_bicubic(Fl_Image *img, double x, double y, } for (int l = 0; l < 3; l++) { - c1[l][iy] = interp_cubic(x - fl_x, c[l]); + c1[l][iy] = interp_cubic(dx, dx2, dx3, c[l]); } } - *r = (int) rint(interp_cubic(x - fl_x, c1[0])); - *g = (int) rint(interp_cubic(x - fl_x, c1[1])); - *b = (int) rint(interp_cubic(x - fl_x, c1[2])); + *r = (int) rint(interp_cubic(dy, dy2, dy3, c1[0])); + *g = (int) rint(interp_cubic(dy, dy2, dy3, c1[1])); + *b = (int) rint(interp_cubic(dy, dy2, dy3, c1[2])); return 0; } -- cgit v1.2.3 From d7696768c7c89442e4a65ba089401bf2d3b619c6 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sun, 18 Mar 2007 13:26:50 +0100 Subject: limit color values --- src/Stitch.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index c0a770b..23558ef 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -17,6 +17,7 @@ #include "Stitch.H" #define MIN(A,B) ((A)<(B)?(A):(B)) +#define MAX(A,B) ((A)>(B)?(A):(B)) #define MAX_VALUE 65025 static double pi_d = asin(1.0) * 2.0; @@ -235,7 +236,7 @@ Stitch::color_correct(int c, double a, int pic, int color) { V1 * a * a + V2 * a * a * a * a); - return (int) MIN(rint(cd), 65025.0); + return MAX(MIN((int) rint(cd), 65025), 0); } int -- cgit v1.2.3 From c169dc1ef87458680a71c5616d9f930e2e4560e0 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sun, 18 Mar 2007 13:29:24 +0100 Subject: fix bicubic --- src/GipfelWidget.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index 73be7e2..c8a2fae 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -738,7 +738,7 @@ GipfelWidget::get_pixel_bicubic(Fl_Image *img, double x, double y, for (int iy = 0; iy < 4; iy++) { for (int ix = 0; ix < 4; ix++) { - if (get_pixel(img, (int) fl_x + ix, (int) fl_y + iy, + if (get_pixel(img, (int) fl_x + ix - 1, (int) fl_y + iy - 1, &ic[0], &ic[1], &ic[2]) != 0) { return 1; } -- cgit v1.2.3 From 16be964c674ef4735e9ed925b78ac06a262c389d Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sun, 18 Mar 2007 14:20:57 +0100 Subject: bilinear->bicubic --- src/gipfel.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 8620641..8ef6b22 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -398,7 +398,7 @@ int main(int argc, char** argv) { int err, my_argc; int stitch_flag = 0, stitch_w = 2000, stitch_h = 500; int jpeg_flag = 0, tiff_flag = 0, distortion_flag = 0; - int bilinear_flag = 0, vignette_flag = 0; + int bicubic_flag = 0, vignette_flag = 0; double stitch_from = 0.0, stitch_to = 380.0; double dist_k0 = 0.0, dist_k1 = 0.0, dist_x0 = 0.0; char *outpath = "/tmp"; @@ -463,7 +463,7 @@ int main(int argc, char** argv) { stitch_h = atoi(optarg); break; case 'b': - bilinear_flag++; + bicubic_flag++; break; default: err++; @@ -497,7 +497,7 @@ int main(int argc, char** argv) { type |= STITCH_VIGNETTE_CALIB; } - stitch(bilinear_flag?GipfelWidget::BICUBIC:GipfelWidget::NEAREST, + stitch(bicubic_flag?GipfelWidget::BICUBIC:GipfelWidget::NEAREST, stitch_w, stitch_h, stitch_from, stitch_to, type, outpath, my_argc, my_argv); -- cgit v1.2.3 From 0d68eea574e7ce89497f59a5ac0333da60851d81 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 19 Mar 2007 17:19:57 +0100 Subject: cleanup and tune vignetting correction --- src/Stitch.cxx | 58 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 23558ef..1237581 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -92,6 +92,24 @@ var_offset(int pic, int color) { return 2 + pic* 3 + color; } +static int +similar_color(double *c1, double *c2) { + for (int i=0; i<3; i++) { + if (c1[i] > MAX_VALUE * 0.9 || c1[i] < MAX_VALUE * 0.1 || + c2[i] > MAX_VALUE * 0.9 || c2[i] < MAX_VALUE * 0.1) { + return 0; + } + } + + if (fabs(c1[1] / c1[0] - c2[1] / c2[0]) < 0.05 && + fabs(c1[1] / c1[2] - c2[1] / c2[2]) < 0.05 && + fabs(c1[2] / c1[0] - c2[2] / c2[0]) < 0.05 ) { + return 1; + } else { + return 0; + } +} + int Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end) { @@ -112,12 +130,11 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int ret; int n_vars = 2 ; gsl_matrix *X, *cov; - gsl_vector *yv, *c, *wv; + gsl_vector *yv, *c; double chisq; X = gsl_matrix_calloc(max_samples, n_vars); yv = gsl_vector_calloc(max_samples); - wv = gsl_vector_calloc(max_samples); c = gsl_vector_calloc(n_vars); cov = gsl_matrix_calloc (n_vars, n_vars); @@ -159,31 +176,16 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, c2d[l] = (double) c2[l]; } - a2 = gipf[p2]->get_angle_off(a_view, a_nick); + a2 = pow(cos(gipf[p2]->get_angle_off(a_view, a_nick)), 4.0); if (n_samples < max_samples && - c1[0] < MAX_VALUE * 0.9 && - c1[1] < MAX_VALUE * 0.9 && - c1[2] < MAX_VALUE * 0.9 && - c2[0] < MAX_VALUE * 0.9 && - c2[1] < MAX_VALUE * 0.9 && - c2[2] < MAX_VALUE * 0.9 && - c1[0] > MAX_VALUE * 0.1 && - c1[1] > MAX_VALUE * 0.1 && - c1[2] > MAX_VALUE * 0.1 && - c2[0] > MAX_VALUE * 0.1 && - c2[1] > MAX_VALUE * 0.1 && - c2[2] > MAX_VALUE * 0.1 && - fabs(c1d[1] / c1d[0] - c2d[1] / c2d[0]) < 0.05 && - fabs(c1d[1] / c1d[2] - c2d[1] / c2d[2]) < 0.05 && - fabs(c1d[2] / c1d[0] - c2d[2] / c2d[0]) < 0.05 ) { + similar_color(c1d, c2d)) { for (int l = 0; l<3; l++) { - gsl_vector_set(wv, n_samples, 1.0); - gsl_matrix_set(X, n_samples, 0, c1d[l] * a1 * a1); - gsl_matrix_set(X, n_samples, 1, c1d[l] * a1 *a1 * a1 * a1); - gsl_matrix_set(X, n_samples, 0, -c2d[l] * a2 * a2); - gsl_matrix_set(X, n_samples, 1, -c2d[l] * a2 *a2 * a2 * a2); + gsl_matrix_set(X, n_samples, 0, c1d[l] * a1); + gsl_matrix_set(X, n_samples, 1, c1d[l] * a1 * a1); + gsl_matrix_set(X, n_samples, 0, -c2d[l] * a2); + gsl_matrix_set(X, n_samples, 1, -c2d[l] * a2 * a2); gsl_vector_set(yv, n_samples, c2d[l]-c1d[l]); n_samples++; @@ -218,12 +220,12 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, gsl_multifit_linear_workspace * work = gsl_multifit_linear_alloc (max_samples, n_vars); - ret = gsl_multifit_wlinear (X, wv, yv, c, cov, &chisq, work); + ret = gsl_multifit_linear (X, yv, c, cov, &chisq, work); gsl_multifit_linear_free (work); V1 = gsl_vector_get(c, 0); V2 = gsl_vector_get(c, 1); -fprintf(stderr, "==> V1 %f V2 %f\n", V1, V2); + fprintf(stderr, "==> V1 %f V2 %f\n", V1, V2); return 0; } @@ -232,9 +234,7 @@ int Stitch::color_correct(int c, double a, int pic, int color) { double cd = (double) c; - cd = cd * (1.0 + - V1 * a * a + - V2 * a * a * a * a); + cd = cd * (1.0 + V1 * a + V2 * a * a); return MAX(MIN((int) rint(cd), 65025), 0); } @@ -274,7 +274,7 @@ Stitch::resample(GipfelWidget::sample_mode_t m, break; } else if (gipf[i]->get_pixel(m, a_view, a_nick, &r, &g, &b) == 0) { - double a = gipf[i]->get_angle_off(a_view, a_nick); + double a = pow(cos(gipf[i]->get_angle_off(a_view, a_nick)), 4.0); r = color_correct(r, a, i, 0); g = color_correct(g, a, i, 1); -- cgit v1.2.3 From decb030e4bd48c581d7cb7ae33e2b4d56b24c927 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 19 Mar 2007 17:20:39 +0100 Subject: update copyright year --- src/Stitch.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 1237581..47e9667 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -1,5 +1,5 @@ // -// Copyright 2006 Johannes Hofmann +// Copyright 2007 Johannes Hofmann // // This software may be used and distributed according to the terms // of the GNU General Public License, incorporated herein by reference. -- cgit v1.2.3 From 5457c660336a7f9bc74bdf85ab4e001a4f81a6f9 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 19 Mar 2007 18:04:49 +0100 Subject: further refactoring --- src/Stitch.H | 6 ++++++ src/Stitch.cxx | 58 ++++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 44 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/Stitch.H b/src/Stitch.H index 7a47cf6..b2913aa 100644 --- a/src/Stitch.H +++ b/src/Stitch.H @@ -19,11 +19,17 @@ class Stitch { GipfelWidget *gipf[MAX_PICS]; int num_pics; double V1, V2; + double color_adjust[MAX_PICS][3]; OutputImage *single_images[MAX_PICS]; OutputImage *merged_image; + double vignetting_parameter(int pic, double a_view, double a_nick); + int color_correct(int c, double a, int pic, int color); + int get_pixel(GipfelWidget::sample_mode_t m, int pic, + double a_view, double a_nick, int *r, int *g, int *b); + public: Stitch(); diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 47e9667..1da565b 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -27,10 +27,14 @@ Stitch::Stitch() { for (int i=0; iget_angle_off(a_view, a_nick)), 4.0); +} + int Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end) { @@ -121,7 +130,6 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, view_end = view_end * deg2rad; double step_view = (view_end - view_start) / w; - int r, g, b; int y_off = h / 2; int merged_pixel_set; double radius = (double) w / (view_end -view_start); @@ -149,45 +157,43 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, double a_view; a_view = view_start + x * step_view; merged_pixel_set = 0; - double a1, a2; int c1[3], c2[3]; double c1d[3], c2d[3]; for (int p1=0; p1get_pixel(m, a_view, a_nick, + } else if (get_pixel(m, p1, a_view, a_nick, &c1[0], &c1[1], &c1[2]) == 0) { + for (int l = 0; l<3; l++) { c1d[l] = (double) c1[l]; } - a1 = gipf[p1]->get_angle_off(a_view, a_nick); + double a1 = vignetting_parameter(p1, a_view, a_nick); + + for (int p2 = p1 + 1; p2 < num_pics; p2++) { - for (int p2=0; p2get_pixel(m, a_view, a_nick, + if (get_pixel(m, p2, a_view, a_nick, &c2[0], &c2[1], &c2[2]) == 0) { for (int l = 0; l<3; l++) { c2d[l] = (double) c2[l]; } - a2 = pow(cos(gipf[p2]->get_angle_off(a_view, a_nick)), 4.0); if (n_samples < max_samples && similar_color(c1d, c2d)) { + double a2 = vignetting_parameter(p2, a_view, a_nick); + for (int l = 0; l<3; l++) { gsl_matrix_set(X, n_samples, 0, c1d[l] * a1); gsl_matrix_set(X, n_samples, 1, c1d[l] * a1 * a1); gsl_matrix_set(X, n_samples, 0, -c2d[l] * a2); gsl_matrix_set(X, n_samples, 1, -c2d[l] * a2 * a2); - gsl_vector_set(yv, n_samples, c2d[l]-c1d[l]); + gsl_vector_set(yv, n_samples, c2d[l] - c1d[l]); n_samples++; } @@ -234,11 +240,28 @@ int Stitch::color_correct(int c, double a, int pic, int color) { double cd = (double) c; - cd = cd * (1.0 + V1 * a + V2 * a * a); + cd = cd * color_adjust[pic][color] * (1.0 + V1 * a + V2 * a * a); return MAX(MIN((int) rint(cd), 65025), 0); } +int +Stitch::get_pixel(GipfelWidget::sample_mode_t m, int pic, + double a_view, double a_nick, int *r, int *g, int *b) { + + if (gipf[pic]->get_pixel(m, a_view, a_nick, r, g, b) != 0) { + return 1; + } + + double a = vignetting_parameter(pic, a_view, a_nick); + + *r = color_correct(*r, a, pic, 0); + *g = color_correct(*g, a, pic, 1); + *b = color_correct(*b, a, pic, 2); + + return 0; +} + int Stitch::resample(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end) { @@ -272,13 +295,8 @@ Stitch::resample(GipfelWidget::sample_mode_t m, for (int i=0; iget_pixel(m, a_view, a_nick, + } else if (get_pixel(m, i, a_view, a_nick, &r, &g, &b) == 0) { - double a = pow(cos(gipf[i]->get_angle_off(a_view, a_nick)), 4.0); - - r = color_correct(r, a, i, 0); - g = color_correct(g, a, i, 1); - b = color_correct(b, a, i, 2); if (single_images[i]) { single_images[i]->set_pixel(x, r, g, b); -- cgit v1.2.3 From 731d704f7681a09c98e0494f6ea6297892045fb7 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 19 Mar 2007 18:07:23 +0100 Subject: remove unneeded check --- src/Stitch.cxx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 1da565b..11ee274 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -31,6 +31,7 @@ Stitch::Stitch() { color_adjust[i][l] = 1.0; } } + merged_image = NULL; num_pics = 0; V1 = 0.0; @@ -150,20 +151,18 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, merged_image->init(w, h); } - for (int y=0; y Date: Mon, 19 Mar 2007 18:11:02 +0100 Subject: remove unneeded check --- src/Stitch.cxx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 11ee274..c099a72 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -277,24 +277,23 @@ Stitch::resample(GipfelWidget::sample_mode_t m, if (merged_image) { merged_image->init(w, h); } + for (int i=0; iinit(w, h); } } - for (int y=0; y Date: Mon, 19 Mar 2007 18:52:45 +0100 Subject: implement color correction --- src/Stitch.H | 3 ++ src/Stitch.cxx | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/gipfel.cxx | 1 + 3 files changed, 128 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Stitch.H b/src/Stitch.H index b2913aa..cd8d7d4 100644 --- a/src/Stitch.H +++ b/src/Stitch.H @@ -46,6 +46,9 @@ class Stitch { int vignette_calib(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end); + + int color_calib(GipfelWidget::sample_mode_t m, + int w, int h, double view_start, double view_end); }; #endif diff --git a/src/Stitch.cxx b/src/Stitch.cxx index c099a72..a6c54ce 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -92,10 +92,6 @@ Stitch::set_output(const char *file, OutputImage *img) { return ret; } -static int -var_offset(int pic, int color) { - return 2 + pic* 3 + color; -} static int similar_color(double *c1, double *c2) { @@ -115,6 +111,130 @@ similar_color(double *c1, double *c2) { } } +static int +var_offset(int pic, int color) { + return (pic - 1) * 3 + color; +} + +int +Stitch::color_calib(GipfelWidget::sample_mode_t m, + int w, int h, double view_start, double view_end) { + + w = 1500; + h = 400; + + view_start = view_start * deg2rad; + view_end = view_end * deg2rad; + + double step_view = (view_end - view_start) / w; + int y_off = h / 2; + int merged_pixel_set; + double radius = (double) w / (view_end -view_start); + + int max_samples = 20000 * 3, n_samples = 0; + int ret; + int n_vars = (num_pics - 1) * 3; + gsl_matrix *X, *cov; + gsl_vector *yv, *c; + double chisq; + + X = gsl_matrix_calloc(max_samples, n_vars); + yv = gsl_vector_calloc(max_samples); + c = gsl_vector_calloc(n_vars); + cov = gsl_matrix_calloc (n_vars, n_vars); + + if (merged_image) { + merged_image->init(w, h); + } + + for (int y = 0; y < h; y++) { + double a_nick = atan((double)(y_off - y)/radius); + + for (int x = 0; x < w; x++) { + double a_view; + a_view = view_start + x * step_view; + merged_pixel_set = 0; + int c1[3], c2[3]; + double c1d[3], c2d[3]; + + for (int p1 = 0; p1 < num_pics; p1++) { + if (get_pixel(m, p1, a_view, a_nick, + &c1[0], &c1[1], &c1[2]) == 0) { + + for (int l = 0; l<3; l++) { + c1d[l] = (double) c1[l]; + } + + for (int p2 = p1 + 1; p2 < num_pics; p2++) { + + if (get_pixel(m, p2, a_view, a_nick, + &c2[0], &c2[1], &c2[2]) == 0) { + + for (int l = 0; l<3; l++) { + c2d[l] = (double) c2[l]; + } + + + if (n_samples < max_samples && + similar_color(c1d, c2d)) { + + for (int l = 0; l<3; l++) { + if (p1 == 0) { + gsl_matrix_set(X, n_samples, var_offset(p2, l), c2d[l]); + + gsl_vector_set(yv, n_samples, c1d[l]); + } else { + gsl_matrix_set(X, n_samples, var_offset(p1, l), c1d[l]); + gsl_matrix_set(X, n_samples, var_offset(p2, l), -c2d[l]); + + gsl_vector_set(yv, n_samples, 0.0); + } + n_samples++; + } + + if (merged_image) { + merged_image->set_pixel(x, 0, 0, 65025); + merged_pixel_set++; + } + } + + } + } + + if (!merged_pixel_set && merged_image) { + merged_image->set_pixel(x, c1[0], c1[1], c1[2]); + merged_pixel_set++; + } + + } + } + } + if (merged_image) { + merged_image->next_line(); + } + } + + if (merged_image) { + merged_image->done(); + } + + gsl_multifit_linear_workspace * work + = gsl_multifit_linear_alloc (max_samples, n_vars); + + ret = gsl_multifit_linear (X, yv, c, cov, &chisq, work); + gsl_multifit_linear_free (work); + + for (int i = 1; i < num_pics; i++) { + for (int l = 0; l<3; l++) { + color_adjust[i][l] = gsl_vector_get(c, var_offset(i, l)); + } + + fprintf(stderr, "color_adjust(%d) %f\n", i, color_adjust[i][0]); + } + + return 0; +} + double Stitch::vignetting_parameter(int pic, double a_view, double a_nick) { return pow(cos(gipf[pic]->get_angle_off(a_view, a_nick)), 4.0); diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 8ef6b22..9653ae1 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -579,6 +579,7 @@ stitch(GipfelWidget::sample_mode_t m, win->show(0, argv); st->set_output((OutputImage*) img); st->vignette_calib(m, stitch_w, stitch_h, from, to); + // st->color_calib(m, stitch_w, stitch_h, from, to); } if (type & STITCH_JPEG) { -- cgit v1.2.3 From 5da6f96ece0ecf24c8eade8378ca4c90846a8265 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 19 Mar 2007 19:53:50 +0100 Subject: cleanups --- src/Stitch.cxx | 2 +- src/gipfel.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Stitch.cxx b/src/Stitch.cxx index a6c54ce..f0f7236 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -257,7 +257,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int max_samples = 20000 * 3, n_samples = 0; int ret; - int n_vars = 2 ; + int n_vars = 2; gsl_matrix *X, *cov; gsl_vector *yv, *c; double chisq; diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 9653ae1..db13287 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -579,7 +579,7 @@ stitch(GipfelWidget::sample_mode_t m, win->show(0, argv); st->set_output((OutputImage*) img); st->vignette_calib(m, stitch_w, stitch_h, from, to); - // st->color_calib(m, stitch_w, stitch_h, from, to); + //st->color_calib(m, stitch_w, stitch_h, from, to); } if (type & STITCH_JPEG) { -- cgit v1.2.3 From 429ccd9cd43376eab85f84d30427d0d4fb3fa405 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Tue, 20 Mar 2007 23:26:23 +0100 Subject: use single variable vignetting correction model --- src/Stitch.H | 2 +- src/Stitch.cxx | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/Stitch.H b/src/Stitch.H index cd8d7d4..636991c 100644 --- a/src/Stitch.H +++ b/src/Stitch.H @@ -18,7 +18,7 @@ class Stitch { private: GipfelWidget *gipf[MAX_PICS]; int num_pics; - double V1, V2; + double V[4]; double color_adjust[MAX_PICS][3]; OutputImage *single_images[MAX_PICS]; OutputImage *merged_image; diff --git a/src/Stitch.cxx b/src/Stitch.cxx index f0f7236..d59fc87 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -34,8 +34,10 @@ Stitch::Stitch() { merged_image = NULL; num_pics = 0; - V1 = 0.0; - V2 = 0.0; + V[0] = 0.0; + V[1] = 0.0; + V[2] = 0.0; + V[3] = 0.0; } Stitch::~Stitch() { @@ -237,7 +239,7 @@ Stitch::color_calib(GipfelWidget::sample_mode_t m, double Stitch::vignetting_parameter(int pic, double a_view, double a_nick) { - return pow(cos(gipf[pic]->get_angle_off(a_view, a_nick)), 4.0); + return 1.0/pow(cos(gipf[pic]->get_angle_off(a_view, a_nick)), 4.0); } int @@ -257,7 +259,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, int max_samples = 20000 * 3, n_samples = 0; int ret; - int n_vars = 2; + int n_vars = 1; gsl_matrix *X, *cov; gsl_vector *yv, *c; double chisq; @@ -307,10 +309,7 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, double a2 = vignetting_parameter(p2, a_view, a_nick); for (int l = 0; l<3; l++) { - gsl_matrix_set(X, n_samples, 0, c1d[l] * a1); - gsl_matrix_set(X, n_samples, 1, c1d[l] * a1 * a1); - gsl_matrix_set(X, n_samples, 0, -c2d[l] * a2); - gsl_matrix_set(X, n_samples, 1, -c2d[l] * a2 * a2); + gsl_matrix_set(X, n_samples, 0, a1 * c1d[l] - a2 * c2d[l]); gsl_vector_set(yv, n_samples, c2d[l] - c1d[l]); n_samples++; @@ -348,18 +347,19 @@ Stitch::vignette_calib(GipfelWidget::sample_mode_t m, ret = gsl_multifit_linear (X, yv, c, cov, &chisq, work); gsl_multifit_linear_free (work); - V1 = gsl_vector_get(c, 0); - V2 = gsl_vector_get(c, 1); - fprintf(stderr, "==> V1 %f V2 %f\n", V1, V2); - + for (int i=0; i < n_vars; i++) { + V[i] = gsl_vector_get(c, i); + fprintf(stderr, "==> V[i] %f\n", V[i]); + } + return 0; } int Stitch::color_correct(int c, double a, int pic, int color) { double cd = (double) c; - - cd = cd * color_adjust[pic][color] * (1.0 + V1 * a + V2 * a * a); + + cd = cd * color_adjust[pic][color] * a; return MAX(MIN((int) rint(cd), 65025), 0); } -- cgit v1.2.3 From 5b4a674c5922c6516ce6fe580800bacb5bf18b91 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Wed, 9 May 2007 18:49:32 +0200 Subject: remove color- and vignetting correction code --- src/Stitch.H | 15 --- src/Stitch.cxx | 296 +-------------------------------------------------------- src/gipfel.cxx | 24 +---- 3 files changed, 3 insertions(+), 332 deletions(-) (limited to 'src') diff --git a/src/Stitch.H b/src/Stitch.H index 636991c..0632192 100644 --- a/src/Stitch.H +++ b/src/Stitch.H @@ -18,18 +18,9 @@ class Stitch { private: GipfelWidget *gipf[MAX_PICS]; int num_pics; - double V[4]; - double color_adjust[MAX_PICS][3]; OutputImage *single_images[MAX_PICS]; OutputImage *merged_image; - double vignetting_parameter(int pic, double a_view, double a_nick); - - int color_correct(int c, double a, int pic, int color); - - int get_pixel(GipfelWidget::sample_mode_t m, int pic, - double a_view, double a_nick, int *r, int *g, int *b); - public: Stitch(); @@ -43,12 +34,6 @@ class Stitch { int resample(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end); - - int vignette_calib(GipfelWidget::sample_mode_t m, - int w, int h, double view_start, double view_end); - - int color_calib(GipfelWidget::sample_mode_t m, - int w, int h, double view_start, double view_end); }; #endif diff --git a/src/Stitch.cxx b/src/Stitch.cxx index d59fc87..49d2c77 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -27,17 +27,10 @@ Stitch::Stitch() { for (int i=0; i MAX_VALUE * 0.9 || c1[i] < MAX_VALUE * 0.1 || - c2[i] > MAX_VALUE * 0.9 || c2[i] < MAX_VALUE * 0.1) { - return 0; - } - } - - if (fabs(c1[1] / c1[0] - c2[1] / c2[0]) < 0.05 && - fabs(c1[1] / c1[2] - c2[1] / c2[2]) < 0.05 && - fabs(c1[2] / c1[0] - c2[2] / c2[0]) < 0.05 ) { - return 1; - } else { - return 0; - } -} - -static int -var_offset(int pic, int color) { - return (pic - 1) * 3 + color; -} - -int -Stitch::color_calib(GipfelWidget::sample_mode_t m, - int w, int h, double view_start, double view_end) { - - w = 1500; - h = 400; - - view_start = view_start * deg2rad; - view_end = view_end * deg2rad; - - double step_view = (view_end - view_start) / w; - int y_off = h / 2; - int merged_pixel_set; - double radius = (double) w / (view_end -view_start); - - int max_samples = 20000 * 3, n_samples = 0; - int ret; - int n_vars = (num_pics - 1) * 3; - gsl_matrix *X, *cov; - gsl_vector *yv, *c; - double chisq; - - X = gsl_matrix_calloc(max_samples, n_vars); - yv = gsl_vector_calloc(max_samples); - c = gsl_vector_calloc(n_vars); - cov = gsl_matrix_calloc (n_vars, n_vars); - - if (merged_image) { - merged_image->init(w, h); - } - - for (int y = 0; y < h; y++) { - double a_nick = atan((double)(y_off - y)/radius); - - for (int x = 0; x < w; x++) { - double a_view; - a_view = view_start + x * step_view; - merged_pixel_set = 0; - int c1[3], c2[3]; - double c1d[3], c2d[3]; - - for (int p1 = 0; p1 < num_pics; p1++) { - if (get_pixel(m, p1, a_view, a_nick, - &c1[0], &c1[1], &c1[2]) == 0) { - - for (int l = 0; l<3; l++) { - c1d[l] = (double) c1[l]; - } - - for (int p2 = p1 + 1; p2 < num_pics; p2++) { - - if (get_pixel(m, p2, a_view, a_nick, - &c2[0], &c2[1], &c2[2]) == 0) { - - for (int l = 0; l<3; l++) { - c2d[l] = (double) c2[l]; - } - - - if (n_samples < max_samples && - similar_color(c1d, c2d)) { - - for (int l = 0; l<3; l++) { - if (p1 == 0) { - gsl_matrix_set(X, n_samples, var_offset(p2, l), c2d[l]); - - gsl_vector_set(yv, n_samples, c1d[l]); - } else { - gsl_matrix_set(X, n_samples, var_offset(p1, l), c1d[l]); - gsl_matrix_set(X, n_samples, var_offset(p2, l), -c2d[l]); - - gsl_vector_set(yv, n_samples, 0.0); - } - n_samples++; - } - - if (merged_image) { - merged_image->set_pixel(x, 0, 0, 65025); - merged_pixel_set++; - } - } - - } - } - - if (!merged_pixel_set && merged_image) { - merged_image->set_pixel(x, c1[0], c1[1], c1[2]); - merged_pixel_set++; - } - - } - } - } - if (merged_image) { - merged_image->next_line(); - } - } - - if (merged_image) { - merged_image->done(); - } - - gsl_multifit_linear_workspace * work - = gsl_multifit_linear_alloc (max_samples, n_vars); - - ret = gsl_multifit_linear (X, yv, c, cov, &chisq, work); - gsl_multifit_linear_free (work); - - for (int i = 1; i < num_pics; i++) { - for (int l = 0; l<3; l++) { - color_adjust[i][l] = gsl_vector_get(c, var_offset(i, l)); - } - - fprintf(stderr, "color_adjust(%d) %f\n", i, color_adjust[i][0]); - } - - return 0; -} - -double -Stitch::vignetting_parameter(int pic, double a_view, double a_nick) { - return 1.0/pow(cos(gipf[pic]->get_angle_off(a_view, a_nick)), 4.0); -} - -int -Stitch::vignette_calib(GipfelWidget::sample_mode_t m, - int w, int h, double view_start, double view_end) { - - w = 1500; - h = 400; - - view_start = view_start * deg2rad; - view_end = view_end * deg2rad; - - double step_view = (view_end - view_start) / w; - int y_off = h / 2; - int merged_pixel_set; - double radius = (double) w / (view_end -view_start); - - int max_samples = 20000 * 3, n_samples = 0; - int ret; - int n_vars = 1; - gsl_matrix *X, *cov; - gsl_vector *yv, *c; - double chisq; - - X = gsl_matrix_calloc(max_samples, n_vars); - yv = gsl_vector_calloc(max_samples); - c = gsl_vector_calloc(n_vars); - cov = gsl_matrix_calloc (n_vars, n_vars); - - if (merged_image) { - merged_image->init(w, h); - } - - for (int y = 0; y < h; y++) { - double a_nick = atan((double)(y_off - y)/radius); - - for (int x = 0; x < w; x++) { - double a_view; - a_view = view_start + x * step_view; - merged_pixel_set = 0; - int c1[3], c2[3]; - double c1d[3], c2d[3]; - - for (int p1 = 0; p1 < num_pics; p1++) { - if (get_pixel(m, p1, a_view, a_nick, - &c1[0], &c1[1], &c1[2]) == 0) { - - for (int l = 0; l<3; l++) { - c1d[l] = (double) c1[l]; - } - - double a1 = vignetting_parameter(p1, a_view, a_nick); - - for (int p2 = p1 + 1; p2 < num_pics; p2++) { - - if (get_pixel(m, p2, a_view, a_nick, - &c2[0], &c2[1], &c2[2]) == 0) { - - for (int l = 0; l<3; l++) { - c2d[l] = (double) c2[l]; - } - - - if (n_samples < max_samples && - similar_color(c1d, c2d)) { - - double a2 = vignetting_parameter(p2, a_view, a_nick); - - for (int l = 0; l<3; l++) { - gsl_matrix_set(X, n_samples, 0, a1 * c1d[l] - a2 * c2d[l]); - - gsl_vector_set(yv, n_samples, c2d[l] - c1d[l]); - n_samples++; - } - - if (merged_image) { - merged_image->set_pixel(x, 65025, 0, 0); - merged_pixel_set++; - } - } - - } - } - - if (!merged_pixel_set && merged_image) { - merged_image->set_pixel(x, c1[0], c1[1], c1[2]); - merged_pixel_set++; - } - - } - } - } - if (merged_image) { - merged_image->next_line(); - } - } - - if (merged_image) { - merged_image->done(); - } - - gsl_multifit_linear_workspace * work - = gsl_multifit_linear_alloc (max_samples, n_vars); - - ret = gsl_multifit_linear (X, yv, c, cov, &chisq, work); - gsl_multifit_linear_free (work); - - for (int i=0; i < n_vars; i++) { - V[i] = gsl_vector_get(c, i); - fprintf(stderr, "==> V[i] %f\n", V[i]); - } - - return 0; -} - -int -Stitch::color_correct(int c, double a, int pic, int color) { - double cd = (double) c; - - cd = cd * color_adjust[pic][color] * a; - - return MAX(MIN((int) rint(cd), 65025), 0); -} - -int -Stitch::get_pixel(GipfelWidget::sample_mode_t m, int pic, - double a_view, double a_nick, int *r, int *g, int *b) { - - if (gipf[pic]->get_pixel(m, a_view, a_nick, r, g, b) != 0) { - return 1; - } - - double a = vignetting_parameter(pic, a_view, a_nick); - - *r = color_correct(*r, a, pic, 0); - *g = color_correct(*g, a, pic, 1); - *b = color_correct(*b, a, pic, 2); - - return 0; -} - int Stitch::resample(GipfelWidget::sample_mode_t m, int w, int h, double view_start, double view_end) { @@ -413,7 +119,7 @@ Stitch::resample(GipfelWidget::sample_mode_t m, a_view = view_start + x * step_view; merged_pixel_set = 0; for (int i = 0; i < num_pics; i++) { - if (get_pixel(m, i, a_view, a_nick, + if (gipf[i]->get_pixel(m, a_view, a_nick, &r, &g, &b) == 0) { if (single_images[i]) { diff --git a/src/gipfel.cxx b/src/gipfel.cxx index db13287..9db0fce 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -53,7 +53,6 @@ Fl_Menu_Bar *mb; #define STITCH_PREVIEW 1 #define STITCH_JPEG 2 #define STITCH_TIFF 4 -#define STITCH_VIGNETTE_CALIB 8 static int stitch(GipfelWidget::sample_mode_t m ,int stitch_w, int stitch_h, double from, double to, int type, const char *path, int argc, char **argv); @@ -398,7 +397,7 @@ int main(int argc, char** argv) { int err, my_argc; int stitch_flag = 0, stitch_w = 2000, stitch_h = 500; int jpeg_flag = 0, tiff_flag = 0, distortion_flag = 0; - int bicubic_flag = 0, vignette_flag = 0; + int bicubic_flag = 0; double stitch_from = 0.0, stitch_to = 380.0; double dist_k0 = 0.0, dist_k1 = 0.0, dist_x0 = 0.0; char *outpath = "/tmp"; @@ -406,7 +405,7 @@ int main(int argc, char** argv) { err = 0; - while ((c = getopt(argc, argv, ":?d:v:sw:h:j:t:u:br:V")) != EOF) { + while ((c = getopt(argc, argv, ":?d:v:sw:h:j:t:u:br:")) != EOF) { switch (c) { case '?': usage(); @@ -421,9 +420,6 @@ int main(int argc, char** argv) { case 's': stitch_flag++; break; - case 'V': - vignette_flag++; - break; case 'r': stitch_flag++; if (optarg && strcmp(optarg, ":")) { @@ -493,10 +489,6 @@ int main(int argc, char** argv) { type = STITCH_PREVIEW; } - if (vignette_flag) { - type |= STITCH_VIGNETTE_CALIB; - } - stitch(bicubic_flag?GipfelWidget::BICUBIC:GipfelWidget::NEAREST, stitch_w, stitch_h, stitch_from, stitch_to, type, outpath, my_argc, my_argv); @@ -569,18 +561,6 @@ stitch(GipfelWidget::sample_mode_t m, } - if (type & STITCH_VIGNETTE_CALIB) { - win = new Fl_Window(0,0, 1000, 400); - scroll = new Fl_Scroll(0, 0, win->w(), win->h()); - PreviewOutputImage *img = - new PreviewOutputImage(0, 0, 1000, 400); - - win->resizable(scroll); - win->show(0, argv); - st->set_output((OutputImage*) img); - st->vignette_calib(m, stitch_w, stitch_h, from, to); - //st->color_calib(m, stitch_w, stitch_h, from, to); - } if (type & STITCH_JPEG) { st->set_output((OutputImage*) new JPEGOutputImage(path, 90)); -- cgit v1.2.3 From 9256a7ef7644f12c5e2f20400b7bf8943433e080 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 11 May 2007 17:23:20 +0200 Subject: limit output values --- src/GipfelWidget.cxx | 1 - src/Stitch.cxx | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index c8a2fae..7abb1dd 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -756,7 +756,6 @@ GipfelWidget::get_pixel_bicubic(Fl_Image *img, double x, double y, *r = (int) rint(interp_cubic(dy, dy2, dy3, c1[0])); *g = (int) rint(interp_cubic(dy, dy2, dy3, c1[1])); *b = (int) rint(interp_cubic(dy, dy2, dy3, c1[2])); - return 0; } diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 49d2c77..0038b28 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -122,6 +122,10 @@ Stitch::resample(GipfelWidget::sample_mode_t m, if (gipf[i]->get_pixel(m, a_view, a_nick, &r, &g, &b) == 0) { + r = MAX(MIN(r, MAX_VALUE), 0); + g = MAX(MIN(g, MAX_VALUE), 0); + b = MAX(MIN(b, MAX_VALUE), 0); + if (single_images[i]) { single_images[i]->set_pixel(x, r, g, b); } -- cgit v1.2.3 From a7784b543b1bf2052b301457b5b7d4f64d20595e Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Fri, 18 May 2007 19:17:59 +0200 Subject: add 16bit output support --- src/JPEGOutputImage.H | 2 +- src/PreviewOutputImage.H | 2 +- src/TIFFOutputImage.H | 5 +++-- src/TIFFOutputImage.cxx | 27 ++++++++++++++++++--------- src/gipfel.cxx | 20 +++++++++++++------- 5 files changed, 36 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/JPEGOutputImage.H b/src/JPEGOutputImage.H index a4b8f47..06499ca 100644 --- a/src/JPEGOutputImage.H +++ b/src/JPEGOutputImage.H @@ -15,7 +15,7 @@ extern "C" { #include "OutputImage.H" -class JPEGOutputImage : OutputImage { +class JPEGOutputImage : public OutputImage { private: unsigned char *row; char *file; diff --git a/src/PreviewOutputImage.H b/src/PreviewOutputImage.H index cbd55a6..53b58db 100644 --- a/src/PreviewOutputImage.H +++ b/src/PreviewOutputImage.H @@ -14,7 +14,7 @@ #include "OutputImage.H" -class PreviewOutputImage : OutputImage , public Fl_Widget { +class PreviewOutputImage : public OutputImage , public Fl_Widget { private: uchar *data; int d; diff --git a/src/TIFFOutputImage.H b/src/TIFFOutputImage.H index ce61462..9b0f83b 100644 --- a/src/TIFFOutputImage.H +++ b/src/TIFFOutputImage.H @@ -12,14 +12,15 @@ #include "OutputImage.H" -class TIFFOutputImage : OutputImage { +class TIFFOutputImage : public OutputImage { private: + int bitspersample; unsigned char *row; char *file; TIFF *tiff; public: - TIFFOutputImage(const char *file); + TIFFOutputImage(const char *file, int b = 8); ~TIFFOutputImage(); diff --git a/src/TIFFOutputImage.cxx b/src/TIFFOutputImage.cxx index 156079c..b8effed 100644 --- a/src/TIFFOutputImage.cxx +++ b/src/TIFFOutputImage.cxx @@ -10,7 +10,8 @@ #include "TIFFOutputImage.H" -TIFFOutputImage::TIFFOutputImage(const char *f) { +TIFFOutputImage::TIFFOutputImage(const char *f, int b) { + bitspersample = (b==16)?16:8; file = strdup(f); tiff = NULL; row = NULL; @@ -32,12 +33,12 @@ TIFFOutputImage::init_internal(int w1, int h1) { row = NULL; } - row = (unsigned char*) malloc(sizeof(char) * 4 * w1); + row = (unsigned char*) malloc(sizeof(char) * (bitspersample / 8) * 4 * w1); if (!row) { perror("malloc"); return 1; } - memset(row, 0, sizeof(char) * 4 * w1); + memset(row, 0, sizeof(char) * (bitspersample / 8) * 4 * w1); if (tiff) { TIFFClose(tiff); @@ -54,7 +55,7 @@ TIFFOutputImage::init_internal(int w1, int h1) { TIFFSetField(tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, 1); - TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 8); + TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, bitspersample); TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 4); return 0; @@ -62,17 +63,25 @@ TIFFOutputImage::init_internal(int w1, int h1) { int TIFFOutputImage::set_pixel_internal(int x, int r, int g, int b) { - row[x*4+0] = (unsigned char) (r / 255); - row[x*4+1] = (unsigned char) (g / 255); - row[x*4+2] = (unsigned char) (b / 255); - row[x*4+3] = 255; + if (bitspersample == 8) { + row[x*4+0] = (unsigned char) (r / 255); + row[x*4+1] = (unsigned char) (g / 255); + row[x*4+2] = (unsigned char) (b / 255); + row[x*4+3] = 255; + } else if (bitspersample == 16) { + unsigned short *row16 = (unsigned short*) row; + row16[x*4+0] = (unsigned short) r; + row16[x*4+1] = (unsigned short) g; + row16[x*4+2] = (unsigned short) b; + row16[x*4+3] = 65025; + } return 0; } int TIFFOutputImage::next_line_internal() { - TIFFWriteEncodedStrip(tiff, line -1 , row, W * 4); + TIFFWriteEncodedStrip(tiff, line - 1 , row, W * (bitspersample / 8) * 4); memset(row, 0, sizeof(char) * 4 * W); return 0; diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 9db0fce..3fbf945 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -54,7 +54,8 @@ Fl_Menu_Bar *mb; #define STITCH_JPEG 2 #define STITCH_TIFF 4 -static int stitch(GipfelWidget::sample_mode_t m ,int stitch_w, int stitch_h, +static int stitch(GipfelWidget::sample_mode_t m , int b_16, + int stitch_w, int stitch_h, double from, double to, int type, const char *path, int argc, char **argv); void set_values() { @@ -256,6 +257,7 @@ void usage() { " -d Use for GPS data.\n" " -u , Use distortion correction values k0,k1.\n" " -s Stitch mode.\n" + " -4 Create 16bit output (only with TIFF stitching).\n" " -r , Stitch range in degrees (e.g. 100.0,200.0).\n" " -b Use bilinear interpolation for stitching.\n" " -w Width of result image.\n" @@ -397,7 +399,7 @@ int main(int argc, char** argv) { int err, my_argc; int stitch_flag = 0, stitch_w = 2000, stitch_h = 500; int jpeg_flag = 0, tiff_flag = 0, distortion_flag = 0; - int bicubic_flag = 0; + int bicubic_flag = 0, b_16_flag = 0; double stitch_from = 0.0, stitch_to = 380.0; double dist_k0 = 0.0, dist_k1 = 0.0, dist_x0 = 0.0; char *outpath = "/tmp"; @@ -405,7 +407,7 @@ int main(int argc, char** argv) { err = 0; - while ((c = getopt(argc, argv, ":?d:v:sw:h:j:t:u:br:")) != EOF) { + while ((c = getopt(argc, argv, ":?d:v:sw:h:j:t:u:br:4")) != EOF) { switch (c) { case '?': usage(); @@ -420,6 +422,9 @@ int main(int argc, char** argv) { case 's': stitch_flag++; break; + case '4': + b_16_flag++; + break; case 'r': stitch_flag++; if (optarg && strcmp(optarg, ":")) { @@ -490,6 +495,7 @@ int main(int argc, char** argv) { } stitch(bicubic_flag?GipfelWidget::BICUBIC:GipfelWidget::NEAREST, + b_16_flag, stitch_w, stitch_h, stitch_from, stitch_to, type, outpath, my_argc, my_argv); @@ -548,7 +554,7 @@ int main(int argc, char** argv) { } static int -stitch(GipfelWidget::sample_mode_t m, +stitch(GipfelWidget::sample_mode_t m, int b_16, int stitch_w, int stitch_h, double from, double to, int type, const char *path, int argc, char **argv) { @@ -563,7 +569,7 @@ stitch(GipfelWidget::sample_mode_t m, if (type & STITCH_JPEG) { - st->set_output((OutputImage*) new JPEGOutputImage(path, 90)); + st->set_output(new JPEGOutputImage(path, 90)); st->resample(m, stitch_w, stitch_h, from, to); } else if (type & STITCH_TIFF) { @@ -577,7 +583,7 @@ stitch(GipfelWidget::sample_mode_t m, *dot = '\0'; strncat(buf, ".tiff", sizeof(buf)); - st->set_output(argv[i], (OutputImage*) new TIFFOutputImage(buf)); + st->set_output(argv[i], new TIFFOutputImage(buf, b_16?16:8)); } st->resample(m, stitch_w, stitch_h, from, to); @@ -590,7 +596,7 @@ stitch(GipfelWidget::sample_mode_t m, win->resizable(scroll); win->show(0, argv); - st->set_output((OutputImage*) img); + st->set_output(img); st->resample(m, stitch_w, stitch_h, from, to); -- cgit v1.2.3