Commit f294e853 authored by Antoine Regimbeau's avatar Antoine Regimbeau
Browse files

REFAC: changing some while loop in for loop with assert,

move protected function to private,
and using constiteratorwithindex instead of constiterator
No related merge requests found
Showing with 46 additions and 56 deletions
+46 -56
...@@ -285,7 +285,7 @@ private: ...@@ -285,7 +285,7 @@ private:
m_VectorToImageListFilter->UpdateOutputInformation(); m_VectorToImageListFilter->UpdateOutputInformation();
ImageListType::Pointer inputImageList = ImageListType::Pointer inputImageList =
m_VectorToImageListFilter->GetOutput(); m_VectorToImageListFilter->GetOutput();
int nbChannel = inImage->GetVectorLength (); unsigned int nbChannel = inImage->GetVectorLength ();
if ( mode == "each") if ( mode == "each")
{ {
...@@ -436,13 +436,13 @@ private: ...@@ -436,13 +436,13 @@ private:
if ( IsParameterEnabled("minmax.auto.global") ) if ( IsParameterEnabled("minmax.auto.global") )
{ {
float temp(min[0]); float temp(min[0]);
for (unsigned int i = 0 ; i < min.GetSize() ; i++ ) for ( unsigned int i = 0 ; i < min.GetSize() ; i++ )
{ {
temp = std::min(temp , min[i]); temp = std::min(temp , min[i]);
} }
min.Fill(temp); min.Fill(temp);
temp = max[0]; temp = max[0];
for (unsigned int i = 0 ; i < max.GetSize() ; i++ ) for ( unsigned int i = 0 ; i < max.GetSize() ; i++ )
{ {
temp = std::max(temp , max[i]); temp = std::max(temp , max[i]);
} }
...@@ -480,7 +480,7 @@ private: ...@@ -480,7 +480,7 @@ private:
// Function corresponding to the "each" mode // Function corresponding to the "each" mode
void PerBandEqualization( const FloatVectorImageType::Pointer inImage , void PerBandEqualization( const FloatVectorImageType::Pointer inImage ,
const ImageListType::Pointer inputImageList , const ImageListType::Pointer inputImageList ,
const int nbChannel, const unsigned int nbChannel,
ImageListType::Pointer outputImageList ) ImageListType::Pointer outputImageList )
{ {
FloatVectorImageType::PixelType min(nbChannel) , max(nbChannel); FloatVectorImageType::PixelType min(nbChannel) , max(nbChannel);
...@@ -494,7 +494,7 @@ private: ...@@ -494,7 +494,7 @@ private:
m_BufferFilter.resize(nbChannel); m_BufferFilter.resize(nbChannel);
m_StreamingFilter.resize(nbChannel); m_StreamingFilter.resize(nbChannel);
for (int channel = 0 ; channel<nbChannel ; channel++ ) for ( unsigned int channel = 0 ; channel < nbChannel ; channel++ )
{ {
m_GainLutFilter[channel] = GainLutFilterType::New(); m_GainLutFilter[channel] = GainLutFilterType::New();
m_HistoFilter[channel] = HistoFilterType::New(); m_HistoFilter[channel] = HistoFilterType::New();
...@@ -551,11 +551,7 @@ private: ...@@ -551,11 +551,7 @@ private:
lumCoef[1] = GetParameterFloat("mode.lum.gre.coef"); lumCoef[1] = GetParameterFloat("mode.lum.gre.coef");
lumCoef[2] = GetParameterFloat("mode.lum.blu.coef"); lumCoef[2] = GetParameterFloat("mode.lum.blu.coef");
// Normalize those coeffs // Normalize those coeffs
float sum = 0.0; float sum = std::accumulate( lumCoef.begin() , lumCoef.end() , 0 );
for (float f : lumCoef)
{
sum +=f;
}
assert(sum>0); assert(sum>0);
for (int i = 0 ; i<3 ; i++ ) for (int i = 0 ; i<3 ; i++ )
{ {
......
...@@ -108,15 +108,16 @@ protected : ...@@ -108,15 +108,16 @@ protected :
void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread,
itk::ThreadIdType threadId) override; itk::ThreadIdType threadId) override;
/** Bilineare interpolation of the gain beetween the different window.*/
float InterpolateGain( typename LutType::ConstPointer gridLut ,
unsigned int pixelValue ,
typename InputImageType::IndexType index);
private : private :
ApplyGainFilter(const Self &) = delete ; ApplyGainFilter(const Self &) = delete ;
void operator =(const Self&) = delete ; void operator =(const Self&) = delete ;
/** Bilinear interpolation of the gain between the different window.*/
double InterpolateGain( typename LutType::ConstPointer gridLut ,
unsigned int pixelValue ,
typename InputImageType::IndexType index);
InputPixelType m_NoData; InputPixelType m_NoData;
InputPixelType m_Min; InputPixelType m_Min;
InputPixelType m_Max; InputPixelType m_Max;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "otbApplyGainFilter.h" #include "otbApplyGainFilter.h"
#include "itkImageRegionIterator.h" #include "itkImageRegionIterator.h"
#include "itkImageRegionConstIteratorWithIndex.h"
#include <limits> #include <limits>
...@@ -111,38 +112,37 @@ void ApplyGainFilter < TInputImage , TLut , TOutputImage > ...@@ -111,38 +112,37 @@ void ApplyGainFilter < TInputImage , TLut , TOutputImage >
typename OutputImageType::Pointer output ( this->GetOutput() ); typename OutputImageType::Pointer output ( this->GetOutput() );
typename InputImageType::RegionType inputRegionForThread; typename InputImageType::RegionType inputRegionForThread;
this->CallCopyOutputRegionToInputRegion(inputRegionForThread , inputRegionForThread = outputRegionForThread ;
outputRegionForThread);
// Is it usefull???
itk::ImageRegionConstIterator < InputImageType > it ( input , itk::ImageRegionConstIteratorWithIndex < InputImageType > it ( input ,
inputRegionForThread ); inputRegionForThread );
itk::ImageRegionIterator <OutputImageType > oit ( output , itk::ImageRegionIterator <OutputImageType > oit ( output ,
outputRegionForThread ); outputRegionForThread );
unsigned int pixelLutValue(0); unsigned int pixelLutValue(0);
float gain(0.0); double gain(0.0) , newValue(0);
InputPixelType currentPixel(0); InputPixelType currentPixel(0);
for(it.GoToBegin() , oit.GoToBegin() ; !oit.IsAtEnd() , !it.IsAtEnd() ; for( it.GoToBegin() , oit.GoToBegin() ; !oit.IsAtEnd() || !it.IsAtEnd() ;
++oit , ++it ) ++oit , ++it )
{ {
currentPixel = it.Get(); currentPixel = it.Get();
if( ( currentPixel == m_NoData && m_NoDataFlag ) || newValue = static_cast< double > ( currentPixel );
currentPixel > m_Max || currentPixel < m_Min ) if( !( ( currentPixel == m_NoData && m_NoDataFlag ) ||
currentPixel > m_Max || currentPixel < m_Min ) )
{ {
oit.Set( static_cast<OutputPixelType>( currentPixel ) ); pixelLutValue = static_cast< unsigned int > (
continue; std::round( ( currentPixel - m_Min ) / m_Step ) );
gain = InterpolateGain( lut , pixelLutValue , it.GetIndex() );
newValue *= gain;
} }
pixelLutValue = static_cast< unsigned int > ( oit.Set( static_cast<OutputPixelType>( newValue ) );
std::round( ( currentPixel - m_Min ) / m_Step ) );
gain = InterpolateGain( lut , pixelLutValue , it.GetIndex() );
oit.Set( static_cast<OutputPixelType>( gain * currentPixel ) );
} }
assert ( oit.IsAtEnd() && it.IsAtEnd() );
} }
template <class TInputImage , class TLut , class TOutputImage > template <class TInputImage , class TLut , class TOutputImage >
float ApplyGainFilter < TInputImage , TLut , TOutputImage > double ApplyGainFilter < TInputImage , TLut , TOutputImage >
::InterpolateGain( typename LutType::ConstPointer gridLut, ::InterpolateGain( typename LutType::ConstPointer gridLut,
unsigned int pixelLutValue , unsigned int pixelLutValue ,
typename InputImageType::IndexType index) typename InputImageType::IndexType index)
......
...@@ -88,6 +88,10 @@ protected: ...@@ -88,6 +88,10 @@ protected:
const OutputImageRegionType & outputRegionForThread , const OutputImageRegionType & outputRegionForThread ,
itk::ThreadIdType threadId) override ; itk::ThreadIdType threadId) override ;
private:
ComputeGainLutFilter(const Self &) = delete ;
void operator =(const Self&) = delete ;
/** Post-process the look up tabe to get a gain instead of a simple value */ /** Post-process the look up tabe to get a gain instead of a simple value */
OutputPixelType PostProcess( unsigned int countMapValue , OutputPixelType PostProcess( unsigned int countMapValue ,
unsigned int countValue ) ; unsigned int countValue ) ;
...@@ -106,10 +110,6 @@ protected: ...@@ -106,10 +110,6 @@ protected:
/** Check whether the input histogram has enought pixel to be meaningful */ /** Check whether the input histogram has enought pixel to be meaningful */
bool IsValid(const HistoType & inputHisto ) ; bool IsValid(const HistoType & inputHisto ) ;
private:
ComputeGainLutFilter(const Self &) = delete ;
void operator =(const Self&) = delete ;
double m_Min; double m_Min;
double m_Max; double m_Max;
double m_Step; double m_Step;
......
...@@ -65,7 +65,7 @@ void ComputeGainLutFilter <TInputImage , TOutputImage > ...@@ -65,7 +65,7 @@ void ComputeGainLutFilter <TInputImage , TOutputImage >
typename OutputImageType::Pointer output ( this->GetOutput() ); typename OutputImageType::Pointer output ( this->GetOutput() );
typename InputImageType::RegionType inputRegionForThread; typename InputImageType::RegionType inputRegionForThread;
this->CallCopyOutputRegionToInputRegion(inputRegionForThread , outputRegionForThread); inputRegionForThread = outputRegionForThread;
// Is it usefull??? // Is it usefull???
itk::ImageRegionConstIterator < InputImageType > it ( input , itk::ImageRegionConstIterator < InputImageType > it ( input ,
...@@ -82,9 +82,8 @@ void ComputeGainLutFilter <TInputImage , TOutputImage > ...@@ -82,9 +82,8 @@ void ComputeGainLutFilter <TInputImage , TOutputImage >
LutType lut; LutType lut;
lut.SetSize( m_NbBin ); lut.SetSize( m_NbBin );
it.GoToBegin(); for (it.GoToBegin() , oit.GoToBegin() ; !oit.IsAtEnd() || !it.IsAtEnd() ;
oit.GoToBegin(); ++oit , ++it )
for (; !oit.IsAtEnd() && !it.IsAtEnd() ; ++oit , ++it )
{ {
currentHisto = it.Get(); currentHisto = it.Get();
target.Fill(0); target.Fill(0);
...@@ -96,6 +95,7 @@ void ComputeGainLutFilter <TInputImage , TOutputImage > ...@@ -96,6 +95,7 @@ void ComputeGainLutFilter <TInputImage , TOutputImage >
} }
oit.Set( lut ); oit.Set( lut );
} }
assert ( oit.IsAtEnd() && it.IsAtEnd() );
} }
template <class TInputImage, class TOutputImage > template <class TInputImage, class TOutputImage >
......
...@@ -128,14 +128,14 @@ protected: ...@@ -128,14 +128,14 @@ protected:
void GenerateOutputRequestedRegion( itk::DataObject *output ) override; void GenerateOutputRequestedRegion( itk::DataObject *output ) override;
void ApplyThreshold(
typename itk::ImageRegionIterator < OutputImageType > oit ,
unsigned int total );
private: private:
ComputeHistoFilter(const Self &) = delete ; ComputeHistoFilter(const Self &) = delete ;
void operator =(const Self&) = delete ; void operator =(const Self&) = delete ;
void ApplyThreshold(
typename itk::ImageRegionIterator < OutputImageType > oit ,
unsigned int total );
std::vector< typename OutputImageType::PixelType > m_HistoThread; std::vector< typename OutputImageType::PixelType > m_HistoThread;
InputPixelType m_Min; InputPixelType m_Min;
InputPixelType m_Max; InputPixelType m_Max;
......
...@@ -283,10 +283,9 @@ void ComputeHistoFilter < TInputImage , TOutputImage > ...@@ -283,10 +283,9 @@ void ComputeHistoFilter < TInputImage , TOutputImage >
} }
typename itk::ImageRegionConstIterator < InputImageType > typename itk::ImageRegionConstIterator < InputImageType >
it( input , region ); it( input , region );
it.GoToBegin();
InputPixelType currentPixel(0); InputPixelType currentPixel(0);
for ( ; !it.IsAtEnd() ; ++it ) for ( it.GoToBegin() ; !it.IsAtEnd() ; ++it )
{ {
currentPixel = it.Get(); currentPixel = it.Get();
if( ( currentPixel == m_NoData && m_NoDataFlag ) || if( ( currentPixel == m_NoData && m_NoDataFlag ) ||
...@@ -311,11 +310,10 @@ void ComputeHistoFilter < TInputImage , TOutputImage > ...@@ -311,11 +310,10 @@ void ComputeHistoFilter < TInputImage , TOutputImage >
GetHistoOutput()->GetRequestedRegion() ); GetHistoOutput()->GetRequestedRegion() );
SizeType outSize ( histoRegion.GetSize() ); SizeType outSize ( histoRegion.GetSize() );
IndexType outIndex ( histoRegion.GetIndex() ); IndexType outIndex ( histoRegion.GetIndex() );
oit.GoToBegin();
unsigned int agreg(0) , total(0) ; unsigned int agreg(0) , total(0) ;
while ( !oit.IsAtEnd() ) for ( oit.GoToBegin() ; !oit.IsAtEnd() ; ++oit )
{ {
total = 0; total = 0;
...@@ -323,22 +321,17 @@ void ComputeHistoFilter < TInputImage , TOutputImage > ...@@ -323,22 +321,17 @@ void ComputeHistoFilter < TInputImage , TOutputImage >
{ {
agreg = 0; agreg = 0;
for (unsigned int threadId = 0 ; threadId<m_ValidThreads ; threadId++ ) for ( unsigned int threadId = 0 ; threadId < m_ValidThreads ; threadId++ )
{ {
agreg += m_HistoThread[threadId * outSize[0] * outSize[1] \ agreg += m_HistoThread[ threadId * outSize[0] * outSize[1]
+ ( ( oit.GetIndex()[0] - outIndex[0] ) ) \ + ( ( oit.GetIndex()[0] - outIndex[0] ) )
+ ( oit.GetIndex()[1] - outIndex[1] ) * outSize[0]][i]; + ( oit.GetIndex()[1] - outIndex[1] ) * outSize[0] ][i] ;
} }
oit.Get()[i] = agreg; oit.Get()[i] = agreg;
total += agreg; total += agreg;
} }
if ( m_Threshold == std::numeric_limits< float >::max() ) if ( m_Threshold != std::numeric_limits< float >::max() )
{ ApplyThreshold( oit , total );
++oit;
continue;
}
ApplyThreshold( oit , total );
++oit;
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment