vtkOtsu Class Reference

#include <vtkOtsu.h>

List of all members.

Public Member Functions

 vtkOtsu ()
virtual ~vtkOtsu ()
double calculateOptimalThreshold (vtkImageData *volume, vtkImageData *region)

Private Member Functions

double getCriteria (double threshold)

Private Attributes

int voxelCount
int * histogram
double * criterias
vtkImageData * volume
vtkImageData * region
double sigmaT
double max

Detailed Description

Definition at line 9 of file vtkOtsu.h.


Constructor & Destructor Documentation

vtkOtsu::vtkOtsu (  ) 

Definition at line 3 of file vtkOtsu.cxx.

References region, and volume.

00003                          {
00004                  volume = NULL;
00005                  region = NULL;
00006         
00007         }

vtkOtsu::~vtkOtsu (  )  [virtual]

Definition at line 9 of file vtkOtsu.cxx.

00009                           {
00010                 
00011         }


Member Function Documentation

double vtkOtsu::calculateOptimalThreshold ( vtkImageData *  volume,
vtkImageData *  region 
)

Definition at line 16 of file vtkOtsu.cxx.

References criterias, getCriteria(), histogram, max, sigmaT, and voxelCount.

00016                                                                                            {
00017 
00018                 this->volume = volume;
00019                 this->region = region;
00020         
00021                 double valor = 0.0;
00022                 double media = 0.0;
00023                 double valorEnRegion = 0.0;
00024             
00025         
00026                 int extent[6];
00027                 
00028                 int index = 0;
00029                 
00030                 
00031                 this->volume->GetExtent(extent);
00032                 this->max=0.0;
00033                 this->sigmaT = 0.0;
00034                 
00035                 //1. Numero de voxeles
00036                 this->voxelCount = 0;
00037                 
00038 
00039 
00040                 //2. Inicializar el histograma y criterios
00041                 this->histogram = new int[1000];
00042                 this->criterias = new double[1000];
00043                 for (index = 0; index <1000; index++){
00044                         this->histogram[index] = 0;
00045                         this->criterias[index] = 0.0;
00046                 }
00047                 
00048                 
00049                 //3. Encontrar el maximo, el promedio y calcular el histograma
00050                 int i, j, k;
00051                 for(i=extent[0];i<=extent[1];i++){
00052                         for(j=extent[2];j<=extent[3];j++){
00053                                 for(k=extent[4];k<=extent[5];k++){
00054                                         valorEnRegion = this->region->GetScalarComponentAsDouble(i,j,k,0);
00055                                         if (valorEnRegion == 0.0){
00056                                                 valor = this->volume->GetScalarComponentAsDouble(i,j,k,0);
00057                                                 if (valor > this->max){
00058                                                         this->max = valor;
00059                                                 }
00060                                                 index  = (int)valor;
00061                                                 this->histogram[index]++;
00062                                                 media += valor;
00063                                                 this->voxelCount++;
00064                                         }
00065                                 }
00066                         }
00067                 }
00068                 
00069                 media = (double)media/(double)this->voxelCount;
00070 
00071                 //calcula sigma total
00072                 for(index=0;index<=max;index++){
00073                         this->sigmaT += (index - media)*(index - media)* this->histogram[index] / (double)this->voxelCount;
00074                 }
00075 
00076 
00077                 //calcular criterio para cada posible threshold e ir seleccionando el maximo
00078             int optimalThreshold = 0;
00079                 double optimalCriteria = 0.0;
00080 
00081                 for (index=0;index<=max;index++){
00082                         criterias[index] = this->getCriteria(index);
00083                         if (criterias[index] > optimalCriteria){
00084                                 optimalCriteria = criterias[index];
00085                                 optimalThreshold = index;
00086                         }
00087                 }
00088                 return optimalThreshold;
00089 
00090                 
00091         }

Here is the call graph for this function:

