40 #include "omega_trim.h"
41 #include "omega_fits.h"
42 #include "omega_pfits.h"
43 #include "omega_stats.h"
44 #include "omega_utils.h"
95 const char *_id =
"TrimOscanCorrect";
97 cpl_image *image=NULL;
98 cpl_image *trim_image=NULL;
99 cpl_image *tmp_img=NULL;
100 cpl_vector *region=NULL;
101 cpl_stats *px = NULL;
102 cpl_stats *py = NULL;
103 cpl_stats *ox = NULL;
104 cpl_stats *oy = NULL;
107 cpl_msg_error(_id,
"NULL input frame. %s",cpl_error_get_message());
111 image = cpl_image_load(cpl_frame_get_filename(frame), CPL_TYPE_FLOAT, 0, extn);
113 cpl_msg_error(_id,
"Cannot load input image. %s",cpl_error_get_message());
118 tmp_img = cpl_image_duplicate(image);
122 if (oscan > 0 && oscan < 5){
133 tmp_img = cpl_image_subtract_scalar_create(image,cpl_stats_get_median(px));
136 tmp_img = cpl_image_duplicate(image);
137 cpl_msg_warning(_id,
"The overscan method %d may not suit these data",oscan);
143 tmp_img = cpl_image_subtract_scalar_create(image,cpl_stats_get_median(ox));
146 tmp_img = cpl_image_duplicate(image);
147 cpl_msg_warning(_id,
"The overscan method %d may not suit these data",oscan);
153 tmp_img = cpl_image_subtract_scalar_create(image,cpl_stats_get_median(py));
156 tmp_img = cpl_image_duplicate(image);
157 cpl_msg_warning(_id,
"The overscan method %d may not suit these data",oscan);
163 tmp_img = cpl_image_subtract_scalar_create(image,cpl_stats_get_median(oy));
166 tmp_img = cpl_image_duplicate(image);
167 cpl_msg_warning(_id,
"The overscan method %d may not suit these data",oscan);
174 cpl_propertylist *plist = cpl_propertylist_load(cpl_frame_get_filename(frame), extn);
177 tmp_img =
oscan_row(image, (
int)cpl_vector_get(region,0),(
int)cpl_vector_get(region,2));
182 tmp_img =
oscan_row(image, (
int)cpl_vector_get(region,0),(
int)cpl_vector_get(region,2));
189 x0 = (int)cpl_vector_get(region,0);
190 ry0 = (int)cpl_vector_get(region,1);
191 x1 = (int)cpl_vector_get(region,2);
192 ry1 = (int)cpl_vector_get(region,3);
194 trim_image = cpl_image_extract(tmp_img, x0, ry0, x1, ry1);
195 if (trim_image == NULL) {
196 cpl_msg_error (_id,
"Cannot extract trimmed image <%s>", cpl_error_get_message());
256 cpl_image *trim_image;
259 cpl_propertylist *xlist;
260 cpl_stats *px = NULL;
261 cpl_stats *py = NULL;
262 cpl_stats *ox = NULL;
263 cpl_stats *oy = NULL;
266 cpl_msg_error(cpl_func,
"NULL input file. %s",cpl_error_get_message());
275 if (oscan > 0 && oscan < 5){
282 tmp_img = cpl_image_subtract_scalar_create(
omega_fits_get_image(ofits),cpl_stats_get_median(px));
286 cpl_msg_warning(cpl_func,
"The overscan method %d may not suit these data",oscan);
292 tmp_img = cpl_image_subtract_scalar_create(
omega_fits_get_image(ofits),cpl_stats_get_median(ox));
296 cpl_msg_warning(cpl_func,
"The overscan method %d may not suit these data",oscan);
302 tmp_img = cpl_image_subtract_scalar_create(
omega_fits_get_image(ofits),cpl_stats_get_median(py));
306 cpl_msg_warning(cpl_func,
"The overscan method %d may not suit these data",oscan);
312 tmp_img = cpl_image_subtract_scalar_create(
omega_fits_get_image(ofits),cpl_stats_get_median(oy));
316 cpl_msg_warning(cpl_func,
"The overscan method %d may not suit these data",oscan);
327 (
int)cpl_vector_get(region,2));
332 (
int)cpl_vector_get(region,2));
338 x0 = (int)cpl_vector_get(region,0);
339 ry0 = (int)cpl_vector_get(region,1);
340 x1 = (int)cpl_vector_get(region,2);
341 ry1 = (int)cpl_vector_get(region,3);
343 trim_image = cpl_image_extract(tmp_img, x0, ry0, x1, ry1);
344 if (trim_image == NULL) {
345 cpl_msg_error (cpl_func,
"Cannot extract trimmed image <%s>", cpl_error_get_message());
391 cpl_image *image_out;
394 lx = cpl_image_get_size_x (img);
395 ly = cpl_image_get_size_y (img);
397 image_out = cpl_image_new (lx, ly, CPL_TYPE_FLOAT);
402 pindata = (
float *)cpl_image_get_data (img);
403 poutdata = (
float *)cpl_image_get_data (image_out);
408 oscanoffset = offset+x1-1;
411 for (j=0; j<oscansize; j++)
413 med += pindata[oscanoffset+j];
419 for (j=0; j<lx; j++){
420 poutdata[offset+j] = pindata[offset+j]-med;
458 const char *filename = NULL;
460 cpl_propertylist *xplist;
466 cpl_msg_error(cpl_func,
"Input frame is NULL");
470 filename = cpl_frame_get_filename(frame);
473 xplist = cpl_propertylist_load(filename, extnum);
475 cpl_msg_error(cpl_func,
"Cannot load header");
479 naxis1 = cpl_propertylist_get_int(xplist,
"NAXIS1");
480 naxis2 = cpl_propertylist_get_int(xplist,
"NAXIS2");
481 if (naxis1 == 0 || naxis2 == 0){
482 cpl_msg_error(cpl_func,
"NAXIS1 or NAXIS2 is 0");
490 cpl_msg_warning(cpl_func,
"Cannot get pre and overscan regions");
495 prscx = cpl_vector_get(sregion,0);
496 prscy = cpl_vector_get(sregion,1);
497 ovscx = cpl_vector_get(sregion,2);
498 ovscy = cpl_vector_get(sregion,3);
511 ry1 = naxis2 - ovscy;
517 ry1 = naxis2 - prscy;
523 ry1 = naxis2 - ovscy;
524 cpl_msg_warning(cpl_func,
"Using default chip layout");
567 region = cpl_vector_new(4);
568 cpl_vector_set(region, 0, x0);
569 cpl_vector_set(region, 1, ry0);
570 cpl_vector_set(region, 2, x1);
571 cpl_vector_set(region, 3, ry1);
610 cpl_propertylist *xlist;
614 cpl_msg_error(cpl_func,
"Input frame is NULL");
619 naxis1 = cpl_propertylist_get_int(xlist,
"NAXIS1");
620 naxis2 = cpl_propertylist_get_int(xlist,
"NAXIS2");
621 if (naxis1 == 0 || naxis2 == 0){
622 cpl_msg_error(cpl_func,
"NAXIS1 or NAXIS2 is 0");
630 cpl_msg_warning(cpl_func,
"Cannot get pre and overscan regions");
634 prscx = cpl_vector_get(sregion,0);
635 prscy = cpl_vector_get(sregion,1);
636 ovscx = cpl_vector_get(sregion,2);
637 ovscy = cpl_vector_get(sregion,3);
647 ry1 = naxis2 - ovscy;
653 ry1 = naxis2 - prscy;
659 ry1 = naxis2 - ovscy;
660 cpl_msg_warning(cpl_func,
"Using default chip layout");
664 region = cpl_vector_new(4);
665 cpl_vector_set(region, 0, x0);
666 cpl_vector_set(region, 1, ry0);
667 cpl_vector_set(region, 2, x1);
668 cpl_vector_set(region, 3, ry1);
692 void DoStatistics (
const cpl_frame *frame, cpl_image *image,
int extnum,
693 cpl_stats **px,cpl_stats **py,cpl_stats **ox,cpl_stats **oy)
700 double threshold = 1.0;
703 cpl_propertylist *plist;
706 if((plist = cpl_propertylist_load(cpl_frame_get_filename(frame), extnum)) == NULL)
722 x0 = (int)cpl_vector_get(region,0);
723 ry0 = (int)cpl_vector_get(region,1);
724 x1 = (int)cpl_vector_get(region,2);
725 ry1 = (int)cpl_vector_get(region,3);
740 x0 = (int)cpl_vector_get(region,0);
741 ry0 = (int)cpl_vector_get(region,1);
742 x1 = (int)cpl_vector_get(region,2);
743 ry1 = (int)cpl_vector_get(region,3);
751 if (ry1 - ry0 +1 > 0){
758 x0 = (int)cpl_vector_get(region,0);
759 ry0 = (int)cpl_vector_get(region,1);
760 x1 = (int)cpl_vector_get(region,2);
761 ry1 = (int)cpl_vector_get(region,3);
776 x0 = (int)cpl_vector_get(region,0);
777 ry0 = (int)cpl_vector_get(region,1);
778 x1 = (int)cpl_vector_get(region,2);
779 ry1 = (int)cpl_vector_get(region,3);
787 if (ry1 - ry0 +1 > 0){
812 cpl_stats **ox,cpl_stats **oy)
819 double threshold = 1.0;
822 cpl_propertylist *xlist;
842 x0 = (int)cpl_vector_get(region,0);
843 ry0 = (int)cpl_vector_get(region,1);
844 x1 = (int)cpl_vector_get(region,2);
845 ry1 = (int)cpl_vector_get(region,3);
855 x0 = (int)cpl_vector_get(region,0);
856 ry0 = (int)cpl_vector_get(region,1);
857 x1 = (int)cpl_vector_get(region,2);
858 ry1 = (int)cpl_vector_get(region,3);
860 if (ry1 - ry0 +1 > 0){
867 x0 = (int)cpl_vector_get(region,0);
868 ry0 = (int)cpl_vector_get(region,1);
869 x1 = (int)cpl_vector_get(region,2);
870 ry1 = (int)cpl_vector_get(region,3);
879 x0 = (int)cpl_vector_get(region,0);
880 ry0 = (int)cpl_vector_get(region,1);
881 x1 = (int)cpl_vector_get(region,2);
882 ry1 = (int)cpl_vector_get(region,3);
884 if (ry1 - ry0 +1 > 0){
942 naxis1 = cpl_propertylist_get_int(plist,
"NAXIS1");
943 naxis2 = cpl_propertylist_get_int(plist,
"NAXIS2");
944 if (naxis1 == 0 || naxis2 == 0){
945 cpl_msg_error(cpl_func,
"NAXIS1 or NAXIS2 is 0");
952 if(chipornt == 0) chipornt = 1;
957 prscx = (int)cpl_vector_get(sregion,0);
958 prscy = (int)cpl_vector_get(sregion,1);
959 ovscx = (int)cpl_vector_get(sregion,2);
960 ovscy = (int)cpl_vector_get(sregion,3);
972 ry1 = naxis2 - ovscy;
973 cpl_msg_debug(cpl_func,
"px: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
981 cpl_msg_debug(cpl_func,
"py: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
988 ry1 = naxis2 - ovscy;
989 cpl_msg_debug(cpl_func,
"ox: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
994 ry0 = naxis2-ovscy+1;
997 cpl_msg_debug(cpl_func,
"oy: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
1000 cpl_msg_error(cpl_func,
"Unable to get pre/overscan coordinates");
1001 freevector(sregion);
1011 x0 = naxis1 - prscx + 1;
1015 cpl_msg_debug(cpl_func,
"px: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
1023 cpl_msg_debug(cpl_func,
"py: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
1030 ry1 = naxis2 - prscy;
1031 cpl_msg_debug(cpl_func,
"ox: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
1039 cpl_msg_debug(cpl_func,
"oy: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
1042 cpl_msg_error(cpl_func,
"Unable to get pre/overscan coordinates");
1043 freevector(sregion);
1049 region = cpl_vector_new(4);
1050 cpl_vector_set(region, 0, x0);
1051 cpl_vector_set(region, 1, ry0);
1052 cpl_vector_set(region, 2, x1);
1053 cpl_vector_set(region, 3, ry1);
1056 freevector(sregion);