38 #include "omega_dfs.h"
39 #include "omega_background.h"
40 #include "omega_utils.h"
41 #include "omega_satellites.h"
82 cpl_mask *
detsat(cpl_image *nscience, cpl_parameterlist *hpars)
93 double hthre = 1000.0;
97 float threshold = 0.0f;
99 const char *_id =
"detsat";
100 const char *alias = NULL;
114 cpl_msg_error (
"",
"%s Parameters list not found", _id);
120 npars = cpl_parameterlist_get_size(hpars);
121 par = cpl_parameterlist_get_first(hpars);
123 for(i=0; i<npars; i++) {
124 alias = cpl_parameter_get_alias(par, CPL_PARAMETER_MODE_CLI);
125 if(strcmp(
"det-sate", alias) == 0) {
126 dthre = cpl_parameter_get_double(par) ;
129 else if(strcmp(
"hough-thre", alias) == 0) {
130 hthre = cpl_parameter_get_double(par) ;
133 par = cpl_parameterlist_get_next(hpars);
138 stats = cpl_stats_new_from_image (nscience, CPL_STATS_ALL);
140 cpl_msg_warning(
"",
"%s Cannot calculate image statistics",_id);
146 stdev = cpl_stats_get_median_dev(stats);
147 median = cpl_stats_get_median(stats);
148 if(stdev == 0.0) stdev = 1.0;
149 cpl_stats_delete(stats);
151 threshold = median + (float)(dthre * stdev);
157 cpl_msg_warning(
"",
"%s Error in Hough Transform", _id);
158 cpl_image_delete(hough);
161 threshold = (float)hthre;
163 nx = cpl_image_get_size_x(nscience);
164 ny = cpl_image_get_size_y(nscience);
166 hough_map = hough_inverse_transform(hough, threshold, nx, ny);
167 if(hough_map == NULL) {
168 cpl_msg_warning(
"",
"%s Error in Inverse Hough Transform", _id);
169 cpl_image_delete(hough);
170 cpl_mask_delete(hough_map);
175 count = cpl_mask_count(hough_map);
177 cpl_msg_info(
"",
"No satellite tracks were detected in image");
180 cpl_msg_info(
"",
"Detected %d satellite tracks in image", count);
186 cpl_image_delete(hough);
228 const char *_id =
"hough_transform:";
230 cpl_image *hough_img;
236 cpl_msg_error(
"",
"<%s> No input image",_id);
241 img_data = (
float *)cpl_image_get_data(img);
243 drho = 1.0/sqrt(2.0);
244 nx = cpl_image_get_size_x (img);
245 ny = cpl_image_get_size_y (img);
247 nrho = (int)(sqrt(nx*nx + ny*ny)/drho) + 1;
249 dtheta = 2*PI/(double)ntheta;
251 hough_img = cpl_image_new(nrho,ntheta,CPL_TYPE_FLOAT);
252 if(hough_img == NULL) {
253 cpl_msg_error(
"",
"<%s>Cannot create Hough image",_id);
257 hough_data = (
float *)cpl_image_get_data(hough_img);
260 for(i=0; i<nrho*ntheta; i++) {
261 hough_data[i] = (float)0.0;
264 sins = calloc(1, ntheta*
sizeof(
float));
266 cpl_msg_error(
"",
"%s Error in allocating memory", _id);
267 cpl_image_delete(hough_img);
271 coss = calloc(1, ntheta*
sizeof(
float));
273 cpl_msg_error(
"",
"%s Error in allocating memory", _id);
274 cpl_image_delete(hough_img);
279 for(i=0; i<ntheta; i++){
280 theta = ((double)i + 0.5) * dtheta;
281 sins[i] = sin(theta);
282 coss[i] = cos(theta);
288 if(img_data[j*nx+i] > thre){
290 for(k=0; k<ntheta; k++){
291 l = (int)floor((x*coss[k] + y*sins[k]) / drho);
292 hough_data[k*nrho+l] += (float)1.0;
305 cpl_mask *hough_inverse_transform(cpl_image *himg,
float thre,
int lx,
int ly)
327 const char *_id =
"hough_inverse_transform:";
334 cpl_msg_error(
"",
"<%s> No input image",_id);
338 drho = 1.0/sqrt(2.0);
339 nrho = (int)(sqrt(lx*lx + ly*ly)/drho) + 1;
341 dtheta = 2*PI / (double)ntheta;
343 hnx = cpl_image_get_size_x(himg);
344 hny = cpl_image_get_size_y(himg);
347 if( !((nrho == hnx) && (ntheta == hny)) ) {
348 cpl_msg_error(
"",
"%s Dimensions of Hough image are incompatible",_id);
352 pmap = cpl_mask_new(lx, ly);
354 cpl_msg_error(
"",
"<%s> Error creating pixelmap",_id);
358 pdata = cpl_mask_get_data(pmap);
360 edge = sqrt(2.0)/2.0;
362 hdata = (
float *)cpl_image_get_data(himg);
364 for(j=0; j<ntheta; j++) {
365 theta = ((double)j + 0.5) * dtheta;
366 for(i=0; i<nrho; i++) {
367 rho = (double)i * drho;
368 if( hdata[j*nrho + i] > thre ) {
370 if( fabs(sin(theta) > edge) ) {
372 a = -cos(theta) / sin(theta);
375 k = floor( (
double)l * a + b);
376 if( (k>0) && (k<ly) ){
377 pdata[k*lx+l] = CPL_BINARY_1;
383 a = -sin(theta) / cos(theta);
386 l = floor( (
double)k * a + b);
387 if( (l>=0) && (l<lx) ){
388 pdata[k*lx+l] = CPL_BINARY_1;