29#include "hdrl_prototyping.h"
39void test_prototyping_spatial_freq(
void)
43 cpl_image *image = cpl_image_new(dim_X, dim_Y, CPL_TYPE_DOUBLE);
46 double gausfilt = 1.0;
53 cpl_test_error(CPL_ERROR_NONE);
54 cpl_image_delete(out1);
55 cpl_image_delete(image);
57 image = cpl_image_new(1, 1, CPL_TYPE_INT);
59 cpl_test_error(CPL_ERROR_NONE);
60 cpl_image_delete(image);
61 cpl_image_delete(out2);
65void test_mime_image_polynomial_bkg(
void)
69 cpl_image *image = NULL;
70 cpl_matrix *coeffs = NULL;
71 cpl_image *out = hdrl_mime_image_polynomial_bkg(image, dim_X, dim_Y, &coeffs);
72 cpl_test_error(CPL_ERROR_NULL_INPUT);
75 image = cpl_image_new(dim_X, dim_Y, CPL_TYPE_DOUBLE);
76 out = hdrl_mime_image_polynomial_bkg(image, dim_X, dim_Y, &coeffs);
77 cpl_test_error(CPL_ERROR_NONE);
78 cpl_test_nonnull(out);
79 cpl_test_nonnull(coeffs);
81 cpl_image_delete(image);
82 cpl_image_delete(out);
83 cpl_matrix_delete(coeffs);
86void test_mime_compute_polynomial_bkg(
void){
88 cpl_imagelist *images = NULL;
89 cpl_imagelist *bkg_images = NULL;
92 cpl_matrix *coeffs = NULL;
98 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
101 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
104 cpl_image *image = cpl_image_new(dim_X, dim_Y, CPL_TYPE_DOUBLE);
105 images = cpl_imagelist_new();
106 cpl_imagelist_set(images, cpl_image_duplicate(image), 0);
107 cpl_imagelist_set(images, cpl_image_duplicate(image), 1);
112 bkg_images = cpl_imagelist_new();
113 cpl_imagelist_set(bkg_images, cpl_image_duplicate(image), 0);
114 cpl_imagelist_set(bkg_images, cpl_image_duplicate(image), 1);
120 cpl_image_delete(image);
121 cpl_imagelist_delete(images);
122 cpl_imagelist_delete(bkg_images);
125void test_mime_legendre_polynomials_create(
void){
130 cpl_matrix *x = NULL;
131 cpl_matrix *legendre;
137 cpl_test_error(CPL_ERROR_NULL_INPUT);
138 cpl_test_null(legendre);
140 x = cpl_matrix_new(a, b);
142 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
143 cpl_test_null(legendre);
144 cpl_matrix_delete(x);
151 x = cpl_matrix_new(a, b);
153 cpl_test_error(CPL_ERROR_NONE);
154 cpl_test_nonnull(legendre);
155 cpl_matrix_delete(legendre);
156 cpl_matrix_delete(x);
161void test_mime_legendre_tensors_create(
void)
173 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
177 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
181 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
185 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
191 cpl_test_error(CPL_ERROR_NONE);
192 cpl_test_nonnull(out);
193 cpl_matrix_delete(out);
196void test_mime_matrix_linspace_create(
void)
204 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
210 cpl_test_error(CPL_ERROR_NONE);
211 cpl_test_nonnull(out);
212 cpl_matrix_delete(out);
215void test_mime_matrix_copy_column(
void)
221 cpl_matrix *mat1 = cpl_matrix_new(nx, ny);
222 cpl_matrix *mat2 = cpl_matrix_new(nx, ny);
224 cpl_matrix *mat = cpl_matrix_new(ny, nx);
230 cpl_test_error(CPL_ERROR_NULL_INPUT);
233 cpl_test_error(CPL_ERROR_NULL_INPUT);
236 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
239 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
242 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
245 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
248 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
251 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
256 cpl_test_error(CPL_ERROR_NONE);
259 cpl_matrix_delete(mat );
260 cpl_matrix_delete(mat1);
261 cpl_matrix_delete(mat2);
265void test_mime_linalg_pairwise_column_tensor_products_create(
void)
270 cpl_matrix *mat1 = NULL;
271 cpl_matrix *mat2 = NULL;
277 cpl_test_error(CPL_ERROR_NULL_INPUT);
280 mat1 = cpl_matrix_new(nx, ny);
282 cpl_test_error(CPL_ERROR_NULL_INPUT);
287 mat2 = cpl_matrix_new(nx, ny);
289 cpl_test_nonnull(out);
290 cpl_matrix_delete(out);
293 cpl_matrix_delete(mat1);
294 cpl_matrix_delete(mat2);
297void test_mime_linalg_tensor_products_columns_create(
void)
301 cpl_matrix *mat1 = cpl_matrix_new(nx, ny);
302 cpl_matrix *mat2 = cpl_matrix_new(nx, ny);
304 cpl_matrix *mat = cpl_matrix_new(ny, nx);
313 cpl_test_error(CPL_ERROR_NULL_INPUT);
317 cpl_test_error(CPL_ERROR_NULL_INPUT);
321 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
327 cpl_test_error(CPL_ERROR_NONE);
328 cpl_test_nonnull(out);
329 cpl_matrix_delete(out);
333 cpl_matrix_delete(mat );
334 cpl_matrix_delete(mat1);
335 cpl_matrix_delete(mat2);
338void test_mime_tensor_weights_create(
void)
349 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
353 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
359 cpl_test_error(CPL_ERROR_NONE);
360 cpl_test_nonnull(out);
361 cpl_matrix_delete(out);
364void test_mime_matrix_mask_rows(
void){
368 cpl_matrix *mat = cpl_matrix_new(nx, ny);
369 cpl_mask *mask = cpl_mask_new( nx, ny);
370 cpl_mask *mask1 = cpl_mask_new( ny, nx);
376 cpl_test_error(CPL_ERROR_NULL_INPUT);
379 cpl_test_error(CPL_ERROR_NULL_INPUT);
382 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
387 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
391 cpl_matrix_delete(mat);
392 cpl_mask_delete(mask);
393 cpl_mask_delete(mask1);
396void test_mime_matrix_rescale_rows(
void){
398 cpl_matrix *mat = cpl_matrix_new(2, 1);
399 cpl_matrix *d = cpl_matrix_new(2, 1);
400 cpl_matrix *dmat = cpl_matrix_new(2, 1);
401 cpl_matrix *d1 = cpl_matrix_new(2, 2);
402 cpl_matrix *dmat1 = cpl_matrix_new(1, 2);
408 cpl_test_error(CPL_ERROR_NULL_INPUT);
411 cpl_test_error(CPL_ERROR_NULL_INPUT);
414 cpl_test_error(CPL_ERROR_NULL_INPUT);
417 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
420 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
425 cpl_test_error(CPL_ERROR_NONE);
427 cpl_matrix_delete(mat);
428 cpl_matrix_delete(d);
429 cpl_matrix_delete(d1);
430 cpl_matrix_delete(dmat);
431 cpl_matrix_delete(dmat1);
434void test_mime_linalg_solve_tikhonov(
void)
436 cpl_matrix *mat = cpl_matrix_new(1,2);
437 cpl_matrix *rhs = cpl_matrix_new(1,2);
438 cpl_matrix *rhs1 = cpl_matrix_new(2,2);
446 cpl_test_error(CPL_ERROR_NULL_INPUT);
450 cpl_test_error(CPL_ERROR_NULL_INPUT);
454 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
460 cpl_test_error(CPL_ERROR_NONE);
461 cpl_test_nonnull(out);
462 cpl_matrix_delete(out);
466 cpl_matrix_delete(mat);
467 cpl_matrix_delete(rhs);
468 cpl_matrix_delete(rhs1);
471void test_mime_linalg_normal_equations_create(
void)
473 cpl_matrix *mat = cpl_matrix_new(1,2);
481 cpl_test_error(CPL_ERROR_NULL_INPUT);
485 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
491 cpl_test_error(CPL_ERROR_NONE);
492 cpl_test_nonnull(out);
493 cpl_matrix_delete(out);
497 cpl_matrix_delete(mat);
500void test_mime_matrix_product_left_transpose_create(
void)
504 cpl_matrix *mat1 = cpl_matrix_new(nx, ny);
505 cpl_matrix *mat2 = cpl_matrix_new(nx, ny);
507 cpl_matrix *mat = cpl_matrix_new(ny, nx);
516 cpl_test_error(CPL_ERROR_NULL_INPUT);
520 cpl_test_error(CPL_ERROR_NULL_INPUT);
524 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
530 cpl_test_error(CPL_ERROR_NONE);
531 cpl_test_nonnull(out);
532 cpl_matrix_delete(out);
536 cpl_matrix_delete(mat );
537 cpl_matrix_delete(mat1);
538 cpl_matrix_delete(mat2);
541void test_mime_matrix_product(
void)
543 cpl_matrix *mat1 = cpl_matrix_new(2, 3);
544 cpl_matrix *mat2 = cpl_matrix_new(3, 2);
545 cpl_matrix *mat = cpl_matrix_new(2, 3);
547 cpl_matrix *product = cpl_matrix_new(2, 2);
548 cpl_matrix *product_1 = cpl_matrix_new(3, 2);
549 cpl_matrix *product_2 = cpl_matrix_new(3, 2);
555 cpl_test_error(CPL_ERROR_NULL_INPUT);
558 cpl_test_error(CPL_ERROR_NULL_INPUT);
561 cpl_test_error(CPL_ERROR_NULL_INPUT);
564 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
567 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
570 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
574 cpl_test_error(CPL_ERROR_NONE);
578 cpl_matrix_delete(mat1);
579 cpl_matrix_delete(mat2);
580 cpl_matrix_delete(mat);
581 cpl_matrix_delete(product);
582 cpl_matrix_delete(product_1);
583 cpl_matrix_delete(product_2);
594 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
596 test_prototyping_spatial_freq();
598 test_mime_image_polynomial_bkg();
599 test_mime_compute_polynomial_bkg();
601 test_mime_legendre_polynomials_create();
602 test_mime_legendre_tensors_create();
603 test_mime_matrix_linspace_create();
604 test_mime_matrix_copy_column();
605 test_mime_linalg_pairwise_column_tensor_products_create();
606 test_mime_linalg_tensor_products_columns_create();
607 test_mime_tensor_weights_create();
609 test_mime_matrix_mask_rows();
610 test_mime_matrix_rescale_rows();
612 test_mime_linalg_solve_tikhonov();
613 test_mime_linalg_normal_equations_create();
615 test_mime_matrix_product_left_transpose_create();
616 test_mime_matrix_product();
619 return cpl_test_end(0);
cpl_error_code hdrl_mime_compute_polynomial_bkg(const cpl_imagelist *images, cpl_imagelist *bkg_images, int dim_X, int dim_Y, cpl_matrix **coeffs)
Fit smooth background for a list of images.
cpl_matrix * hdrl_mime_legendre_tensors_create(int nx, int ny, int npx, int npy)
Create tensor products of Legendre polynomials.
cpl_error_code hdrl_mime_matrix_mask_rows(cpl_matrix *mat, const cpl_mask *mask)
Fill matrix rows with zeros as indicated by a mask.
cpl_matrix * hdrl_mime_linalg_solve_tikhonov(const cpl_matrix *mat, const cpl_matrix *rhs, double alpha)
Solve an overdetermined linear system in the least-squares sense.
cpl_error_code hdrl_mime_matrix_copy_column(const cpl_matrix *mat1, int j_1, cpl_matrix *mat2, int j_2)
Copy a column from one matrix to another matrix.
cpl_matrix * hdrl_mime_linalg_pairwise_column_tensor_products_create(const cpl_matrix *mat1, const cpl_matrix *mat2)
Create selected pairwise tensor products of the columns of two matrices.
cpl_matrix * hdrl_mime_matrix_product_left_transpose_create(const cpl_matrix *mat1, const cpl_matrix *mat2)
Create the product of the transpose of a matrix with another matrix.
cpl_error_code hdrl_mime_matrix_rescale_rows(const cpl_matrix *mat, const cpl_matrix *d, cpl_matrix *dmat)
Multiply the rows of a matrix by given factors.
cpl_matrix * hdrl_mime_tensor_weights_create(int nx, int ny)
Create tensor product weights.
cpl_matrix * hdrl_mime_legendre_polynomials_create(int npoly, double a, double b, const cpl_matrix *x)
Create the Legendre polynomial basis on the interval (a,b).
cpl_image * hdrl_get_spatial_freq(cpl_image *ima, double gausfilt, int mirrorx, int mirrory)
Get low spatial frequency componenets from an image using the FFTW.
cpl_matrix * hdrl_mime_matrix_linspace_create(int n, double a, double b)
Create equally spaced nodes.
cpl_matrix * hdrl_mime_linalg_normal_equations_create(const cpl_matrix *mat, double alpha)
Create the matrix transpose(A) * A + alpha for given A and alpha.
cpl_matrix * hdrl_mime_linalg_tensor_products_columns_create(const cpl_matrix *mat1, const cpl_matrix *mat2)
Create the tensor products of the columns of two matrices.
cpl_error_code hdrl_mime_matrix_product(const cpl_matrix *mat1, const cpl_matrix *mat2, cpl_matrix *product)
Fill a matrix with the product of two given matrices.