ITK/Examples/Cxx/Developer/ImageSource: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
No edit summary
(Deprecated content that is moved to sphinx)
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
==Description==
{{warning|1=The media wiki content on this page is no longer maintainedThe examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releasesIn many cases, the examples on this page no longer conform to the best practices for modern ITK versions.}}
This example demonstrates how to make a filter which produces an image.
 
==ITK Classes Demonstrated==
 
 
==ImageSourceExample.cxx==
<source lang="cpp">
#include "itkImage.h"
#include "itkImageFileWriter.h"
 
#include "ImageFilter.h"
 
int main(int, char*[])
{
  // Setup types
  typedef itk::Image<unsigned char, 2>  ImageType;
  typedef itk::ImageFilter<ImageType> FilterType;
 
  // Create and the filter
  FilterType::Pointer filter = FilterType::New();
  filter->Update();
 
  typedef  itk::ImageFileWriter< ImageType  > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName("Test.jpg");
  writer->SetInput(filter->GetOutput());
  writer->Update();
 
  return EXIT_SUCCESS;
}
</source>
 
==ImageSource.h==
<source lang="cpp">
#ifndef __itkImageFilter_h
#define __itkImageFilter_h
 
#include "itkImageSource.h"
 
namespace itk
{
template< class TOutputImage>
class ImageFilter:public ImageSource< TOutputImage >
{
public:
  /** Standard class typedefs. */
  typedef ImageFilter            Self;
  typedef ImageSource< TOutputImage > Superclass;
  typedef SmartPointer< Self >        Pointer;
 
  /** Method for creation through the object factory. */
  itkNewMacro(Self);
 
  /** Run-time type information (and related methods). */
   itkTypeMacro(ImageFilter, ImageSource);
 
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 "ImageFilter.txx"
#endif
 
 
#endif // __itkImageFilter_h
</source>
 
==ImageSource.txx==
<source lang="cpp">
#ifndef __itkImageFilter_txx
#define __itkImageFilter_txx
 
#include "ImageFilter.h"
 
#include "itkObjectFactory.h"
 
namespace itk
{
 
template< class TOutputImage>
void ImageFilter< 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
</source>
 
{{ITKCMakeLists|ImageSource}}

Latest revision as of 17:41, 7 June 2019

Warning: The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.