gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 5d6ff95: Segment: labeled pixels set to blank


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 5d6ff95: Segment: labeled pixels set to blank when input has blank values
Date: Fri, 2 Aug 2019 11:22:41 -0400 (EDT)

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

    Segment: labeled pixels set to blank when input has blank values
    
    Until now, when the input has blanks but the labeled image doesn't (or has
    blanks in other places), the inconsistency between the two can cause a
    crash, something like this:
    
    astsegment: a bug! Please contact us at address@hidden to fix it. 1
    pixels of detection 1 have not been labeled (as an object)
    
    This happens is because on the labeled image pixels may be connected, but
    when accounting for the blank pixels of the input, they maybe separate
    regions.
    
    With this commit, after Segment reads the labeled image, if the input has
    blank values, they are set to blank on the labeled image is well.
    
    This bug was reported by Roberto Baena Gallé.
    
    This fixes bug #56709.
---
 NEWS             | 30 ++++++++++--------------------
 bin/segment/ui.c | 12 +++++++++++-
 lib/label.c      |  9 +++++----
 3 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/NEWS b/NEWS
index 3f1247c..4cb13ae 100644
--- a/NEWS
+++ b/NEWS
@@ -119,25 +119,15 @@ See the end of the file for license conditions.
    - gal_statistics_outlier_flat_cfp: Improved implementation with new API.
    - New `quietmmap' argument added to the following functions (as the
      argument following `minmapsize'). For more, see the description above
-     of the new similarly named option to all programs.
-       - gal_array_read
-       - gal_array_read_to_type
-       - gal_array_read_one_ch
-       - gal_array_read_one_ch_to_type
-       - gal_data_alloc
-       - gal_data_initialize
-       - gal_fits_img_read
-       - gal_fits_img_read_to_type
-       - gal_fits_img_read_kernel
-       - gal_fits_tab_read
-       - gal_jpeg_read
-       - gal_label_indexs
-       - gal_list_data_add_alloc
-       - gal_match_coordinates
-       - gal_pointer_allocate_mmap
-       - gal_table_read
-       - gal_tiff_read
-       - gal_txt_image_read
+     of the new similarly named option to all programs: `gal_array_read'
+     `gal_array_read_to_type', `gal_array_read_one_ch',
+     `gal_array_read_one_ch_to_type', `gal_data_alloc',
+     `gal_data_initialize', `gal_fits_img_read',
+     `gal_fits_img_read_to_type', `gal_fits_img_read_kernel',
+     `gal_fits_tab_read', `gal_jpeg_read', `gal_label_indexs',
+     `gal_list_data_add_alloc', `gal_match_coordinates',
+     `gal_pointer_allocate_mmap', `gal_table_read', `gal_tiff_read' and
+     `gal_txt_image_read'
 
   Book:
    - The two larger tutorials ("General program usage tutorial", and
@@ -161,7 +151,7 @@ See the end of the file for license conditions.
   bug #56635: Update tutorial 3 with bug-fixed NoiseChisel.
   bug #56662: Converting -R to -Wl,-R causes a crash in configure on macOS.
   bug #56671: Bad sorting with asttable if nan is present.
-
+  bug #56709: Segment crash when input has blanks, but labels don't.
 
 
 
diff --git a/bin/segment/ui.c b/bin/segment/ui.c
index e41b651..782826b 100644
--- a/bin/segment/ui.c
+++ b/bin/segment/ui.c
@@ -405,7 +405,7 @@ static void
 ui_prepare_inputs(struct segmentparams *p)
 {
   int32_t *i, *ii;
-  gal_data_t *maxd, *ccin, *ccout=NULL;
+  gal_data_t *maxd, *ccin, *blankflag, *ccout=NULL;
 
   /* Read the input as a single precision floating point dataset. */
   p->input = gal_array_read_one_ch_to_type(p->inputname, p->cp.hdu,
@@ -483,6 +483,16 @@ ui_prepare_inputs(struct segmentparams *p)
               p->dhdu, gal_type_name(p->olabel->type, 1),
               p->useddetectionname, p->dhdu);
 
+      /* If the input has blank values, set them to blank values in the
+         labeled image too. It doesn't matter if the labeled image has
+         blank pixels that aren't blank on the input image. */
+      if(gal_blank_present(p->input, 1))
+        {
+          blankflag=gal_blank_flag(p->input);
+          gal_blank_flag_apply(p->olabel, blankflag);
+          gal_data_free(blankflag);
+        }
+
       /* Get the maximum value of the input (total number of labels if they
          are separate). If the maximum is 1 (the image is a binary image),
          then apply the connected components algorithm to separate the
diff --git a/lib/label.c b/lib/label.c
index b6f16a6..791b8e2 100644
--- a/lib/label.c
+++ b/lib/label.c
@@ -914,10 +914,11 @@ gal_label_grow_indexs(gal_data_t *labels, gal_data_t 
*indexs, int withrivers,
   /* The basic idea is this: after growing, not all the blank pixels are
      necessarily filled, for example the pixels might belong to two regions
      above the growth threshold. So the pixels in between them (which are
-     below the threshold will not ever be able to get a label). Therefore,
-     the safest way we can terminate the loop of growing the objects is to
-     stop it when the number of pixels left to fill in this round
-     (thisround) equals the number of blanks.
+     below the threshold will not ever be able to get a label, even if they
+     are in the indexs list). Therefore, the safest way we can terminate
+     the loop of growing the objects is to stop it when the number of
+     pixels left to fill in this round (thisround) equals the number of
+     blanks.
 
      To start the loop, we set `thisround' to one more than the number of
      indexed pixels. Note that it will be corrected immediately after the



reply via email to

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