gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master cf188d0: ConvertType: forced range also when u


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master cf188d0: ConvertType: forced range also when using color maps
Date: Tue, 15 Jan 2019 15:15:51 -0500 (EST)

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

    ConvertType: forced range also when using color maps
    
    Until now, `--flminbyte' and `--flmaxbyte' were used to force the range of
    conversion to color channels (even if the range is beyond the limits of the
    dataset). With the introduction of color maps recently, it is also
    necessary to force a range on non-byte datasets. It is thus necessary to
    use a more generic name.
    
    With this commit, it is now also possible to force the range in
    single-input-channel, but color-mapped outputs.
---
 NEWS                    |  7 +++++++
 bin/convertt/args.h     | 14 +++++++-------
 bin/convertt/color.c    | 46 ++++++++++++++++++++++++++++++++++------------
 bin/convertt/convertt.c |  4 ++--
 bin/convertt/main.h     |  4 ++--
 bin/convertt/ui.h       |  4 ++--
 doc/gnuastro.texi       | 19 ++++++++++---------
 7 files changed, 64 insertions(+), 34 deletions(-)

diff --git a/NEWS b/NEWS
index b4aad07..0dd41c5 100644
--- a/NEWS
+++ b/NEWS
@@ -45,6 +45,13 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
 
 ** Changed features
 
+  ConvertType:
+   --forcemin & --forcemax: until now, `--flminbyte' and `--flmaxbyte' were
+     used to force the range of conversion to color channels (even if the
+     range is beyond the limits of the dataset). With the introduction of
+     color maps in Gnuastro 0.8, it is also necessary to force a range on
+     non-byte datasets. It is thus necessary to use a more generic name.
+
 ** Bugs fixed
   bug #55313: Fits program writing --write values in reverse order
   bug #55333: Fits program crash when --write or --update have no value.
