Skip to content

Commit

Permalink
Merge pull request #146 from Bookaflok/bugfix20220120
Browse files Browse the repository at this point in the history
Fix bug with improper cluster threshold set for variable threshold situations
  • Loading branch information
PJ-Watson authored Nov 26, 2024
2 parents e328a2e + 16053fb commit 1557cf4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 1557cf4

Please sign in to comment.