
// Anistropic Diffusion LBR Image FIlter
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>

#include <itkImage.h>
#include <itkImageFileReader.h>
#include <itkImageFileWriter.h>
#include <itkGDCMImageIO.h>
#include <itkGDCMSeriesFileNames.h>
#include <itkImageSeriesReader.h>
#include <itkImageRegionIterator.h>
#include <itkRGBPixel.h>
#include "itkAnisotropicDiffusionLBRImageFilter.h"
#include "itkAnisotropicDiffusionLBRMacro.h"
#include "itkAnisotropicDiffusionImageFilter.h"
#include "itkLinearAnisotropicDiffusionLBRImageFilter.h"
#include "itkCoherenceEnhancingDiffusionImageFilter.h"

#include <QuickView.h>

using namespace std;

const string filename = "IM-0001-0011.dcm";


int main(int argc, char** argv)
{
	typedef unsigned char                 PixelType;
	typedef itk::Image<PixelType, 2>      ImageType;


	typedef float InputPixelType;//Pixel Type
	const unsigned int InputDimension = 2;//Dimension of image
	const unsigned int OutputDimension = 2;//Dimension of image

	typedef itk::Image< InputPixelType, InputDimension > InputImageType;//Image Type
	typedef itk::Image< InputPixelType, OutputDimension > OutputImageType;//Image Type


	typedef itk::GDCMImageIO ImageIOType;
	typedef itk::ImageSeriesReader<OutputImageType> ReaderType;
	typedef itk::CoherenceEnhancingDiffusionImageFilter<InputImageType> DiffusionFilterType;

	ReaderType::Pointer reader = ReaderType::New();
	reader->SetFileName( filename );

	ImageIOType::Pointer gdcmimageIO = ImageIOType::New();
	reader->SetImageIO( gdcmimageIO );

	try{
		reader->Update();
	} catch (itk::ExceptionObject &e){
		std::cerr << e << std::endl;
		return -1;
	}
	QuickView viewer;
	viewer.AddImage(reader->GetOutput());
	


	DiffusionFilterType::Pointer diffusionFilter = DiffusionFilterType::New();
	diffusionFilter->SetInput(reader->GetOutput());
	const double diffusionTime = 2;

	diffusionFilter->SetDiffusionTime(diffusionTime);
	const double lambda = 0.0001;
	diffusionFilter->SetLambda(lambda);
	const char * enhancement = "Isotropic";

	diffusionFilter->SetEnhancement(DiffusionFilterType::Isotropic);
	const double noiseScale = 1;
	diffusionFilter->SetNoiseScale(noiseScale);
	const double featureScale = 2;

	diffusionFilter->SetFeatureScale(featureScale);
	const double exponent = 0.8;
	diffusionFilter->SetExponent(exponent);
	diffusionFilter->Update();

	
	viewer.AddImage(diffusionFilter->GetOutput());
	
	viewer.Visualize();	
	return 0;
}
