gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master b3a3480: NoiseChisel doing final growth with m


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master b3a3480: NoiseChisel doing final growth with max connectivity
Date: Wed, 1 Nov 2017 17:52:26 -0400 (EDT)

branch: master
commit b3a348024665d93425e1493e0794fbe6472ac9d9
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    NoiseChisel doing final growth with max connectivity
    
    When doing the final growth of true clumps, until now, NoiseChisel used
    4-connectivity to expand the clumps. However, earlier, it defined the
    detections using 8-connectivity. As a result, in some rare cases where the
    detection had an 8-connected region to the main body with no true clump in
    it, that region was left unlabeled after the final growth and would somehow
    get a wrong label (similar to another object in a completely separate part
    of the image).
    
    The main cause for this choice was that we want the initial growth of true
    clumps to be based on 4-connectivity to have 8-connected rivers. So, to fix
    the problem, With this commit, a `connectivity' argument is given to
    `clumps_grow'. Thanks to this argument, now, it is possible to ask the
    function to use 8 connectivity when we want to cover the full area (don't
    want rivers) and 4-connectivity when we want rivers.
    
    Also, a small sanity check was added to `GAL_DIMENSION_NEIGHBOR_OP' to make
    sure the connectivity value is reasonable.
    
    This fixes bug #52327.
---
 NEWS                           |  1 +
 bin/noisechisel/clumps.c       | 10 +++++++---
 bin/noisechisel/clumps.h       |  3 ++-
 bin/noisechisel/detection.c    |  8 +++++---
 bin/noisechisel/segmentation.c | 15 ++++++++++++---
 lib/gnuastro/dimension.h       |  6 ++++++
 6 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/NEWS b/NEWS
index 6f37e66..23b3928 100644
--- a/NEWS
+++ b/NEWS
@@ -143,6 +143,7 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
 
   MakeCatalog crash in upper-limit with full size label (bug #52281).
 
+  NoiseChisel leaving unlabeld regions after clump growth (bug #52327).
 
 
 
diff --git a/bin/noisechisel/clumps.c b/bin/noisechisel/clumps.c
index 6b92b5d..954fa02 100644
--- a/bin/noisechisel/clumps.c
+++ b/bin/noisechisel/clumps.c
@@ -542,10 +542,13 @@ clumps_grow_prepare_final(struct clumps_thread_params 
*cltprm)
 
      diffuseindexs: The indexs of the pixels that must be grown.
 
-     withrivers: as described abvoe.
+     withrivers: as described above.
+
+     connectivity: connectivity to define neighbors for growth.
 */
 void
-clumps_grow(gal_data_t *labels, gal_data_t *diffuseindexs, int withrivers)
+clumps_grow(gal_data_t *labels, gal_data_t *diffuseindexs, int withrivers,
+            int connectivity)
 {
   int searchngb;
   size_t *diarray=diffuseindexs->array;
@@ -595,7 +598,8 @@ clumps_grow(gal_data_t *labels, gal_data_t *diffuseindexs, 
int withrivers)
              in a 2D image). Note that since this macro has multiple loops
              within it, we can't use break. We'll use a variable instead. */
           searchngb=1;
-          GAL_DIMENSION_NEIGHBOR_OP(*s, labels->ndim, labels->dsize, 1, dinc,
+          GAL_DIMENSION_NEIGHBOR_OP(*s, labels->ndim, labels->dsize,
+                                    connectivity, dinc,
             {
               if(searchngb)
                 {
diff --git a/bin/noisechisel/clumps.h b/bin/noisechisel/clumps.h
index 1557955..0c300fa 100644
--- a/bin/noisechisel/clumps.h
+++ b/bin/noisechisel/clumps.h
@@ -79,7 +79,8 @@ void
 clumps_grow_prepare_final(struct clumps_thread_params *cltprm);
 
 void
-clumps_grow(gal_data_t *labels, gal_data_t *diffuseindexs, int withrivers);
+clumps_grow(gal_data_t *labels, gal_data_t *diffuseindexs, int withrivers,
+            int connectivity);
 
 void
 clumps_true_find_sn_thresh(struct noisechiselparams *p);
diff --git a/bin/noisechisel/detection.c b/bin/noisechisel/detection.c
index 857dad3..f6f7b76 100644
--- a/bin/noisechisel/detection.c
+++ b/bin/noisechisel/detection.c
@@ -112,7 +112,8 @@ detection_initial(struct noisechiselparams *p)
 
 
   /* Label the connected components. */
-  p->numinitialdets=gal_binary_connected_components(p->binary, &p->olabel, 1);
+  p->numinitialdets=gal_binary_connected_components(p->binary, &p->olabel,
+                                                    p->binary->ndim);
   if(p->detectionname)
     {
       p->olabel->name="OPENED_AND_LABELED";
@@ -969,7 +970,7 @@ detection_quantile_expand(struct noisechiselparams *p, 
gal_data_t *workbin)
   while(++o<of);
 
   /* Expand the detections. */
-  clumps_grow(p->olabel, diffuseindexs, 0);
+  clumps_grow(p->olabel, diffuseindexs, 0, p->olabel->ndim);
 
   /* Only keep the 1 valued pixels in the binary array and fill its
      holes. */
@@ -980,7 +981,8 @@ detection_quantile_expand(struct noisechiselparams *p, 
gal_data_t *workbin)
   gal_binary_fill_holes(workbin, 1, p->detgrowmaxholesize);
 
   /* Get the labeled image. */
-  numexpanded=gal_binary_connected_components(workbin, &p->olabel, 8);
+  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. */
diff --git a/bin/noisechisel/segmentation.c b/bin/noisechisel/segmentation.c
index 1c4bc15..74908ef 100644
--- a/bin/noisechisel/segmentation.c
+++ b/bin/noisechisel/segmentation.c
@@ -472,7 +472,7 @@ segmentation_on_threads(void *in_prm)
           /* Grow the true clumps over the detection. */
           clumps_grow_prepare_initial(&cltprm);
           if(cltprm.diffuseindexs->size)
-            clumps_grow(p->olabel, cltprm.diffuseindexs, 1);
+            clumps_grow(p->olabel, cltprm.diffuseindexs, 1, 1);
           if(clprm->step==3)
             { gal_data_free(cltprm.diffuseindexs); continue; }
 
@@ -507,8 +507,17 @@ segmentation_on_threads(void *in_prm)
                  grown. */
               clumps_grow_prepare_final(&cltprm);
 
-              /* Cover the whole area. */
-              clumps_grow(p->olabel, cltprm.diffuseindexs, 0);
+              /* Cover the whole area (using maximum connectivity to not
+                 miss any pixels). */
+              clumps_grow(p->olabel, cltprm.diffuseindexs, 0,
+                          p->olabel->ndim);
+
+              /* Make sure all diffuse pixels are labeled. */
+              if(cltprm.diffuseindexs->size)
+                error(EXIT_FAILURE, 0, "a bug! Please contact us at %s to "
+                      "fix it. %zu pixels of detection %zu have not been "
+                      "labeled (as an object)", PACKAGE_BUGREPORT,
+                      cltprm.diffuseindexs->size, cltprm.id);
             }
           gal_data_free(cltprm.diffuseindexs);
           if(clprm->step==5) { gal_data_free(cltprm.clumptoobj); continue; }
diff --git a/lib/gnuastro/dimension.h b/lib/gnuastro/dimension.h
index 314891e..4d81db0 100644
--- a/lib/gnuastro/dimension.h
+++ b/lib/gnuastro/dimension.h
@@ -188,6 +188,12 @@ gal_dimension_dist_manhattan(size_t *a, size_t *b, size_t 
ndim);
     size_t nind, gdn_ind=index;                                         \
     uint8_t gdn_D, *gdn_is_start, *gdn_is_end, *gdn_is_edge, gdn_one=1; \
                                                                         \
+    /* A small sanity check. */                                         \
+    if(connectivity>ndim)                                               \
+      error(EXIT_FAILURE, 0, "%s: connectivity value (%d) is larger "   \
+            "than the number of dimensions (%zu)", __func__,            \
+            (int)connectivity, ndim);                                   \
+                                                                        \
     /* Initialize the start/end. */                                     \
     gdn_is_start=(uint8_t *)(&gdn_bitstr);                              \
     gdn_is_end=(uint8_t *)(&gdn_bitstr)+1;                              \



reply via email to

[Prev in Thread] Current Thread [Next in Thread]