diff --git a/bin/convertt/args.h b/bin/convertt/args.h
index 52f95d6..558df83 100644
--- a/bin/convertt/args.h
+++ b/bin/convertt/args.h
@@ -161,13 +161,13 @@ struct argp_option program_options[] =
       GAL_OPTIONS_NOT_SET
     },
     {
-      "flminbyte",
-      UI_KEY_FLMINBYTE,
+      "forcemin",
+      UI_KEY_FORCEMIN,
       0,
       0,
-      "Set value of fluxlow as the minimum byte value.",
+      "Force --fluxmin, even when smaller than minimum.",
       UI_GROUP_FLUX,
-      &p->flminbyte,
+      &p->forcemin,
       GAL_OPTIONS_NO_ARG_TYPE,
       GAL_OPTIONS_RANGE_0_OR_1,
       GAL_OPTIONS_NOT_MANDATORY,
@@ -175,12 +175,12 @@ struct argp_option program_options[] =
     },
     {
       "fhmaxbyte",
-      UI_KEY_FHMAXBYTE,
+      UI_KEY_FORCEMAX,
       0,
       0,
-      "Set value of fluxhigh as the maximum byte value.",
+      "Force --fluxmax, even when smaller than maximum.",
       UI_GROUP_FLUX,
-      &p->fhmaxbyte,
+      &p->forcemax,
       GAL_OPTIONS_NO_ARG_TYPE,
       GAL_OPTIONS_RANGE_0_OR_1,
       GAL_OPTIONS_NOT_MANDATORY,
diff --git a/bin/convertt/color.c b/bin/convertt/color.c
index a7419b4..72806ee 100644
--- a/bin/convertt/color.c
+++ b/bin/convertt/color.c
@@ -28,6 +28,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <stdlib.h>
 
 #include <gnuastro/data.h>
+#include <gnuastro/statistics.h>
 
 #include "main.h"
 
@@ -40,6 +41,33 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 /***********************************************************************/
 /**************            From mono-channel           *****************/
 /***********************************************************************/
+static void
+color_min_max(struct converttparams *p, float *value, int min0max1)
+{
+  gal_data_t *tmp;
+  gal_data_t *given  = min0max1 ? p->fluxhigh : p->fluxlow;
+  uint8_t fixedlimit = min0max1 ? p->forcemax : p->forcemin;
+
+  /* Find the value to write. */
+  if(fixedlimit && given)
+    tmp=gal_data_copy_to_new_type(given, GAL_TYPE_FLOAT32);
+  else
+    {
+      tmp = ( min0max1
+              ? gal_statistics_maximum(p->chll)
+              : gal_statistics_minimum(p->chll) );
+      tmp=gal_data_copy_to_new_type_free(tmp, GAL_TYPE_FLOAT32);
+    }
+  *value=((float *)(tmp->array))[0];
+
+  /* Clean up. */
+  gal_data_free(tmp);
+}
+
+
+
+
+
 /* This algorithm is a translation of the primary algorithm in this page:
 
https://stackoverflow.com/questions/3018313/algorithm-to-convert-rgb-to-hsv-and-hsv-to-rgb-in-range-0-255-for-both
 */
 void
@@ -66,13 +94,10 @@ color_from_mono_hsv(struct converttparams *p)
     error(EXIT_FAILURE, 0, "the maximum angle (%g) must be smaller than "
           "360", h_max);
 
-  /* Convert the dataset to floating point, then change its range to the
-     given angle values. */
-  gal_type_min(GAL_TYPE_FLOAT32, &max);
-  gal_type_max(GAL_TYPE_FLOAT32, &min);
+  /* Set the range of values and convert the dataset to float. */
+  color_min_max(p, &min, 0);
+  color_min_max(p, &max, 1);
   channel=gal_data_copy_to_new_type_free(p->chll, GAL_TYPE_FLOAT32);
-  fp=(f=channel->array)+channel->size;
-  do {if(*f<min) min=*f; if(*f>max) max=*f;} while(++f<fp);
 
   /* Allocate the three datasets to keep the RGB colors. */
   R=gal_data_alloc(NULL, GAL_TYPE_FLOAT32, channel->ndim,
@@ -155,13 +180,10 @@ color_from_mono_sls(struct converttparams *p)
   gal_data_t *R, *G, *B, *channel;
   float *r, *g, *b, *f, *fp, min, max;
 
-  /* Convert the dataset to floating point, then find its minimum and
-     maximum values. */
-  gal_type_min(GAL_TYPE_FLOAT32, &max);
-  gal_type_max(GAL_TYPE_FLOAT32, &min);
+  /* Set the range, then convert the dataset to floating point. */
+  color_min_max(p, &min, 0);
+  color_min_max(p, &max, 1);
   channel=gal_data_copy_to_new_type_free(p->chll, GAL_TYPE_FLOAT32);
-  fp=(f=channel->array)+channel->size;
-  do {if(*f<min) min=*f; if(*f>max) max=*f;} while(++f<fp);
 
   /* Allocate the three datasets to keep the RGB colors. */
   R=gal_data_alloc(NULL, GAL_TYPE_FLOAT32, channel->ndim,
diff --git a/bin/convertt/convertt.c b/bin/convertt/convertt.c
index 0f22c08..3ffb66d 100644
--- a/bin/convertt/convertt.c
+++ b/bin/convertt/convertt.c
@@ -222,14 +222,14 @@ convertt_scale_to_uchar(struct converttparams *p)
      maximum and minimum values in the image.*/
   if(p->fluxlow || p->fluxhigh)
     {
-      if(p->flminbyte)
+      if(p->forcemin)
         {
           /* Convert the fluxlow value to float and put it in min. */
           copied=gal_data_copy_to_new_type(p->fluxlow, GAL_TYPE_FLOAT32);
           min = *((float *)(copied->array));
           gal_data_free(copied);
         }
-      if(p->fhmaxbyte)
+      if(p->forcemax)
         {
           /* Convert the fluxhigh value to float and put it in min. */
           copied=gal_data_copy_to_new_type(p->fluxhigh, GAL_TYPE_FLOAT32);
diff --git a/bin/convertt/main.h b/bin/convertt/main.h
index efca953..6b69968 100644
--- a/bin/convertt/main.h
+++ b/bin/convertt/main.h
@@ -90,8 +90,8 @@ struct converttparams
   char          *fluxlowstr;  /* Lower flux truncation value.          */
   char         *fluxhighstr;  /* Higher flux truncation value.         */
   uint8_t           maxbyte;  /* Maximum byte value.                   */
-  uint8_t         flminbyte;  /* fluxlow is minimum byte.              */
-  uint8_t         fhmaxbyte;  /* fluxhigh is maximum byte.             */
+  uint8_t          forcemin;  /* fluxlow is minimum.                   */
+  uint8_t          forcemax;  /* fluxhigh is maximum.                  */
   char           *changestr;  /* String of change values.              */
   uint8_t  changeaftertrunc;  /* First convert, then truncate.         */
   uint8_t            invert;  /* ==1: invert the output image.         */
diff --git a/bin/convertt/ui.h b/bin/convertt/ui.h
index 28a523e..c31a8e6 100644
--- a/bin/convertt/ui.h
+++ b/bin/convertt/ui.h
@@ -55,8 +55,8 @@ enum option_keys_enum
   UI_KEY_FLUXLOW             = 'L',
   UI_KEY_FLUXHIGH            = 'H',
   UI_KEY_MAXBYTE             = 'm',
-  UI_KEY_FLMINBYTE           = 'A',
-  UI_KEY_FHMAXBYTE           = 'B',
+  UI_KEY_FORCEMIN            = 'A',
+  UI_KEY_FORCEMAX            = 'B',
   UI_KEY_CHANGE              = 'c',
   UI_KEY_CHANGEAFTERTRUNC    = 'C',
   UI_KEY_INVERT              = 'i',
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 34fc7bd..1225654 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -11084,17 +11084,18 @@ the maximum value. By doing so you will decrease the 
dynamic range. It can
 be useful if you plan to use those values for other purposes.
 
 @item -A INT
address@hidden --flminbyte=INT
-If the lowest pixel value in the input channels is larger than the value to
address@hidden, then that input value will be redundant. In some
-situations it might be necessary to set the minimum byte value (0) to
-correspond to that flux even if the data do not reach that value. With this
-option you can do this. Note that if the minimum pixel value is smaller
-than @option{--fluxlow}, then this option is redundant.
address@hidden --forcemin=INT
+Enforce the value of @option{--fluxlow} (when its given), even if its
+smaller than the minimum of the dataset and the output is format supporting
+color. This is particularly useful when you are converting a number of
+images to a common image format like JPEG or PDF with a single command and
+want them all to have the same range of colors, independent of the contents
+of the dataset. Note that if the minimum value is smaller than
address@hidden, then this option is redundant.
 
 @item -B INT
address@hidden --fhmaxbyte=INT
-See @option{--flminbyte}.
address@hidden --forcemax=INT
+Similar to @option{--forcemin}, but for the maximum.
 
 
 @item -i



reply via email to

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