Skip to content
Snippets Groups Projects
Commit f6d25979 authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

STYLE : code factorization

parent 24da2eb1
Branches
Tags
No related merge requests found
......@@ -48,74 +48,24 @@ public:
typedef TIterInput1 IterType1;
typedef TIterInput2 IterType2;
typedef TOutput OutputType;
typedef typename IterType1::OffsetType OffsetType;
typedef typename IterType1::RadiusType RadiusType;
typedef typename IterType1::InternalPixelType InternalPixelType;
typedef typename IterType1::ImageType ImageType;
typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType;
typedef std::vector<double> DoubleVectorType;
typedef std::vector<int> IntVectorType;
typedef std::vector<IntVectorType> IntVectorVectorType;
virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff)
{
DoubleVectorType binsLength = this->StatComputation(neigh, neighOff);
this->ComputeJointHistogram(neigh, neighOff);
double out = 0.;
RadiusType radius = neigh.GetRadius();
double area = static_cast<double>(neigh.GetSize()[0]*neigh.GetSize()[1]);
double areaInv = 1/area;
OffsetType offset;
offset.Fill(0);
OffsetType offsetOff;
OffsetType offsetOffInit;
offsetOffInit[0] = -radius[0]+this->GetOffset()[0]-1;
offsetOffInit[1] = -radius[1]+this->GetOffset()[1]-1;
int histoIdX = 0;
int histoIdY = 0;
double out = 0.;
IntVectorType histoTemp;
IntVectorVectorType histo;
if (binsLength[0] != 0)
histoTemp = IntVectorType( vcl_floor( static_cast<double>(this->GetMaxi()-this->GetMini())/binsLength[0])+1., 0);
else
histoTemp = IntVectorType( 1, 0 );
if (binsLength[1] != 0)
histo = IntVectorVectorType( vcl_floor(static_cast<double>(this->GetMaxiOff()-this->GetMiniOff())/binsLength[1])+1., histoTemp );
else
histo = IntVectorVectorType( 1, histoTemp );
offsetOff = offsetOffInit;
for ( int l = -static_cast<int>(radius[0]); l <= static_cast<int>(radius[0]); l++ )
{
offsetOff[0]++;
offsetOff[1] = offsetOffInit[1];
offset[0] = l;
for ( int k = -static_cast<int>(radius[1]); k <= static_cast<int>(radius[1]); k++)
{
offsetOff[1]++;
offset[1] = k;
histoIdX = 0;
histoIdY = 0;
if ( binsLength[1] != 0)
histoIdX = static_cast<int>(vcl_floor( (static_cast<double>(neighOff[offsetOff])-this->GetMiniOff()) / static_cast<double>(binsLength[1]) ));
if ( binsLength[0] !=0 )
histoIdY = static_cast<int>(vcl_floor( (static_cast<double>(neigh[offset])-this->GetMini()) /static_cast<double>( binsLength[0]) ));
histo[histoIdX][histoIdY]++;
}
}
for (unsigned r = 0; r<histo.size(); r++)
for (unsigned r = 0; r<this->GetHisto().size(); r++)
{
for (unsigned s = 0; s<histo[r].size(); s++)
for (unsigned s = 0; s<this->GetHisto()[r].size(); s++)
{
double p = static_cast<double>(histo[r][s]) * areaInv;
double p = static_cast<double>(this->GetHisto()[r][s]) * areaInv;
out += vcl_pow( p, 2 );
}
}
......
......@@ -54,6 +54,9 @@ public:
m_MeanOff = 0.;
m_Std = 0.;
m_StdOff = 0.;
m_NeighBinLength = 0;
m_OffsetBinLength = 0;
m_Histo.clear();
};
~TextureFunctorBase() {};
......@@ -67,6 +70,9 @@ public:
typedef typename IterType1::ImageType ImageType;
typedef itk::Neighborhood<InternalPixelType, ::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType;
typedef std::vector<double> DoubleVectorType;
typedef std::vector<int> IntVectorType;
typedef std::vector<IntVectorType> IntVectorVectorType;
void SetOffset(OffsetType off){ m_Offset=off; };
OffsetType GetOffset(){ return m_Offset; };
......@@ -77,7 +83,10 @@ public:
double GetMean(){ return m_Mean; };
double GetMeanOff(){ return m_MeanOff; };
double GetStd(){ return m_Std; };
double GetStdOff(){ return m_StdOff; };
double GetStdOff(){ return m_StdOff;};
double GetNeighBinLength(){ return m_NeighBinLength; };
double GetOffsetBinLength(){ return m_OffsetBinLength; };
IntVectorVectorType GetHisto(){ return m_Histo; };
/** Computes the histogram bins using Scott formula, plus min/max, means, stds */
DoubleVectorType StatComputation(const NeighborhoodType &neigh, const NeighborhoodType &neighOff)
......@@ -153,6 +162,9 @@ public:
output.push_back( scottCoef*binLength );
output.push_back( scottCoef*binLengthOff );
m_NeighBinLength = scottCoef*binLength;
m_OffsetBinLength = scottCoef*binLengthOff;
return output;
}
......@@ -197,6 +209,59 @@ public:
return outPix;
}
void ComputeJointHistogram(const NeighborhoodType &neigh, const NeighborhoodType &neighOff)
{
DoubleVectorType binsLength = this->StatComputation(neigh, neighOff);
RadiusType radius = neigh.GetRadius();
double area = static_cast<double>(neigh.GetSize()[0]*neigh.GetSize()[1]);
double areaInv = 1/area;
OffsetType offset;
offset.Fill(0);
OffsetType offsetOff;
OffsetType offsetOffInit;
offsetOffInit[0] = -radius[0]+this->GetOffset()[0]-1;
offsetOffInit[1] = -radius[1]+this->GetOffset()[1]-1;
int histoIdX = 0;
int histoIdY = 0;
double out = 0.;
IntVectorType histoTemp;
if (binsLength[0] != 0)
histoTemp = IntVectorType( vcl_floor( static_cast<double>(this->GetMaxi()-this->GetMini())/m_NeighBinLength)+1., 0);
else
histoTemp = IntVectorType( 1, 0 );
if (binsLength[1] != 0)
m_Histo = IntVectorVectorType( vcl_floor(static_cast<double>(this->GetMaxiOff()-this->GetMiniOff())/m_OffsetBinLength)+1., histoTemp );
else
m_Histo = IntVectorVectorType( 1, histoTemp );
offsetOff = offsetOffInit;
for ( int l = -static_cast<int>(radius[0]); l <= static_cast<int>(radius[0]); l++ )
{
offsetOff[0]++;
offsetOff[1] = offsetOffInit[1];
offset[0] = l;
for ( int k = -static_cast<int>(radius[1]); k <= static_cast<int>(radius[1]); k++)
{
offsetOff[1]++;
offset[1] = k;
histoIdX = 0;
histoIdY = 0;
if ( binsLength[1] != 0)
histoIdX = static_cast<int>(vcl_floor( (static_cast<double>(neighOff[offsetOff])-this->GetMiniOff()) / static_cast<double>(m_OffsetBinLength) ));
if ( binsLength[0] !=0 )
histoIdY = static_cast<int>(vcl_floor( (static_cast<double>(neigh[offset])-this->GetMini()) /static_cast<double>( m_NeighBinLength) ));
m_Histo[histoIdX][histoIdY]++;
}
}
}
virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) = 0;
private:
......@@ -213,6 +278,11 @@ public:
/** Stores standard deviation of neighborhood+offset */
double m_Std;
double m_StdOff;
/** Bins length */
double m_NeighBinLength;
double m_OffsetBinLength;
/** Joint histogramm */
IntVectorVectorType m_Histo;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment