#include <vtkOtsuSphereSource.h>
Public Member Functions | |
vtkOtsuSphereSource () | |
virtual | ~vtkOtsuSphereSource () |
double | calculateOptimalThreshold (vtkImageData *voi) |
vtkImageData * | getImageForSegmentation () |
Private Attributes | |
int * | H |
double * | SI |
double * | P |
vtkImageData * | volume |
vtkImageData * | region |
vtkImageData * | result |
Definition at line 9 of file vtkOtsuSphereSource.h.
vtkOtsuSphereSource::vtkOtsuSphereSource | ( | ) |
vtkOtsuSphereSource::~vtkOtsuSphereSource | ( | ) | [virtual] |
Definition at line 11 of file vtkOtsuSphereSource.cxx.
double vtkOtsuSphereSource::calculateOptimalThreshold | ( | vtkImageData * | voi | ) |
Definition at line 15 of file vtkOtsuSphereSource.cxx.
References H, P, region, result, SI, and volume.
Referenced by wxPathologyWidget_01::OnBtnExtractPat().
00015 { 00016 00017 int extent[6]; 00018 double centro[3]; 00019 int static TAM = 2000; 00020 00021 00022 00023 this->volume = voi; //VOI 00024 this->region = region; //JF 00025 this->volume->GetExtent(extent); 00026 00027 centro[0] = (extent[0] + extent[1]) / 2; 00028 centro[1] = (extent[2] + extent[3]) / 2; 00029 centro[2] = (extent[4] + extent[5]) / 2; 00030 00031 double radio = (extent[1] - extent[0]) /(double)2.0; 00032 00033 result = vtkImageData::New(); 00034 result->DeepCopy(volume); 00035 00036 double valorEnRegion = 0.0; 00037 double valor = 0.0; 00038 int index = 0; 00039 int T = 0; 00040 int max=0; 00041 int voxelCount = 0; 00042 00043 //1. Inicializacion 00044 this->H = new int[TAM]; 00045 this->P = new double[TAM]; 00046 this->SI = new double[TAM]; 00047 for (index = 0; index <TAM; index++){ 00048 this->H[index] = 0; 00049 this->P[index] = 0.0; //probabilidad acumulada 00050 this->SI[index] = 0.0; 00051 } 00052 00053 //2. Calcular el Histograma 00054 double *ptr; 00055 int i, j, k; 00056 for(i=extent[0];i<=extent[1];i++){ 00057 for(j=extent[2];j<=extent[3];j++){ 00058 for(k=extent[4];k<=extent[5];k++){ 00059 00060 ptr = (double *)this->result->GetScalarPointer(i,j,k); 00061 00062 // verificar si esta dentro de la esfera 00063 if( ((i-centro[0])*(i-centro[0]) + 00064 (j-centro[1])*(j-centro[1]) + 00065 (k-centro[2])*(k-centro[2])) <= (radio*radio)){ 00066 00067 00068 valor = this->volume->GetScalarComponentAsDouble(i,j,k,0); 00069 if (valor > max){ 00070 max = (int)valor; 00071 } 00072 index = (int)valor; 00073 this->H[index]++; 00074 voxelCount++; 00075 00076 00077 } 00078 else { 00079 *ptr=0.0; 00080 } 00081 00082 } 00083 } 00084 } 00085 00086 //3. Normalizacion de la funcion P 00087 for(index=0;index<=max;index++){ 00088 this->P[index] = (double)this->H[index] / (double)voxelCount; 00089 } 00090 00091 00092 //4. Recorrer los diferentes niveles de intensidad 00093 00094 for(T=0;T<=max;T++){ 00095 00096 //4.1 Calcular las probabilidades acumuladas de las clases A y B 00097 double Q1 = 0.0; 00098 double Q2 = 0.0; 00099 for(index=0;index<=max;index++){ 00100 if (index < T){ 00101 Q1 = Q1 + this->P[index]; 00102 } 00103 else{ 00104 Q2 = Q2 + this->P[index]; 00105 } 00106 } 00107 00108 //4.2 Calcular las medias de las clases A y B 00109 double U1 = 0.0; 00110 double U2 = 0.0; 00111 for (index=0;index<=max;index++){ 00112 if (index < T){ 00113 U1 = U1 + ((double)(index * this->P[index])/(double)Q1); 00114 } 00115 else{ 00116 U2 = U2 + ((double)(index * this->P[index])/(double)Q2); 00117 } 00118 } 00119 00120 00121 //4.3 Calcular las varianzas individuales 00122 double S1 = 0.0; 00123 double S2 = 0.0; 00124 for (index=0;index<=max;index++){ 00125 if (index < T){ 00126 S1 = S1 + ((index - U1)*(index - U1)*(this->P[index]/(double)Q1)); 00127 } 00128 else{ 00129 S2 = S2 + ((index - U2)*(index - U2)*(this->P[index]/(double)Q2)); 00130 } 00131 } 00132 00133 //4.4 Calcular SI: La varianza intraclases y seleccionar el valor minimo 00134 this->SI[T] = Q1*S1 + Q2*S2; 00135 } 00136 00137 int optimalThreshold = 0; 00138 double optimalCriteria = VTK_LARGE_FLOAT; 00139 00140 for (index=0;index<=max;index++){ 00141 if (SI[index] < optimalCriteria){ 00142 optimalCriteria = SI[index]; 00143 optimalThreshold = index; 00144 } 00145 } 00146 return optimalThreshold; 00147 }
vtkImageData * vtkOtsuSphereSource::getImageForSegmentation | ( | ) |
Definition at line 152 of file vtkOtsuSphereSource.cxx.
References result.
Referenced by wxPathologyWidget_01::OnBtnExtractPat().
00152 { 00153 return this->result; 00154 }
int* vtkOtsuSphereSource::H [private] |
Definition at line 17 of file vtkOtsuSphereSource.h.
Referenced by calculateOptimalThreshold().
double* vtkOtsuSphereSource::P [private] |
Definition at line 19 of file vtkOtsuSphereSource.h.
Referenced by calculateOptimalThreshold(), and vtkOtsuSphereSource().
vtkImageData* vtkOtsuSphereSource::region [private] |
Definition at line 22 of file vtkOtsuSphereSource.h.
Referenced by calculateOptimalThreshold(), and vtkOtsuSphereSource().
vtkImageData* vtkOtsuSphereSource::result [private] |
Definition at line 23 of file vtkOtsuSphereSource.h.
Referenced by calculateOptimalThreshold(), getImageForSegmentation(), and vtkOtsuSphereSource().
double* vtkOtsuSphereSource::SI [private] |
Definition at line 18 of file vtkOtsuSphereSource.h.
Referenced by calculateOptimalThreshold().
vtkImageData* vtkOtsuSphereSource::volume [private] |
Definition at line 21 of file vtkOtsuSphereSource.h.
Referenced by calculateOptimalThreshold(), and vtkOtsuSphereSource().