GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/unrrdu/histax.c Lines: 19 36 52.8 %
Date: 2017-05-26 Branches: 1 16 6.2 %

Line Branch Exec Source
1
/*
2
  Teem: Tools to process and visualize scientific data and images             .
3
  Copyright (C) 2013, 2012, 2011, 2010, 2009  University of Chicago
4
  Copyright (C) 2008, 2007, 2006, 2005  Gordon Kindlmann
5
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah
6
7
  This library is free software; you can redistribute it and/or
8
  modify it under the terms of the GNU Lesser General Public License
9
  (LGPL) as published by the Free Software Foundation; either
10
  version 2.1 of the License, or (at your option) any later version.
11
  The terms of redistributing and/or modifying this software also
12
  include exceptions to the LGPL that facilitate static linking.
13
14
  This library is distributed in the hope that it will be useful,
15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
  Lesser General Public License for more details.
18
19
  You should have received a copy of the GNU Lesser General Public License
20
  along with this library; if not, write to Free Software Foundation, Inc.,
21
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
*/
23
24
#include "unrrdu.h"
25
#include "privateUnrrdu.h"
26
27
#define INFO "Replace each scanline along an axis with its histogram"
28
static const char *_unrrdu_histaxInfoL =
29
  (INFO
30
   ".\n "
31
   "* Uses nrrdHistoAxis");
32
33
int
34
unrrdu_histaxMain(int argc, const char **argv, const char *me,
35
                  hestParm *hparm) {
36
2
  hestOpt *opt = NULL;
37
1
  char *out, *err;
38
1
  Nrrd *nin, *nout;
39
1
  char *minStr, *maxStr;
40
1
  int type, pret, blind8BitRange;
41
1
  unsigned int axis, bins;
42
  airArray *mop;
43
  NrrdRange *range;
44
45
1
  OPT_ADD_AXIS(axis, "axis to histogram along");
46
1
  hestOptAdd(&opt, "b,bin", "bins", airTypeUInt, 1, 1, &bins, NULL,
47
             "# of bins in histogram");
48
1
  OPT_ADD_TYPE(type, "output type", "uchar");
49
  /* HEY copy and paste from unrrdu/quantize.c */
50
1
  hestOptAdd(&opt, "min,minimum", "value", airTypeString, 1, 1,
51
             &minStr, "nan",
52
             "The value to map to zero, given explicitly as a regular number, "
53
             "*or*, if the number is given with a \"" NRRD_MINMAX_PERC_SUFF
54
             "\" suffix, this "
55
             "minimum is specified in terms of the percentage of samples in "
56
             "input that are lower. "
57
             "\"0" NRRD_MINMAX_PERC_SUFF "\" means the "
58
             "lowest input value is used, "
59
             "\"1" NRRD_MINMAX_PERC_SUFF "\" means that the "
60
             "1% of the lowest values are all mapped to zero. "
61
             "By default (not using this option), the lowest input value is "
62
             "used.");
63
1
  hestOptAdd(&opt, "max,maximum", "value", airTypeString, 1, 1,
64
             &maxStr, "nan",
65
             "The value to map to the highest unsigned integral value, given "
66
             "explicitly as a regular number, "
67
             "*or*, if the number is given with "
68
             "a \"" NRRD_MINMAX_PERC_SUFF "\" suffix, "
69
             "this maximum is specified "
70
             "in terms of the percentage of samples in input that are higher. "
71
             "\"0" NRRD_MINMAX_PERC_SUFF "\" means the highest input value is "
72
             "used, which is also the default "
73
             "behavior (same as not using this option).");
74
1
  hestOptAdd(&opt, "blind8", "bool", airTypeBool, 1, 1, &blind8BitRange,
75
1
             nrrdStateBlind8BitRange ? "true" : "false",
76
             "Whether to know the range of 8-bit data blindly "
77
             "(uchar is always [0,255], signed char is [-128,127]).");
78
1
  OPT_ADD_NIN(nin, "input nrrd");
79
1
  OPT_ADD_NOUT(out, "output nrrd");
80
81
1
  mop = airMopNew();
82
1
  airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways);
83
84
2
  USAGE(_unrrdu_histaxInfoL);
85
  PARSE();
86
  airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);
87
88
  range = nrrdRangeNew(AIR_NAN, AIR_NAN);
89
  airMopAdd(mop, range, (airMopper)nrrdRangeNix, airMopAlways);
90
  nout = nrrdNew();
91
  airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);
92
  if (nrrdRangePercentileFromStringSet(range, nin, minStr, maxStr,
93
                                       10*bins /* HEY magic */,
94
                                       blind8BitRange)
95
      || nrrdHistoAxis(nout, nin, range, axis, bins, type)) {
96
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
97
    fprintf(stderr, "%s: error doing axis histogramming:\n%s", me, err);
98
    airMopError(mop);
99
    return 1;
100
  }
101
102
  SAVE(out, nout, NULL);
103
104
  airMopOkay(mop);
105
  return 0;
106
1
}
107
108
UNRRDU_CMD(histax, INFO);