Skip to content
Snippets Groups Projects
Commit 0cdc55f6 authored by Antoine Regimbeau's avatar Antoine Regimbeau
Browse files

Fix minor bugs, still a lot of work to do!

parent f90de44e
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,7 @@
#define otbContrastEnhancementFilter_h
#include "itkImageToImageFilter.h"
#include "itkImage.h"
#include "otbImage.h"
#include "itkMultiplyImageFilter.h"
......@@ -47,8 +47,8 @@ public:
typedef itk::SmartPointer< Self > Pointer;
typedef itk::SmartPointer< const Self > ConstPointer;
typedef itk::Image< float , 2 > ImageGainType;
typedef itk::Image< int , 2 > ImageBinType;
typedef otb::Image< float , 2 > ImageGainType;
typedef otb::Image< int , 2 > ImageBinType;
typedef typename InputImageType::PixelType PixelType;
/** "object factory" management method. */
......
......@@ -118,7 +118,9 @@ void ContrastEnhancementFilter < TInputImage , TOutputImage >
++gridHisto[ (i / this->wThumbnail) + ( j / this->hThumbnail ) * nW] \
[ input->GetPixel( index ) ];
}
// std::cout<<"gridHisto[0][127] = "<<gridHisto[0][127]<<std::endl;
}
// std::cout<<"end of histogram computation"<<std::endl;
}
template <class TInputImage, class TOutputImage >
......@@ -139,6 +141,11 @@ void ContrastEnhancementFilter < TInputImage , TOutputImage >
++diff;
}
this->targetHisto = tempTarget;
// ////////////////////////DEBUG////////////////////////
// std::cout<<"size ="<<this->hSize<<std::endl;
// std::cout<<"height ="<<height<<std::endl;
// std::cout<<"targetHisto[middle] ="<<targetHisto[this->hSize/2]<<std::endl;
}
template <class TInputImage, class TOutputImage >
......@@ -223,6 +230,7 @@ void ContrastEnhancementFilter < TInputImage , TOutputImage >
int nW,
int nH )
{
assert(hThresh>=0);
int histoLength = gridHisto[0].size();
int nbHisto = nW * nH;
int toThresh = 0;
......@@ -289,18 +297,22 @@ void ContrastEnhancementFilter < TInputImage , TOutputImage >
statFilter->Update();
this->min = statFilter->GetMinimum();
this->max = statFilter->GetMaximum();
this->step = static_cast<double>( this->max - this->min ) \
/ static_cast<double>( this->hSize - 1 );
this->step = static_cast<double>( this->max - this->min + 1) \
/ static_cast<double>( this->hSize );
typename itk::ImageRegionConstIterator < InputImageType >
it( input , input->GetRequestedRegion() );
typename itk::ImageRegionIterator < ImageBinType >
nit ( this->binImage , this->binImage->GetRequestedRegion() );
it.GoToBegin();
nit.GoToBegin();
std::cout<<"min ="<<this->min<<std::endl;
std::cout<<"max ="<<this->max<<std::endl;
std::cout<<"step ="<<this->step<<std::endl;
int pixelValue = 0;
while( !nit.IsAtEnd() )
{
nit.Set(std::floor( ( it.Get() - this->min ) / this->step ) );
pixelValue = std::floor( ( it.Get() - this->min ) / this->step );
nit.Set( pixelValue );
++it;
++nit;
}
......@@ -374,8 +386,38 @@ void ContrastEnhancementFilter < TInputImage , TOutputImage >
int histoTresh = static_cast<int>( this->threshFactor * this->targetHisto[0] );
computehisto( gridHisto , nW , nH );
histoLimiteContrast( gridHisto , histoTresh , nW , nH );
for (int i : gridHisto[0])
{
if (i<0)
std::cout<<i<<std::endl;
}
// std::cout<<gridHisto[0][this->hSize/2]<<std::endl;
// std::cout<<"========one==========="<<std::endl;
// histoLimiteContrast( gridHisto , histoTresh , nW , nH );
// std::cout<<gridHisto[0][this->hSize/2]<<std::endl;
// std::cout<<"========two==========="<<std::endl;
equalized( gridHisto , gridLut , nW , nH );
// std::cout<<gridHisto[0][this->hSize/2]<<std::endl;
// std::cout<<"========three==========="<<std::endl;
// ///////////////////Debug ///////////////////
// std::cout<<"=======LUT======="<<std::endl;
// for (int i : gridLut[0])
// {
// std::cout<<i<<std::endl;
// }
// std::cout<<"=======Histo======="<<std::endl;
for (int i : gridHisto[0])
{
if (i<0)
std::cout<<i<<std::endl;
}
float gainValue = 0.0;
typename InputImageType::IndexType index;
......@@ -387,7 +429,14 @@ void ContrastEnhancementFilter < TInputImage , TOutputImage >
index[1] = j;
gainValue = interpoleGain( gridLut , this->binImage->GetPixel( index ) ,
index , nW , nH );
// if (i>2000 && i<3000 && j>2000 && j<2010)
// std::cout<<gainValue<<std::endl;
if (gainValue <0 )
std::cout<<"WARNING"<<std::endl;
gainImage->SetPixel( index , gainValue );
}
}
......@@ -398,8 +447,8 @@ void ContrastEnhancementFilter < TInputImage , TOutputImage >
gainMultiplyer->SetInput2( gainImage );
gainMultiplyer->Update();
this->GraftOutput( gainMultiplyer -> GetOutput () );
this->GetOutput()->SetOrigin( input->GetOrigin() );
this->GetOutput()->SetSpacing( input->GetSpacing() );
// this->GetOutput()->SetOrigin( input->GetOrigin() );
// this->GetOutput()->SetSpacing( input->GetSpacing() );
}
......
......@@ -24,13 +24,12 @@ otb_module(OTBContrast
DEPENDS
OTBITK
OTBCommon
OTBImageBase
TEST_DEPENDS
OTBTestKernel
OTBImageIO
OTBImageBase
OTBImageIO
DESCRIPTION
"${DOCUMENTATION}"
......
......@@ -11,12 +11,15 @@
#include "itkComposeImageFilter.h"
#include "itkThresholdImageFilter.h"
#include "otbContrastEnhancementFilter.h"
#include "otbVectorImageToImageListFilter.h"
#include "otbImageListToVectorImageFilter.h"
#if 0
int const sizeh = 256;
typedef int PixelType;
typedef itk::Image< PixelType , 2 > ImageType;
typedef itk::VectorImage< PixelType , 2 > VectorImageType;
typedef itk::Image< float , 2 > ImageGainType;
typedef otb::Image< PixelType , 2 > ImageType;
typedef otb::VectorImage< PixelType , 2 > VectorImageType;
typedef otb::Image< float , 2 > ImageGainType;
void
......@@ -358,6 +361,7 @@ prototype ( int argc,
return 0;
}
#endif
int
main ( int argc,
......@@ -384,24 +388,46 @@ main ( int argc,
writer->SetInput(filter->GetOutput());
writer->Update();
return 0;*/
// typedef int OPixelType;
// typedef otb::Image<OPixelType, 2 > OImageType;
// typedef otb::VectorImage< OPixelType , 2 > OVectorImageType;
typedef int PixelType;
typedef otb::Image< PixelType , 2 > ImageType;
typedef otb::VectorImage< PixelType , 2 > VectorImageType;
typedef otb::ImageFileReader< VectorImageType > ReaderType;
typedef itk::VectorIndexSelectionCastImageFilter< VectorImageType , ImageType > VectorToImageFilterType;
typedef itk::ComposeImageFilter< ImageType > ImageToVectorImageFilterType;
typedef otb::ImageFileWriter< VectorImageType > WriterType;
typedef otb :: ImageList< ImageType > ImageListType;
typedef otb::VectorImageToImageListFilter< VectorImageType, ImageListType >
VectorToImageListFilterType;
typedef otb::ImageListToVectorImageFilter< ImageListType, VectorImageType >
ImageListToVectorFilterType;
typedef otb::ContrastEnhancementFilter< ImageType , ImageType > FilterType;
ReaderType::Pointer reader( ReaderType::New() );
reader->SetFileName( argv[ 1 ] );
reader->Update();
VectorImageType::Pointer input = reader->GetOutput();
ImageToVectorImageFilterType::Pointer imageToVectorImageFilterOut( ImageToVectorImageFilterType::New() );
VectorToImageFilterType::Pointer vectorToImageFilter ( VectorToImageFilterType::New() );
vectorToImageFilter->SetInput( input );
vectorToImageFilter->SetIndex( 0 );
vectorToImageFilter->Update();
VectorToImageListFilterType::Pointer vectorToImageListFilter ( VectorToImageListFilterType::New() );
ImageListToVectorFilterType::Pointer imageListToVectorFilterOut( ImageListToVectorFilterType::New() );
vectorToImageListFilter->SetInput( input );
vectorToImageListFilter->Update();
if (argc<5)
{
std::cout<<"error : otbContrastTestDriver -inputFilename -outputFilename -hThumbnail -wThumbnail"<<std::endl;
if (argc>1)
{
std::cout<<"Image Width = "<<input->GetLargestPossibleRegion().GetSize()[0]<<std::endl;
std::cout<<"Image Height = "<<input->GetLargestPossibleRegion().GetSize()[1]<<std::endl;
}
return 1;
}
int hThumbnail = atoi(argv[3]);
int wThumbnail = atoi(argv[4]);
ImageType::Pointer inputImage = vectorToImageFilter->GetOutput();
ImageListType::Pointer inputImageList = vectorToImageListFilter->GetOutput();
ImageType::Pointer inputImage = inputImageList->Front();
if ( inputImage->GetLargestPossibleRegion().GetSize()[1]%hThumbnail != 0 )
{
std::cout<<"error : hThumbnail = "<<hThumbnail<<" is not a divider of the input's height"<<std::endl;
......@@ -415,29 +441,29 @@ main ( int argc,
return 1;
}
typedef otb::ContrastEnhancementFilter< ImageType , ImageType > FilterType;
ImageListType::Pointer outputImageList ( ImageListType::New() );
int m = input->GetVectorLength ();
for (int chanel = 0 ; chanel<m ; chanel++ )
{
vectorToImageFilter->SetIndex( chanel );
vectorToImageFilter->Update();
FilterType::Pointer filter( FilterType::New() );
filter->SetInput(vectorToImageFilter->GetOutput());
filter->setHistoThreshFactor(3);
filter->setHistoSize(512);
// filter->setGainThresh(1.0, 1.0);
filter->SetInput( inputImageList->GetNthElement(chanel) ) ;
filter->setHistoThreshFactor(6);
filter->setHistoSize(1024);
// filter->setGainThresh(0.1, 10.0);
filter->setThumbnailSize( wThumbnail, hThumbnail );
filter->Update();
imageToVectorImageFilterOut->SetInput( chanel , filter->GetOutput() );
outputImageList->PushBack( filter->GetOutput() );
}
VectorImageType::Pointer output = imageToVectorImageFilterOut->GetOutput();
imageListToVectorFilterOut->SetInput(outputImageList);
imageListToVectorFilterOut->Update();
VectorImageType::Pointer output = imageListToVectorFilterOut->GetOutput();
output->SetOrigin(input->GetOrigin());
output->CopyInformation(input);
output->Graft(input);
// Here we compute a gain image corresponding to the associated gain of the equalization
typedef otb::ImageFileWriter<VectorImageType> WriterType;
WriterType::Pointer writer( WriterType::New());
writer->SetFileName( argv[2] );
writer->SetInput( output );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment