29#include "hdrl_image.h"
30#include "hdrl_parameter.h"
47void hdrl_flat_test_parlist(
void)
50 hdrl_parameter * hpar;
51 cpl_size filter_size_x=5;
52 cpl_size filter_size_y=5;
53 hdrl_flat_method method=HDRL_FLAT_FREQ_LOW;
56 filter_size_y, method);
58 cpl_test_error(CPL_ERROR_NONE);
63 cpl_test_error(CPL_ERROR_NONE);
64 cpl_test_eq(cpl_parameterlist_get_size(pflat), 3);
68 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
71 cpl_parameterlist_delete(pflat);
72 cpl_test_error(CPL_ERROR_NONE);
85 cpl_test_null(deflts);
86 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
90 cpl_test_null(deflts);
91 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
95 cpl_test_null(deflts);
96 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
100 cpl_test_null(deflts);
101 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
105 cpl_test_null(deflts);
106 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
110 cpl_test_null(deflts);
111 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
157hdrl_flat_imlist_flag_region(hdrl_imagelist * imglist,
158 const hdrl_parameter * rect,
159 const double outlier,
174 for (
int var = 0; var < nima ; ++var) {
178 cpl_mask * data_bpm = cpl_mask_new(ima_sx, ima_sy);
183 for(
int j = b_lly; j < b_ury; j++) {
184 for(
int i = b_llx; i < b_urx; i++) {
185 cpl_image_set(data, i, j, outlier);
190 for(
int j = b_lly; j < b_ury; j++) {
191 for(
int i = b_llx; i < b_urx; i++) {
192 cpl_mask_set(data_bpm, i, j, CPL_BINARY_1);
199 cpl_image_reject_from_mask(data, data_bpm);
201 cpl_image * errors=cpl_image_power_create(data, 0.5);
222 cpl_mask_delete(data_bpm);
224 cpl_image_delete(errors);
228 cpl_imagelist* iml_data = NULL;
229 cpl_imagelist* iml_errs = NULL;
230 hdrl_imagelist_to_cplwrap(imglist, &iml_data, &iml_errs);
237 cpl_imagelist_unwrap(iml_data);
238 cpl_imagelist_unwrap(iml_errs);
240 return cpl_error_get_code();
245static hdrl_imagelist*
246hdrl_flat_create_uniform_images(
248 const cpl_size ima_sx,
249 const cpl_size ima_sy,
250 const cpl_vector* values)
254 for (
int var = 0; var < nima ; ++var) {
256 cpl_image * data = cpl_image_new(ima_sx, ima_sy, CPL_TYPE_DOUBLE);
257 cpl_mask * data_bpm = cpl_mask_new(ima_sx, ima_sy);
260 cpl_image_add_scalar(data, cpl_vector_get(values, var));
261 cpl_image * errors = cpl_image_power_create(data, 0.5);
274 cpl_mask_delete(data_bpm);
275 cpl_image_delete(data);
276 cpl_image_delete(errors);
280 cpl_imagelist* iml_data = NULL;
281 cpl_imagelist* iml_errs = NULL;
282 hdrl_imagelist_to_cplwrap(imglist, &iml_data, &iml_errs);
289 cpl_imagelist_unwrap(iml_data);
290 cpl_imagelist_unwrap(iml_errs);
295hdrl_flat_crea_static_mask(
const cpl_size ima_sx,
296 const cpl_size ima_sy,
297 const hdrl_parameter * rect)
304 cpl_mask * stat_mask = cpl_mask_new(ima_sx, ima_sy);
305 for(
int j = b_lly; j < b_ury; j++) {
306 for(
int i = b_llx; i < b_urx; i++) {
307 cpl_mask_set(stat_mask, i, j, CPL_BINARY_1);
338hdrl_flat_test_case(hdrl_imagelist* imglist,
339 const hdrl_parameter * rect,
340 const hdrl_flat_method method,
343 const hdrl_parameter* collapse_params,
351 hdrl_parameter * fparam ;
352 cpl_mask * stat_mask = NULL;
362 cpl_size b_cx = (int)(0.5 * (b_llx + b_urx) + 0.5);
363 cpl_size b_cy = (int)(0.5 * (b_lly + b_ury) + 0.5);
368 hdrl_image * master = NULL;
369 cpl_image * contrib_map = NULL;
374 stat_mask=hdrl_flat_crea_static_mask(ima_sx, ima_sy, rect);
378 fparam, &master, &contrib_map);
387 cpl_msg_warning(cpl_func,
"Check for err2 = %g still to be implemented",
413 cpl_mask_delete(stat_mask);
414 cpl_image_delete(contrib_map);
416 return cpl_error_get_code();
425static cpl_error_code hdrl_flat_test_multi_options(
void)
428 const cpl_size ima_sx = 200;
429 const cpl_size ima_sy = 300;
430 const cpl_size b_llx = 100;
431 const cpl_size b_lly = 100;
432 const cpl_size b_urx = 200;
433 const cpl_size b_ury = 200;
434 const cpl_size nima = 5;
435 const double outlier = 100000;
436 hdrl_parameter * rect_region_bad_area_def =
441 cpl_vector * vals = cpl_vector_new(nima);
442 cpl_vector * valserr_rel = cpl_vector_new(nima);
443 const double base = 2;
445 for (
int i = 0; i < nima ; ++i) {
446 double intensity = pow(base, i);
447 cpl_vector_set(vals, i, intensity);
448 cpl_vector_set(valserr_rel, i, sqrt(intensity)/intensity);
451 hdrl_imagelist * imglist = hdrl_flat_create_uniform_images(nima, ima_sx,
453 hdrl_flat_imlist_flag_region(imglist, rect_region_bad_area_def, outlier, 0);
456 cpl_size filter_size_x = 1;
457 cpl_size filter_size_y = 1;
458 const double r_median = 25000;
459 const double r_mean = 38750;
468 cpl_vector_power(valserr_rel, 2);
470 double error_expected_pix1_mean = sqrt(cpl_vector_get_sum(valserr_rel))/nima;
471 double error_expected_pix1_median = error_expected_pix1_mean* sqrt(CPL_MATH_PI_2);
482 hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_LOW,
483 filter_size_x, filter_size_y, collapse_pMedian, 0,
484 1, error_expected_pix1_median, r_median, 91.4844);
493 hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_LOW,
494 filter_size_x, filter_size_y, collapse_pMedian, 1,
495 1, error_expected_pix1_median, r_median, 91.4844);
504 hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_LOW,
505 filter_size_x, filter_size_y, collapse_pMean, 0,
506 1, error_expected_pix1_mean, r_mean, 72.994);
515 hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_LOW,
516 filter_size_x, filter_size_y, collapse_pMean, 1,
517 1, error_expected_pix1_mean,r_mean,72.994);
526 hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_HIGH,
527 filter_size_x, filter_size_y, collapse_pMedian, 0,
528 1, error_expected_pix1_median, 1, 0.00177245);
537 hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_HIGH,
538 filter_size_x, filter_size_y, collapse_pMedian, 1,
539 1, error_expected_pix1_median, 1, 0.00177245);
548 hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_HIGH,
549 filter_size_x, filter_size_y, collapse_pMean, 0,
550 1, error_expected_pix1_mean, 1, 0.00141421);
559 hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_HIGH,
560 filter_size_x, filter_size_y, collapse_pMean, 1,
561 1, error_expected_pix1_mean, 1, 0.00141421);
569 cpl_vector_delete(vals);
570 cpl_vector_delete(valserr_rel);
571 return cpl_error_get_code();
580static cpl_error_code hdrl_flat_test_static_mask(
void)
583 const cpl_size ima_sx = 200;
584 const cpl_size ima_sy = 300;
586 const cpl_size r1_llx = 50;
587 const cpl_size r1_lly = 50;
588 const cpl_size r1_urx = 80;
589 const cpl_size r1_ury = 250;
590 const double outlier1 = 100000;
592 const cpl_size r2_llx = 100;
593 const cpl_size r2_lly = 90;
594 const cpl_size r2_urx = 130;
595 const cpl_size r2_ury = 260;
596 const double outlier2 = 200000;
598 const cpl_size r3_llx = 150;
599 const cpl_size r3_lly = 80;
600 const cpl_size r3_urx = 180;
601 const cpl_size r3_ury = 270;
602 const double outlier3 = 300000;
604 const cpl_size nima = 5;
615 cpl_vector * vals = cpl_vector_new(nima);
617 const double base = 2;
618 for (
int i = 0; i < nima ; ++i) {
619 double intensity = pow(base, i);
620 cpl_vector_set(vals, i, intensity);
623 hdrl_imagelist* imglist = hdrl_flat_create_uniform_images(nima, ima_sx,
625 hdrl_flat_imlist_flag_region(imglist, rect1, outlier1, 1);
626 hdrl_flat_imlist_flag_region(imglist, rect2, outlier2, 1);
627 hdrl_flat_imlist_flag_region(imglist, rect3, outlier3, 1);
630 cpl_size filter_size_x = 1;
631 cpl_size filter_size_y = 1;
632 const double r_mean = 38750;
633 const double e_mean = 72.994;
649 hdrl_flat_test_case(imglist, rect1, HDRL_FLAT_FREQ_LOW,
650 filter_size_x, filter_size_y, collapse_pMean, 0,
651 1, 0.278388, r_mean, e_mean);
663 hdrl_flat_test_case(imglist, rect1, HDRL_FLAT_FREQ_HIGH,
664 filter_size_x, filter_size_y, collapse_pMean, 0,
665 1, 0.278388, 1, 0.00141421);
674 hdrl_flat_test_case(imglist, rect1, HDRL_FLAT_FREQ_HIGH,
675 filter_size_x, filter_size_y, collapse_pMedian, 0,
676 1, 0.278388, 1, 0.00141421);
687 cpl_vector_delete(vals);
689 return cpl_error_get_code();
699static cpl_error_code hdrl_flat_test_data_value_basic(
void)
702 const cpl_size ima_sx = 51;
703 const cpl_size ima_sy = 31;
704 int npix = ima_sx * ima_sy;
705 const cpl_size filter_size_x = 1;
706 const cpl_size filter_size_y = 1;
707 const cpl_size nima = 9;
710 cpl_vector * vals = cpl_vector_new(nima);
712 double error = sqrt(value);
713 cpl_vector_fill(vals, value);
715 hdrl_imagelist * imglist = hdrl_flat_create_uniform_images(nima, ima_sx,
717 cpl_vector_delete(vals);
719 hdrl_parameter * flat_params;
720 hdrl_image * master = NULL;
721 cpl_image * contrib_map = NULL;
723 double expected_error;
745 expected_error = error / value / sqrt(nima) / sqrt(ima_sx * ima_sy);
748 cpl_test_abs( res.data, 1, HDRL_EPS_ERROR);
749 cpl_test_abs( res.error, expected_error, HDRL_EPS_ERROR);
757 cpl_test_abs( res.data, 1, HDRL_EPS_ERROR);
762 cpl_test_abs( res.error, expected_error * sqrt(CPL_MATH_PI_2),
769 cpl_test_abs( res.data, npix, HDRL_EPS_ERROR);
774 cpl_test_abs( res.error, sqrt(npix) / nima, npix * HDRL_EPS_ERROR);
776 cpl_test_abs( cpl_image_get_mean(contrib_map), nima, HDRL_EPS_ERROR );
778 cpl_image_delete(contrib_map);
793 HDRL_FLAT_FREQ_HIGH);
801 expected_error = error / value / sqrt(nima) / sqrt(ima_sx * ima_sy);
803 cpl_test_abs( res.data, 1, HDRL_EPS_ERROR);
804 cpl_test_abs( res.error, expected_error, HDRL_EPS_ERROR);
807 cpl_test_abs( res.data, 1, HDRL_EPS_ERROR);
808 cpl_test_abs( res.error, expected_error * sqrt(CPL_MATH_PI_2),
814 cpl_test_abs( res.data, npix, HDRL_EPS_ERROR);
819 cpl_test_abs( res.error, sqrt(npix) / nima, npix * HDRL_EPS_ERROR);
821 cpl_test_abs( cpl_image_get_mean(contrib_map), nima, HDRL_EPS_ERROR);
823 cpl_image_delete(contrib_map);
829 return cpl_error_get_code();
839static cpl_error_code hdrl_flat_test_data_value_bpm(
void)
842 const cpl_size ima_sx = 51;
843 const cpl_size ima_sy = 31;
845 const cpl_size filter_size_x = 1;
846 const cpl_size filter_size_y = 1;
848 const cpl_size nima = 9;
851 cpl_vector * vals = cpl_vector_new(nima);
853 double error = sqrt(value);
854 cpl_vector_fill(vals, value);
856 hdrl_imagelist * imglist = hdrl_flat_create_uniform_images(nima, ima_sx,
858 cpl_vector_delete(vals);
859 const cpl_size r1_llx = 11;
860 const cpl_size r1_lly = 11;
861 const cpl_size r1_urx = 31;
862 const cpl_size r1_ury = 23;
865 const double outlier1 = 10000;
867 hdrl_parameter * rect1 =
870 hdrl_flat_imlist_flag_region(imglist, rect1, outlier1, 1);
873 hdrl_parameter * flat_params;
874 hdrl_image * master = NULL;
875 cpl_image * contrib_map = NULL;
877 double expected_error;
878 double expected_value;
899 xsam = 0.5 * (r1_llx+r1_urx);
900 ysam = 0.5 * (r1_lly+r1_ury);
902 expected_value = cpl_image_get(contrib_map, xsam, ysam, &status);
905 cpl_test( isnan(res.data));
906 cpl_test( isnan(res.error));
907 cpl_test_abs( expected_value, 0, HDRL_EPS_ERROR );
911 xsam = 0.5 * (ima_sx+r1_urx);
912 ysam = 0.5 * (ima_sy+r1_ury);
913 expected_error = error / value / sqrt(nima);
914 expected_value = cpl_image_get(contrib_map, xsam, ysam, &status);
918 cpl_test_abs(res.data, 1, HDRL_EPS_ERROR);
919 cpl_test_abs(res.error, expected_error, HDRL_EPS_ERROR);
920 cpl_test_abs( expected_value, nima, HDRL_EPS_ERROR );
923 cpl_image_delete(contrib_map);
937 HDRL_FLAT_FREQ_HIGH);
944 xsam = 0.5 * (r1_llx+r1_urx);
945 ysam = 0.5 * (r1_lly+r1_ury);
947 expected_value = cpl_image_get(contrib_map, xsam, ysam, &status);
950 cpl_test( isnan(res.data));
951 cpl_test( isnan(res.error));
953 cpl_test_abs( expected_value, 0, HDRL_EPS_ERROR );
956 xsam = 0.5 * (ima_sx+r1_urx);
957 ysam = 0.5 * (ima_sy+r1_ury);
958 expected_error = error / value / sqrt(nima);
959 expected_value = cpl_image_get(contrib_map, xsam, ysam, &status);
963 cpl_test_abs(res.data, 1, HDRL_EPS_ERROR);
964 cpl_test_abs(res.error, expected_error, HDRL_EPS_ERROR);
965 cpl_test_abs( expected_value, nima, HDRL_EPS_ERROR );
969 cpl_image_delete(contrib_map);
975 return cpl_error_get_code();
984static cpl_error_code hdrl_flat_test_data_value_bpm_static(
void)
987 const cpl_size ima_sx = 51;
988 const cpl_size ima_sy = 31;
990 const cpl_size filter_size_x = 1;
991 const cpl_size filter_size_y = 1;
992 const cpl_size nima = 9;
995 cpl_vector * vals = cpl_vector_new(nima);
997 double error = sqrt(value);
998 cpl_vector_fill(vals, value);
1000 hdrl_imagelist * imglist = hdrl_flat_create_uniform_images(nima, ima_sx,
1002 cpl_vector_delete(vals);
1003 const cpl_size r1_llx = 11;
1004 const cpl_size r1_lly = 11;
1005 const cpl_size r1_urx = 31;
1006 const cpl_size r1_ury = 23;
1009 const double outlier1 = 10000;
1011 hdrl_parameter * rect1 =
1014 hdrl_flat_imlist_flag_region(imglist, rect1, outlier1, 0);
1017 hdrl_parameter * flat_params;
1018 hdrl_image * master = NULL;
1019 cpl_image * contrib_map = NULL;
1021 double expected_error;
1022 double expected_value;
1036 HDRL_FLAT_FREQ_LOW);
1041 cpl_mask* static_bpm=cpl_mask_new(ima_sx,ima_sy);
1042 for(
int j = r1_lly; j < r1_ury; j++) {
1043 for(
int i = r1_llx; i < r1_urx; i++) {
1044 cpl_mask_set(static_bpm, i, j, CPL_BINARY_1);
1049 &master, &contrib_map);
1053 xsam = 0.5 * (r1_llx+r1_urx);
1054 ysam = 0.5 * (r1_lly+r1_ury);
1056 expected_value = cpl_image_get(contrib_map, xsam, ysam, &status);
1059 expected_error = sqrt(outlier1) / value / sqrt(nima);
1061 cpl_test_abs( res.data, outlier1/nima, 13 * 21 * nima * HDRL_EPS_DATA);
1062 cpl_test_abs( res.error, expected_error, 3 * HDRL_EPS_ERROR);
1063 cpl_test_abs( expected_value, nima, HDRL_EPS_ERROR );
1068 xsam = 0.5 * (ima_sx+r1_urx);
1069 ysam = 0.5 * (ima_sy+r1_ury);
1070 expected_error = error / value / sqrt(nima);
1071 expected_value = cpl_image_get(contrib_map, xsam, ysam, &status);
1075 cpl_test_abs(res.data, 1, HDRL_EPS_ERROR);
1076 cpl_test_abs(res.error, expected_error, HDRL_EPS_ERROR);
1077 cpl_test_abs( expected_value, nima, HDRL_EPS_ERROR );
1080 cpl_image_delete(contrib_map);
1094 HDRL_FLAT_FREQ_HIGH);
1097 &master, &contrib_map);
1101 xsam = 0.5 * (r1_llx+r1_urx);
1102 ysam = 0.5 * (r1_lly+r1_ury);
1104 expected_value = cpl_image_get(contrib_map, xsam, ysam, &status);
1107 expected_error = sqrt(outlier1) / outlier1 / sqrt(nima);
1109 cpl_test_abs( res.data, 1, HDRL_EPS_ERROR);
1110 cpl_test_abs( res.error, expected_error, 3 * HDRL_EPS_ERROR);
1111 cpl_test_abs( expected_value, nima, HDRL_EPS_ERROR );
1117 xsam = 0.5 * (ima_sx+r1_urx);
1118 ysam = 0.5 * (ima_sy+r1_ury);
1119 expected_error = error / value / sqrt(nima);
1120 expected_value = cpl_image_get(contrib_map, xsam, ysam, &status);
1124 cpl_test_abs(res.data, 1, HDRL_EPS_ERROR);
1125 cpl_test_abs(res.error, expected_error, HDRL_EPS_ERROR);
1126 cpl_test_abs( expected_value, nima, HDRL_EPS_ERROR );
1129 cpl_image_delete(contrib_map);
1133 cpl_mask_delete(static_bpm);
1136 return cpl_error_get_code();
1146 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
1148 hdrl_flat_test_data_value_bpm();
1149 hdrl_flat_test_data_value_bpm_static();
1150 hdrl_flat_test_data_value_basic();
1151 hdrl_flat_test_multi_options();
1152 hdrl_flat_test_static_mask();
1153 hdrl_flat_test_parlist();
1155 cpl_test_error(CPL_ERROR_NONE);
1156 return cpl_test_end(0);
hdrl_parameter * hdrl_collapse_mean_parameter_create(void)
create a parameter object for mean
hdrl_parameter * hdrl_collapse_median_parameter_create(void)
create a parameter object for median
cpl_size hdrl_flat_parameter_get_filter_size_x(const hdrl_parameter *p)
Access the filter_size_x in the FLAT parameter.
hdrl_parameter * hdrl_flat_parameter_create(cpl_size filter_size_x, cpl_size filter_size_y, hdrl_flat_method method)
Creates FLAT Parameters object.
cpl_size hdrl_flat_parameter_get_filter_size_y(const hdrl_parameter *p)
Access the filter_size_y in the FLAT parameter.
cpl_error_code hdrl_flat_compute(hdrl_imagelist *hdrl_data, const cpl_mask *stat_mask, const hdrl_parameter *collapse_params, hdrl_parameter *flat_params, hdrl_image **master, cpl_image **contrib_map)
compute high or low frequency master flat with median filtering
hdrl_flat_method hdrl_flat_parameter_get_method(const hdrl_parameter *p)
Access the method in the FLAT parameter.
hdrl_parameter * hdrl_flat_parameter_parse_parlist(const cpl_parameterlist *parlist, const char *prefix)
Parse a parameterlist to create input parameters for the FLAT.
cpl_parameterlist * hdrl_flat_parameter_create_parlist(const char *base_context, const char *prefix, const hdrl_parameter *defaults)
Create a parameter list for the FLAT computation.
cpl_boolean hdrl_flat_parameter_check(const hdrl_parameter *self)
Check that the parameter is a FLAT parameter.
hdrl_value hdrl_image_get_pixel(const hdrl_image *self, cpl_size xpos, cpl_size ypos, int *pis_rejected)
get pixel values of hdrl_image
hdrl_value hdrl_image_get_median(const hdrl_image *self)
computes the median and associated error of an image.
double hdrl_image_get_stdev(const hdrl_image *self)
computes the standard deviation of the data of an image
hdrl_value hdrl_image_get_sum(const hdrl_image *self)
computes the sum of all pixel values and the associated error of an image.
cpl_image * hdrl_image_get_error(hdrl_image *himg)
get error as cpl image
hdrl_value hdrl_image_get_mean(const hdrl_image *self)
computes mean pixel value and associated error of an image.
cpl_size hdrl_image_get_size_y(const hdrl_image *self)
return size of Y dimension of image
cpl_size hdrl_image_get_size_x(const hdrl_image *self)
return size of X dimension of image
hdrl_image * hdrl_image_create(const cpl_image *image, const cpl_image *error)
create a new hdrl_image from to existing images by copying them
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
cpl_error_code hdrl_imagelist_set(hdrl_imagelist *himlist, hdrl_image *himg, cpl_size pos)
Insert an image into an imagelist.
void hdrl_imagelist_delete(hdrl_imagelist *himlist)
Free all memory used by a hdrl_imagelist object including the images.
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
hdrl_imagelist * hdrl_imagelist_new(void)
Create an empty imagelist.
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.
void hdrl_parameter_delete(hdrl_parameter *obj)
shallow delete of a parameter
hdrl_parameter * hdrl_rect_region_parameter_create(cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury)
Creates Rect Region Parameters object.
cpl_size hdrl_rect_region_get_llx(const hdrl_parameter *p)
get lower left x coordinate of rectangual region
cpl_size hdrl_rect_region_get_urx(const hdrl_parameter *p)
get upper right x coordinate of rectangular region
cpl_size hdrl_rect_region_get_lly(const hdrl_parameter *p)
get lower left y coordinate of rectangual region
cpl_size hdrl_rect_region_get_ury(const hdrl_parameter *p)
get upper right y coordinate of rectangual region