diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Stitch.H | 15 | ||||
| -rw-r--r-- | src/Stitch.cxx | 296 | ||||
| -rw-r--r-- | src/gipfel.cxx | 24 | 
3 files changed, 3 insertions, 332 deletions
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_PICS; i++) {  		gipf[i] = NULL;  		single_images[i] = NULL; -		for (int l=0; l<3; l++) { -			color_adjust[i][l] = 1.0; -		}  	}  	merged_image = NULL;  	num_pics = 0; -	V[0] = 0.0; -	V[1] = 0.0; -	V[2] = 0.0; -	V[3] = 0.0;  }  Stitch::~Stitch() { @@ -94,293 +87,6 @@ Stitch::set_output(const char *file, OutputImage *img) {  	return ret;  } - -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; -	} -} - -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));  | 
