ITK/Examples/Developer/ImageFilterMultipleInputs: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(→‎ImageFilterMultipleInputs.txx: Add this-> before SetNthInput calls.)
(Deprecated content that is moved to sphinx)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==ImageFilterMultipleInputs.cxx==
{{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.}}
<source lang="cpp">
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
 
#include "ImageFilterMultipleInputs.h"
 
int main(int, char*[])
{
  // Setup types
  typedef itk::Image<unsigned char, 2>  ImageType;
  typedef itk::ImageFilterMultipleInputs<ImageType> FilterType;
 
  typedef itk::ImageFileReader<ImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName("Test.jpg");
  reader->Update();
 
  // Create and the filter
  FilterType::Pointer filter = FilterType::New();
  filter->SetInput(reader->GetOutput());
  filter->Update();
 
  typedef  itk::ImageFileWriter< ImageType  > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName("TestOutput.jpg");
  writer->SetInput(filter->GetOutput());
  writer->Update();
 
  return EXIT_SUCCESS;
}
</source>
 
==ImageFilterMultipleInputs.h==
<source lang="cpp">
#ifndef __itkImageFilterMultipleInputs_h
#define __itkImageFilterMultipleInputs_h
 
#include "itkImageToImageFilter.h"
 
namespace itk
{
template< class TImage>
class ImageFilterMultipleInputs : public ImageToImageFilter< TImage, TImage >
{
public:
  /** Standard class typedefs. */
  typedef ImageFilterMultipleInputs            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(ImageFilterMultipleInputs, ImageToImageFilter);
 
  /** The image to be inpainted in regions where the mask is white.*/
  void SetInputImage(const TImage* image);
 
  /** The mask to be inpainted. White pixels will be inpainted, black pixels will be passed through to the output.*/
  void SetInputMask(const TImage* mask);
 
protected:
  ImageFilterMultipleInputs();
  ~ImageFilterMultipleInputs(){}
 
  /** Does the real work. */
  virtual void GenerateData();
 
private:
  ImageFilterMultipleInputs(const Self &); //purposely not implemented
  void operator=(const Self &);  //purposely not implemented
 
};
} //namespace ITK
 
 
#ifndef ITK_MANUAL_INSTANTIATION
#include "ImageFilterMultipleInputs.txx"
#endif
 
 
#endif // __itkImageFilterMultipleInputs_h
</source>
 
==ImageFilterMultipleInputs.txx==
<source lang="cpp">
#ifndef __itkImageFilterMultipleInputs_txx
#define __itkImageFilterMultipleInputs_txx
 
#include "ImageFilterMultipleInputs.h"
 
#include "itkObjectFactory.h"
#include "itkImageRegionIterator.h"
#include "itkImageRegionConstIterator.h"
 
namespace itk
{
 
template< class TImage>
ImageFilterMultipleInputs<TImage>::ImageFilterMultipleInputs()
{
  this->SetNumberOfRequiredInputs(2);
}
 
template< class TImage>
void ImageFilterMultipleInputs<TImage>::SetInputImage(const TImage* image)
{
  this->SetNthInput(0, const_cast<TImage*>(image));
}
 
template< class TImage>
void ImageFilterMultipleInputs<TImage>::SetInputMask(const TImage* mask)
{
  this->SetNthInput(1, const_cast<TImage*>(mask));
}
 
template< class TImage>
void ImageFilterMultipleInputs<TImage>::GenerateData()
{
  typename TImage::ConstPointer input = this->GetInput();
 
  typename TImage::Pointer output = this->GetOutput();
  output->SetRegions(input->GetLargestPossibleRegion());
  output->Allocate(); 
 
  itk::ImageRegionIterator<TImage> outputIterator(output, output->GetLargestPossibleRegion());
  itk::ImageRegionConstIterator<TImage> inputIterator(input, input->GetLargestPossibleRegion());
 
  while(!outputIterator.IsAtEnd())
    {
    if(inputIterator.GetIndex()[0] == inputIterator.GetIndex()[1])
      {
      outputIterator.Set(255);
      }
    else
      {
      outputIterator.Set(inputIterator.Get());
      }
 
    ++inputIterator;
    ++outputIterator;
    }
 
}
 
}// end namespace
 
 
#endif
</source>
 
{{ITKCMakeLists|{{SUBPAGENAME}}}}

Latest revision as of 19:19, 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.