Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Threshold.hxx

Go to the documentation of this file.
00001 /* ImLib3D
00002  * Copyright (c) 2001, ULP-IPB Strasbourg.
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or (at
00007  * your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00019 #ifndef _Threshold_hxx
00020 #define _Threshold_hxx
00021 
00022 #include<ImLib3D/ImageStats.hpp>
00023 
00024 
00025 template <class ImageType>
00026 void
00027 IP3D::OtsuThresholds(const ImageType& src, Mask3D& res,int nbClasses,vector<double> *pthresholds,int nbBins)
00028 {
00029     res.Resize(src.Size());
00030     // inplace
00031     
00032     vector<float> values;
00033     typename ImageType::const_iteratorFast p;
00034     for(p=src.begin();p!=src.end();++p){values.push_back((float)*p);}
00035 
00036     ProbabilityDistribution dist;
00037     dist.SetWithSamples(values,nbBins);
00038 
00039     vector<double> thresholds;
00040     dist.OtsuThreshholds(nbClasses,thresholds);
00041 
00042     mprintf("OtsuThreshholds::Apply: thresholds:\n");
00043     for(uint i=0;i<thresholds.size();i++)
00044     {
00045         mprintf("   thresholds:%d:%f\n",i,thresholds[i]);
00046     }
00047 
00048     Mask3D::iteratorFast rp;
00049     for(p=src.begin(),rp=res.begin();rp!=res.end();p++,rp++)
00050     {
00051         *rp=0;
00052         for(uint i=0;i<thresholds.size();i++){if(*p>=thresholds[i]){*rp=i+1;}}
00053     }
00054     if(pthresholds){*pthresholds=thresholds;}
00055 }
00056 
00057 
00058 
00059 
00060 #endif // _Threshold_hxx

Generated on Fri Jun 17 13:36:07 2005 for ImLib3D by  doxygen 1.4.2