Skip to content

Commit

Permalink
SYNC: Files added to wiki.
Browse files Browse the repository at this point in the history
  • Loading branch information
lorensen committed Feb 7, 2017
1 parent 0ac1d99 commit ec4182d
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Cxx/Developer/ImageSource.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "itkImage.h"
#include "itkImageFileWriter.h"

#include "MyImageSource.h"

int main(int, char*[])
{
// Setup types
typedef itk::Image<unsigned char, 2> ImageType;
typedef itk::MyImageSource<ImageType> FilterType;

// Create and the filter
FilterType::Pointer filter = FilterType::New();
filter->Update();
filter->GetOutput()->Print(std::cout);

typedef itk::ImageFileWriter< ImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName("Test.jpg");
writer->SetInput(filter->GetOutput());
writer->Update();


return EXIT_SUCCESS;
}
44 changes: 44 additions & 0 deletions Cxx/Developer/MyImageSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef __MyImageSource_h
#define __MyImageSource_h

#include "itkImageSource.h"

#include <set>

namespace itk
{
template< class TImage>
class MyImageSource:public ImageSource< TImage >
{
public:

/** Standard class typedefs. */
typedef MyImageSource Self;
typedef ImageSource< TImage > Superclass;
typedef SmartPointer< Self > Pointer;

/** Method for creation through the object factory. */
itkNewMacro(Self);

/** Run-time type information (and related methods). */
itkTypeMacro(MyImageSource, ImageSource);

protected:
MyImageSource(){}
~MyImageSource(){}

/** Does the real work. */
virtual void GenerateData();

private:
MyImageSource(const Self &); //purposely not implemented
void operator=(const Self &); //purposely not implemented

};
} //namespace ITK

#ifndef ITK_MANUAL_INSTANTIATION
#include "MyImageSource.txx"
#endif

#endif // __MyImageSource_h
50 changes: 50 additions & 0 deletions Cxx/Developer/MyImageSource.txx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef __MyImageSource_txx
#define __MyImageSource_txx

#include "MyImageSource.h"

namespace itk
{

template< class TOutputImage>
void MyImageSource< TOutputImage>
::GenerateData()
{
typename TOutputImage::Pointer output = this->GetOutput();
typename TOutputImage::RegionType region;
typename TOutputImage::IndexType start;
start[0] = 0;
start[1] = 0;

typename TOutputImage::SizeType size;
size[0] = 200;
size[1] = 300;

region.SetSize(size);
region.SetIndex(start);

output->SetRegions(region);
output->Allocate();

itk::ImageRegionIterator<TOutputImage> imageIterator(output,output->GetLargestPossibleRegion());

while(!imageIterator.IsAtEnd())
{
if(imageIterator.GetIndex()[0] == imageIterator.GetIndex()[1])
{
imageIterator.Set(255);
}
else
{
imageIterator.Set(0);
}

++imageIterator;
}

}

}// end namespace


#endif
60 changes: 60 additions & 0 deletions Developer/ImageFilterY.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef __itkImageFilter_h
#define __itkImageFilter_h

#include "itkImageToImageFilter.h"

#include "itkRecursiveGaussianImageFilter.h"

namespace itk
{
template< class TImage>
class ImageFilter:public ImageToImageFilter< TImage, TImage >
{
public:
/** Standard class typedefs. */
typedef ImageFilter Self;
typedef ImageToImageFilter< TImage, TImage > Superclass;
typedef SmartPointer< Self > Pointer;

/** Method for creation through the object factory. */
itkNewMacro(Self);

/** Run-time type information (and related methods). */
itkTypeMacro(ImageFilter, ImageToImageFilter);


/** Image dimension. */
itkStaticConstMacro(ImageDimension, unsigned int,
TImage::ImageDimension);


/** Smoothing filter type */
typedef RecursiveGaussianImageFilter<
TImage,
TImage
> InternalGaussianFilterType;

/** Pointer to a gaussian filter. */
typedef typename InternalGaussianFilterType::Pointer InternalGaussianFilterPointer;

protected:
ImageFilter();
~ImageFilter(){}

/** Does the real work. */
virtual void GenerateData();

private:
ImageFilter(const Self &); //purposely not implemented
void operator=(const Self &); //purposely not implemented

};
} //namespace ITK


