[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 756b312 2/4: NoiseChisel checks if any growth
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 756b312 2/4: NoiseChisel checks if any growth is possible |
Date: |
Fri, 2 Mar 2018 19:04:20 -0500 (EST) |
branch: master
commit 756b312fc57d411650f1290b073e5e745c6bcd05
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
NoiseChisel checks if any growth is possible
Until now, when doing the quantile growth, NoiseChisel wouldn't actually
check if any pixels existed for growth or not. So when the input data and
parameters created conditions where no growth was possible (no pixels
existed to grow), NoiseChisel would crash. A check has been added, so in
such conditions, NoiseChisel acts as if no growth was requested (the
verbose output also explicity says that no growth happened).
This bug was found during a test run of NoiseChisel on data provided by
Nima Dehdilani and Sara Yousefi.
This fixes bug #53268.
---
NEWS | 2 +-
THANKS | 2 +
bin/noisechisel/detection.c | 144 +++++++++++++++++++++++++------------------
doc/announce-acknowledge.txt | 2 +
4 files changed, 90 insertions(+), 60 deletions(-)
diff --git a/NEWS b/NEWS
index 7e83d09..0ca8614 100644
--- a/NEWS
+++ b/NEWS
@@ -30,7 +30,7 @@ GNU Astronomy Utilities NEWS -*-
outline -*-
Statistics program bad results on integer columns with limits (bug #53230).
-
+ NoiseChisel crash when no growth is possible (bug #53268).
diff --git a/THANKS b/THANKS
index e9a72b9..a5ea730 100644
--- a/THANKS
+++ b/THANKS
@@ -24,6 +24,7 @@ support in Gnuastro. The list is ordered alphabetically (by
family name).
Adrian Bunk address@hidden
Rosa Calvi address@hidden
Benjamin Clement address@hidden
+ Nima Dehdilani address@hidden
Antonio Diaz Diaz address@hidden
Thérèse Godefroy address@hidden
Madusha Gunawardhana address@hidden
@@ -52,6 +53,7 @@ support in Gnuastro. The list is ordered alphabetically (by
family name).
Ignacio Trujillo address@hidden
David Valls-Gabaud address@hidden
Christopher Willmer address@hidden
+ Sara Yousefi address@hidden
Teams
diff --git a/bin/noisechisel/detection.c b/bin/noisechisel/detection.c
index 93e2132..9245255 100644
--- a/bin/noisechisel/detection.c
+++ b/bin/noisechisel/detection.c
@@ -928,11 +928,14 @@ detection_remove_false_initial(struct noisechiselparams
*p,
+/* Expand the initial detections based on the quantile threshold and then
+ label the connected regions. If expansion is not possible, then return
+ the `GAL_BLANK_SIZET'.*/
static size_t
detection_quantile_expand(struct noisechiselparams *p, gal_data_t *workbin)
{
int32_t *o, *of;
- size_t *d, counter=0, numexpanded;
+ size_t *d, counter=0, numexpanded=0;
float *i, *e_th, *arr=p->conv->array;
gal_data_t *exp_thresh_full, *diffuseindexs;
uint8_t *b=workbin->array, *bf=b+workbin->size;
@@ -948,72 +951,79 @@ detection_quantile_expand(struct noisechiselparams *p,
gal_data_t *workbin)
e_th=exp_thresh_full->array;
do { if(*b++==0 && *arr>*e_th) ++counter; ++arr; ++e_th; } while(b<bf);
- /* Allocate the space necessary to keep the index of all the pixels that
- must be expanded and re-initialize the necessary pointers. */
- diffuseindexs=gal_data_alloc(NULL, GAL_TYPE_SIZE_T, 1, &counter, NULL, 0,
- p->cp.minmapsize, NULL, NULL, NULL);
-
- /* Fill in the diffuse indexs and initialize the objects dataset. */
- b=workbin->array;
- arr=p->conv->array;
- d=diffuseindexs->array;
- e_th=exp_thresh_full->array;
- of=(o=p->olabel->array)+p->olabel->size;
- do
- {
- /* If the binary value is 1, then we want an initial label of 1 (the
- object is already detected). If it isn't, then we only want it if
- it is above the threshold. */
- *o = *b==1 ? 1 : ( *arr>*e_th ? CLUMPS_INIT : 0);
- if(*b==0 && *arr>*e_th)
- *d++ = o - (int32_t *)(p->olabel->array);
-
- /* Increment the points and go onto the next pixel. */
- ++b;
- ++arr;
- ++e_th;
- }
- while(++o<of);
-
- /* Expand the detections. */
- clumps_grow(p->olabel, diffuseindexs, 0, p->olabel->ndim);
-
- /* Only keep the 1 valued pixels in the binary array and fill its
- holes. */
- o=p->olabel->array;
- bf=(b=workbin->array)+workbin->size;
- do *b = (*o++ == 1); while(++b<bf);
- workbin=gal_binary_dilate(workbin, 1, 1, 1);
- gal_binary_fill_holes(workbin, 1, p->detgrowmaxholesize);
-
- /* Get the labeled image. */
- numexpanded=gal_binary_connected_components(workbin, &p->olabel,
- workbin->ndim);
-
- /* Set all the input's blank pixels to blank in the labeled and binary
- arrays. */
- if( gal_blank_present(p->input, 1) )
+ /* only continue if there actually are any pixels to expand (this can
+ happen!). */
+ if(counter)
{
+ /* Allocate the space necessary to keep the index of all the pixels
+ that must be expanded and re-initialize the necessary pointers. */
+ diffuseindexs=gal_data_alloc(NULL, GAL_TYPE_SIZE_T, 1, &counter, NULL,
+ 0, p->cp.minmapsize, NULL, NULL, NULL);
+
+ /* Fill in the diffuse indexs and initialize the objects dataset. */
b=workbin->array;
- i=p->input->array;
+ arr=p->conv->array;
+ d=diffuseindexs->array;
+ e_th=exp_thresh_full->array;
of=(o=p->olabel->array)+p->olabel->size;
do
{
- if(isnan(*i++))
- {
- *o=GAL_BLANK_INT32;
- *b=GAL_BLANK_UINT8;
- }
+ /* If the binary value is 1, then we want an initial label of 1
+ (the object is already detected). If it isn't, then we only
+ want it if it is above the threshold. */
+ *o = *b==1 ? 1 : ( *arr>*e_th ? CLUMPS_INIT : 0);
+ if(*b==0 && *arr>*e_th)
+ *d++ = o - (int32_t *)(p->olabel->array);
+
+ /* Increment the points and go onto the next pixel. */
++b;
+ ++arr;
+ ++e_th;
}
while(++o<of);
+
+ /* Expand the detections. */
+ clumps_grow(p->olabel, diffuseindexs, 0, p->olabel->ndim);
+
+ /* Only keep the 1 valued pixels in the binary array and fill its
+ holes. */
+ o=p->olabel->array;
+ bf=(b=workbin->array)+workbin->size;
+ do *b = (*o++ == 1); while(++b<bf);
+ workbin=gal_binary_dilate(workbin, 1, 1, 1);
+ gal_binary_fill_holes(workbin, 1, p->detgrowmaxholesize);
+
+ /* Get the labeled image. */
+ numexpanded=gal_binary_connected_components(workbin, &p->olabel,
+ workbin->ndim);
+
+ /* Set all the input's blank pixels to blank in the labeled and
+ binary arrays. */
+ if( gal_blank_present(p->input, 1) )
+ {
+ b=workbin->array;
+ i=p->input->array;
+ of=(o=p->olabel->array)+p->olabel->size;
+ do
+ {
+ if(isnan(*i++))
+ {
+ *o=GAL_BLANK_INT32;
+ *b=GAL_BLANK_UINT8;
+ }
+ ++b;
+ }
+ while(++o<of);
+ }
+
+ /* Clean up. */
+ gal_data_free(diffuseindexs);
}
/* Clean up and return */
gal_data_free(p->expand_thresh);
gal_data_free(exp_thresh_full);
- gal_data_free(diffuseindexs);
- return numexpanded;
+ return numexpanded ? numexpanded : GAL_BLANK_SIZE_T;
}
@@ -1028,7 +1038,7 @@ detection(struct noisechiselparams *p)
char *msg;
gal_data_t *workbin;
struct timeval t0, t1;
- size_t num_true_initial;
+ size_t num_true_initial, num_expanded;
/* Report for the user. */
if(!p->cp.quiet)
@@ -1081,7 +1091,14 @@ detection(struct noisechiselparams *p)
final number of detections. */
if(!p->cp.quiet) gettimeofday(&t1, NULL);
if(p->detgrowquant!=1.0f)
- num_true_initial=detection_quantile_expand(p, workbin);
+ {
+ num_expanded=detection_quantile_expand(p, workbin);
+ if(num_expanded!=GAL_BLANK_SIZE_T)
+ num_true_initial=num_expanded;
+ }
+
+
+ /* Update the user on the progress, if necessary. */
if(!p->cp.quiet)
{
if(p->detgrowquant==1.0f)
@@ -1092,9 +1109,18 @@ detection(struct noisechiselparams *p)
}
else
{
- if( asprintf(&msg, "%zu detections after growth to %.3f quantile.",
- num_true_initial, p->detgrowquant)<0 )
- error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ if(num_expanded==GAL_BLANK_SIZE_T)
+ {
+ if(asprintf(&msg, "%zu detections (no growth to %.3f "
+ "quantile).", num_true_initial, p->detgrowquant)<0)
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
+ else
+ {
+ if( asprintf(&msg, "%zu detections after growth to %.3f "
+ "quantile.", num_true_initial, p->detgrowquant)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+ }
}
gal_timing_report(&t1, msg, 2);
free(msg);
diff --git a/doc/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index 8d8f500..5d21881 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -1,8 +1,10 @@
People who's help must be acknowledged in the next release.
+Nima Dehdilani
Antonio Diaz Diaz
Guillaume Mahler
Ole Streicher
Michel Tallon
Juan C. Tello
Éric Thiébaut
+Sara Yousefi