From 16053fb4cd8d240b6f333db20f3d9b0ab8363470 Mon Sep 17 00:00:00 2001 From: Bookaflok <123209009+Bookaflok@users.noreply.github.com> Date: Fri, 20 Jan 2023 18:28:00 -0700 Subject: [PATCH] fix bug with improper thresh set for rel noise cases --- src/extract.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/extract.c b/src/extract.c index 40d9fb3..399d775 100644 --- a/src/extract.c +++ b/src/extract.c @@ -58,6 +58,7 @@ int sortit(infostruct *info, objliststruct *objlist, int minarea, deblendctx *deblendctx); void plistinit(int hasconv, int hasvar); void clean(objliststruct *objlist, double clean_param, int *survives); +PIXTYPE get_mean_thresh(infostruct *info, pliststruct *pixel); int convert_to_catalog(objliststruct *objlist, const int *survives, sep_catalog *cat, int w, int include_pixels); @@ -626,7 +627,10 @@ int sep_extract(const sep_image *image, float thresh, int thresh_type, if ((int)info[co].pixnb >= minarea) { /* update threshold before object is processed */ - objlist.thresh = thresh; + if (PLISTEXIST(thresh)) + objlist.thresh = get_mean_thresh(&info[co], objlist.plist); + else + objlist.thresh = thresh; status = sortit(&info[co], &objlist, minarea, finalobjlist, @@ -993,6 +997,25 @@ void clean(objliststruct *objlist, double clean_param, int *survives) } /* outer loop of objlist (obj1) */ } +/************************** get_mean_thresh **********************************/ +/* +Compute an average threshold from all pixels in the cluster +*/ +PIXTYPE get_mean_thresh(infostruct *info, pliststruct *pixel) +{ + pliststruct *pixt; + int pix_accum=0; + PIXTYPE thresh_accum=0; + + for (pixt=pixel+info->firstpix; pixt>=pixel; + pixt=pixel+PLIST(pixt,nextpix)) + { + thresh_accum += PLISTPIX(pixt,thresh); + pix_accum++; + } + + return thresh_accum / pix_accum; +} /*****************************************************************************/ /* sep_catalog manipulations */