#ifndef ITK_MANUAL_INSTANTIATION
#include "ImageFilterY.hxx"
#endif


#endif // __itkImageFilter_h
56 changes: 56 additions & 0 deletions Developer/ImageFilterY.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef __ImageFilterY_hxx
#define __ImageFilterY_hxx

#include "ImageFilterY.h"
#include "itkObjectFactory.h"
#include "itkImageRegionIterator.h"

namespace itk
{

template< class TImage>
ImageFilter< TImage>
::ImageFilter()
{

}

template< class TImage>
void ImageFilter< TImage>
::GenerateData()
{
InternalGaussianFilterPointer smoothingFilters[ImageDimension];

// Instantiate all filters
for ( unsigned int i = 0; i < ImageDimension; i++ )
{
smoothingFilters[i] = InternalGaussianFilterType::New();
smoothingFilters[i]->SetOrder(InternalGaussianFilterType::ZeroOrder);
smoothingFilters[i]->SetDirection(i);
}

// Connect all filters (start at 1 because 0th filter is connected to the input
for ( unsigned int i = 1; i < ImageDimension; i++ )
{
smoothingFilters[i]->SetInput(
smoothingFilters[i - 1]->GetOutput() );
}

const typename TImage::ConstPointer inputImage( this->GetInput() );

const typename TImage::RegionType region = inputImage->GetRequestedRegion();
const typename TImage::SizeType size = region.GetSize();

smoothingFilters[0]->SetInput(inputImage);

smoothingFilters[ImageDimension-1]->Update();

// Copy the output from the last filter
//this->GraftOutput( m_SmoothingFilters[ImageDimension-1]->GetOutput() );
this->GetOutput()->Graft(smoothingFilters[ImageDimension-1]->GetOutput() );
}

}// end namespace


#endif
76 changes: 76 additions & 0 deletions ImageProcessing/DanielssonDistanceMapImageFilter.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkDanielssonDistanceMapImageFilter.h"

#include "itksys/SystemTools.hxx"
#include <sstream>

#include "QuickView.h"

typedef itk::Image<unsigned char, 2> UnsignedCharImageType;
typedef itk::Image<float, 2> FloatImageType;

static void CreateImage(UnsignedCharImageType::Pointer image);

int main(int argc, char * argv[])
{
UnsignedCharImageType::Pointer image = UnsignedCharImageType::New();
if (argc < 2)
{
CreateImage(image);
}
else
{
typedef itk::ImageFileReader<UnsignedCharImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
reader->Update();
image = reader->GetOutput();
}

typedef itk::DanielssonDistanceMapImageFilter< UnsignedCharImageType, FloatImageType > DanielssonDistanceMapImageFilterType;
DanielssonDistanceMapImageFilterType::Pointer distanceMapImageFilter =
DanielssonDistanceMapImageFilterType::New();
distanceMapImageFilter->SetInput(image);
distanceMapImageFilter->InputIsBinaryOn();

QuickView viewer;
viewer.AddImage(
image.GetPointer(),true,
argc > 1 ? itksys::SystemTools::GetFilenameName(argv[1]) : "Generated image");

std::stringstream desc;
desc << "Danielsson Distance";
viewer.AddImage(
distanceMapImageFilter->GetOutput(),
true,
desc.str());

viewer.Visualize();

return EXIT_SUCCESS;
}


void CreateImage(UnsignedCharImageType::Pointer image)
{
// Create an image
itk::Index<2> start;
start.Fill(0);

itk::Size<2> size;
size.Fill(100);

itk::ImageRegion<2> region(start, size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);

// Create a line of white pixels
for(unsigned int i = 40; i < 60; ++i)
{
itk::Index<2> pixel;
pixel.Fill(i);
image->SetPixel(pixel, 255);
}
}

0 comments on commit ec4182d

Please sign in to comment.