/home/oan/prosjekt/gotools/segmentation/gpl_distro/lsseg_1.0_gpl/src/Histogram.C

Go to the documentation of this file.
00001 //===========================================================================
00002 // The Level-Set Segmentation Library (LSSEG)
00003 //
00004 //
00005 // Copyright (C) 2000-2005 SINTEF ICT, Applied Mathematics, Norway.
00006 //
00007 // This program is free software; you can redistribute it and/or          
00008 // modify it under the terms of the GNU General Public License            
00009 // as published by the Free Software Foundation version 2 of the License. 
00010 //
00011 // This program is distributed in the hope that it will be useful,        
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of         
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          
00014 // GNU General Public License for more details.                           
00015 //
00016 // You should have received a copy of the GNU General Public License      
00017 // along with this program; if not, write to the Free Software            
00018 // Foundation, Inc.,                                                      
00019 // 59 Temple Place - Suite 330,                                           
00020 // Boston, MA  02111-1307, USA.                                           
00021 //
00022 // Contact information: e-mail: tor.dokken@sintef.no                      
00023 // SINTEF ICT, Department of Applied Mathematics,                         
00024 // P.O. Box 124 Blindern,                                                 
00025 // 0314 Oslo, Norway.                                                     
00026 // 
00027 //
00028 // Other licenses are also available for this software, notably licenses
00029 // for:
00030 // - Building commercial software.                                        
00031 // - Building software whose source code you wish to keep private.        
00032 //
00033 //===========================================================================
00034 //===========================================================================
00035 //                                                                           
00036 // File: Histogram.C                                                         
00037 //                                                                           
00038 // Created: Fri Mar 31 17:54:22 2006                                         
00039 //                                                                           
00040 // Author: Odd A. Andersen <Odd.Andersen@sintef.no>
00041 //                                                                           
00042 // Revision: $Id: Histogram.C,v 1.5 2006/11/13 02:29:28 oan Exp $
00043 //                                                                           
00044 // Description:
00047 //                                                                           
00048 //===========================================================================
00049 
00050 #include "Histogram.h"
00051 #include "cimg_dependent.h"
00052 
00053 using namespace std;
00054 
00055 namespace lsseg {
00056 
00057 void Histogram::write(std::ostream& os) const
00058 {
00059     // writing number of bins
00060     os << numBins() << endl;
00061 
00062     // writing range
00063     os << rangeMin() << " " << rangeMax() << endl;
00064 
00065     // writing distribution
00066     for (int i = 0; i < numBins(); ++i) {
00067         os << dist_[i] << " ";
00068     }
00069     os << endl;
00070 }
00071 
00072 void Histogram::read(std::istream& is)
00073 {
00074     // reading number of bins
00075     int num_bins ;
00076     is >> num_bins;
00077     dist_.resize(num_bins);
00078 
00079     // reading range
00080     is >> range_min_;
00081     is >> range_max_;
00082 
00083     // reading distribution
00084     for (int i = 0; i < numBins(); ++i) {
00085         is >> dist_[i];
00086     }
00087 
00088     bin_factor_ = double(numBins()) / (rangeMax() - rangeMin());
00089 }
00090 
00091 int Histogram::getBin(double val) const
00092 {
00093     int res = int((val - range_min_) * bin_factor_);
00094     if (res == numBins()) {
00095         --res;
00096     }
00097     return res;
00098 }
00099 
00100 void Histogram::blur(double sigma)
00101 {
00102     if (numBins() > 1) {
00103         blur_1D(&dist_[0], numBins(), sigma);
00104     }
00105 }
00106 
00107 double Histogram::valueFor(double val) const 
00108 {
00109     int ix = getBin(val);
00110     if (ix < 0 || ix >= numBins()) {
00111         return 0; // outside histogram range
00112     }
00113     return dist_[ix] * bin_factor_;
00114 }
00115 
00116 }; // end namespace lsseg

Generated on Tue Nov 28 18:35:47 2006 for lsseg by  doxygen 1.4.7