Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
biashistogram.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003, 2004 (see file CONTACTS for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #include <Base/Image/ImageIO.hh>
26 #include <Image/HistogramImage.hh>
27 
28 using namespace BIAS;
29 using namespace std;
30 
31 
32 /**
33  @file
34  @ingroup g_tools
35  @brief Detects a color histogram and writes to file hist.txt, see biashistogram.cpp
36  @author ischiller
37 */
38 HistogramImage hist;
39 bool loga = false;
40 bool ignore_negative = true;
41 Image<float> imf;
42 
43 void Draw()
44 {
45  hist.ZeroHist(0);
46  if (ignore_negative){
47  vector<float> v;
48  float *id = imf.GetImageData();
49  float *end = id + imf.GetPixelCount();
50  while (id<end){
51  if (*id>=0.0) v.push_back(*id);
52  id++;
53  }
54  hist.AddHist(v);
55  } else {
56  hist.AddHist(imf);
57  }
58  hist.FillImageWithConstValue(255);
59  if (loga) hist.DrawLog();
60  else hist.Draw();
61 }
62 
63 int main(int argc, char *argv[])
64 {
65  const int num_bins = 200;
66  const int num_hist = 1;
67  hist.InitHist(num_bins, num_hist);
68  hist.SetColor(0,0,0,0);
69  hist.AddDebugLevel("D_HIST_BIN");
70 
71 
72  ImageBase im;
73 
74  if (argc!=2){
75  cerr << argv[0] << " <image>\n";
76  return -1;
77  }
78 
79  if (ImageIO::Load(argv[1], im)!=0){
80  cerr << "error loading image "<<argv[1]<<endl;
81  return -2;
82  }
83 
84  imf = Image<float>(im);
85  if (imf.IsEmpty()){
86  cerr << "only for float images"<<endl;
87  return -3;
88  }
89  hist.AddHist(imf);
90  Draw();
91 
92  hist.WriteASCII("hist.txt");
93 
94  return 0;
95 }
void AddDebugLevel(const long int lv)
Definition: Debug.hh:355
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
int InitHist(unsigned int bincount=256, unsigned int histcount=1)
reserves the internal data structures for histcount histograms with bincount bins in each in one imag...
int Draw()
actually draws histogram(s) from the internal data structures
void WriteASCII(std::ostream &os=std::cout)
writes ascii data to stream, can be used later e.g. with gnuplot
int ZeroHist(unsigned int hist=0)
zeros existing histogram
int AddHist(const Image< StorageType > &Image, unsigned int hist=0)
calculates the histogram of image and adds them to the internal data structures
void FillImageWithConstValue(StorageType Value)
fill grey images
Definition: Image.cpp:456
Class for easy histogram image generation.
int SetColor(unsigned char R, unsigned char G, unsigned char B, unsigned int hist=0)
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:137
int DrawLog()
actually draws histogram(s) from the internal data structures uses a logarithmic y axis ...
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
Definition: ImageIO.cpp:141
unsigned long int GetPixelCount() const
returns number of pixels in image
Definition: ImageBase.hh:422
This is the base class for images in BIAS.
Definition: ImageBase.hh:102