double vtkOtsu::getCriteria ( double  threshold  )  [private]

Definition at line 94 of file vtkOtsu.cxx.

References histogram, max, region, sigmaT, volume, and voxelCount.

Referenced by calculateOptimalThreshold().

00094                                                    {
00095                 
00096                 int extent[6];
00097                 int i,j,k;
00098                 double valor = 0.0;
00099                 double valorEnRegion = 0.0;
00100 
00101                 this->volume->GetExtent(extent);
00102                 
00103                 //1. Encontrar la frecuencia y la media de las clases A y B
00104                 double mediaA=0.0;
00105                 double wA = 0.0;
00106                 int countA = 0;
00107                 
00108                 double mediaB=0.0;
00109                 double wB = 0.0;
00110                 int countB = 0;
00111 
00112                 for(i=extent[0];i<=extent[1];i++){
00113                         for(j=extent[2];j<=extent[3];j++){
00114                                 for(k=extent[4];k<=extent[5];k++){
00115                                         valorEnRegion = this->region->GetScalarComponentAsDouble(i,j,k,0);
00116                                         if (valorEnRegion == 0.0){
00117                                                 valor = this->volume->GetScalarComponentAsDouble(i,j,k,0);
00118                                                 if (valor < threshold){
00119                                                         mediaA += valor;
00120                                                         countA++;
00121 
00122                                                 }
00123                                                 else{
00124                                                         mediaB += valor;
00125                                                         countB++;
00126                                                 }
00127                                         }
00128                                 }
00129                         }
00130                 }
00131 
00132                 mediaA = (double)mediaA / (double)countA;
00133                 wA = (double)countA / (double)this->voxelCount;
00134 
00135                 mediaB = (double)mediaB / (double)countB;
00136                 wB = (double)countB / (double)this->voxelCount;
00137 
00138 
00139                 //2. Encontrar la varianza de las clases A y B
00140 
00141                 double sigmaA=0.0;
00142                 double sigmaB=0.0;
00143 
00144                 int index = 0;
00145                 
00146                 for(index=0;index<=threshold;index++){
00147                         sigmaA += (index - mediaA)*(index - mediaA)*this->histogram[index]/(double)countA;
00148                 }
00149 
00150                 
00151                 for(index=threshold;index<=this->max;index++){
00152                         sigmaB += (index - mediaB)*(index - mediaB)*this->histogram[index]/(double)countB;
00153                 }
00154 
00155                 //3. Calcular la varianza inter clases
00156 
00157                 double sigmaAB = wA*wB*(mediaA-mediaB)*(mediaA-mediaB);
00158                 double criteria = (double)sigmaAB/(double)sigmaT;
00159 
00160                 return criteria;
00161 
00162         }

Here is the caller graph for this function:


Member Data Documentation

double* vtkOtsu::criterias [private]

Definition at line 20 of file vtkOtsu.h.

Referenced by calculateOptimalThreshold().

int* vtkOtsu::histogram [private]

Definition at line 19 of file vtkOtsu.h.

Referenced by calculateOptimalThreshold(), and getCriteria().

double vtkOtsu::max [private]

Definition at line 26 of file vtkOtsu.h.

Referenced by calculateOptimalThreshold(), and getCriteria().

vtkImageData* vtkOtsu::region [private]

Definition at line 23 of file vtkOtsu.h.

Referenced by getCriteria(), and vtkOtsu().

double vtkOtsu::sigmaT [private]

Definition at line 25 of file vtkOtsu.h.

Referenced by calculateOptimalThreshold(), and getCriteria().

vtkImageData* vtkOtsu::volume [private]

Definition at line 22 of file vtkOtsu.h.

Referenced by getCriteria(), and vtkOtsu().

int vtkOtsu::voxelCount [private]

Definition at line 18 of file vtkOtsu.h.

Referenced by calculateOptimalThreshold(), and getCriteria().


The documentation for this class was generated from the following files:

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1