00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include <float.h>
00037 #include <string.h>
00038 #include <math.h>
00039 #include <cpl.h>
00040
00041 #include "hawki_saa.h"
00042
00043
00052
00053 int hawki_geom_refine_images_offsets
00054 (cpl_imagelist * in,
00055 cpl_bivector * approx_offsets,
00056 cpl_bivector * reference_objects,
00057 int s_hx,
00058 int s_hy,
00059 int m_hx,
00060 int m_hy,
00061 cpl_bivector * refined_offsets,
00062 cpl_vector * correl)
00063 {
00064 cpl_bivector * offs_ref ;
00065 double * offs_ref_x ;
00066 double * offs_ref_y ;
00067 double * correl_data ;
00068 int nimages;
00069 int ngood;
00070 int i;
00071
00072
00073 if (approx_offsets == NULL) return -1;
00074 if (refined_offsets == NULL) return -1;
00075
00076
00077 nimages = cpl_imagelist_get_size(in) ;
00078 if (cpl_bivector_get_size(approx_offsets) != nimages)
00079 {
00080 cpl_msg_error(__func__, "Invalid input objects sizes") ;
00081 return -1;
00082 }
00083
00084
00085 cpl_msg_info(__func__, "Refine the offsets") ;
00086 cpl_msg_indent_more() ;
00087 if ((offs_ref = cpl_geom_img_offset_fine
00088 (in, approx_offsets, reference_objects,
00089 s_hx, s_hy, m_hx, m_hy, correl)) == NULL)
00090 {
00091 cpl_msg_error(cpl_func, "Cannot refine the offsets");
00092 cpl_vector_delete(correl) ;
00093 return -1;
00094 }
00095
00096
00097 offs_ref_x = cpl_bivector_get_x_data(offs_ref) ;
00098 offs_ref_y = cpl_bivector_get_y_data(offs_ref) ;
00099 correl_data = cpl_vector_get_data(correl) ;
00100 cpl_msg_info(cpl_func, "Refined relative offsets [correlation factor]") ;
00101 ngood = 0 ;
00102 for (i=0 ; i<nimages ; i++)
00103 {
00104 cpl_msg_info(cpl_func, "#%02d: %8.2f %8.2f [%12.2f]",
00105 i+1, offs_ref_x[i], offs_ref_y[i], correl_data[i]) ;
00106 if (correl_data[i] > -0.5) ngood++ ;
00107 }
00108 if (ngood == 0)
00109 {
00110 cpl_msg_error(__func__, "No frame correctly correlated") ;
00111 cpl_bivector_delete(offs_ref) ;
00112 cpl_vector_delete(correl) ;
00113 return -1;
00114 }
00115 cpl_msg_indent_less();
00116
00117
00118 cpl_vector_copy(cpl_bivector_get_x(refined_offsets),
00119 cpl_bivector_get_x(offs_ref));
00120 cpl_vector_copy(cpl_bivector_get_y(refined_offsets),
00121 cpl_bivector_get_y(offs_ref));
00122
00123
00124 cpl_bivector_delete(offs_ref);
00125 cpl_msg_indent_less() ;
00126 return 0;
00127 }