ITK/Examples/Smoothing/BilateralImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Now uses QuickView. thjis is an experiment.)
(Use QuickView)
Line 2: Line 2:
<source lang="cpp">
<source lang="cpp">
#include "itkImage.h"
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImageFileWriter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkBilateralImageFilter.h"
#include "itkAbsImageFilter.h"


#include "QuickView.h"
#include "QuickView.h"


int main(int argc, char * argv[])
typedef itk::Image<unsigned char, 2>  UnsignedCharImageType;
typedef itk::Image<float, 2>  FloatImageType;
 
static void CreateImage(FloatImageType::Pointer image);
 
int main(int, char *[])
{
{
   // Verify command line arguments
   FloatImageType::Pointer image = FloatImageType::New();
  if( argc < 2 )
  CreateImage(image);
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << "inputImageFile" << std::endl;
    return EXIT_FAILURE;
    }


   // Parse command line arguments
   // Take the absolute value of the image
   std::string inputFilename = argv[1];
   typedef itk::AbsImageFilter <FloatImageType, FloatImageType>
          AbsImageFilterType;


   // Setup types
   AbsImageFilterType::Pointer absFilter
  typedef itk::Image< unsigned char, 2 >   UnsignedCharImageType;
          = AbsImageFilterType::New ();
  absFilter->SetInput(image);


   typedef itk::ImageFileReader< UnsignedCharImageType > readerType;
   QuickView viewer;
  viewer.AddImage<FloatImageType>(image);
  viewer.AddImage<FloatImageType>(absFilter->GetOutput());
  viewer.Visualize();


   typedef itk::BilateralImageFilter<
   return EXIT_SUCCESS;
    UnsignedCharImageType, UnsignedCharImageType >  filterType;
}


   // Create and setup a reader
void CreateImage(FloatImageType::Pointer image)
   readerType::Pointer reader = readerType::New();
{
   reader->SetFileName( inputFilename.c_str() );
   // Create an image with negative values
   FloatImageType::RegionType region;
  FloatImageType::IndexType start;
  start[0] = 0;
   start[1] = 0;


   // Create and setup a derivative filter
   FloatImageType::SizeType size;
   filterType::Pointer bilateralFilter = filterType::New();
   size[0] = 200;
   bilateralFilter->SetInput( reader->GetOutput() );
   size[1] = 300;


   QuickView viewer;
   region.SetSize(size);
   viewer.AddImage(reader->GetOutput());
   region.SetIndex(start);
   viewer.AddImage(bilateralFilter->GetOutput());
 
   viewer.Visualize();
  image->SetRegions(region);
   image->Allocate();
 
   itk::ImageRegionIterator<FloatImageType> imageIterator(image,region);


   return EXIT_SUCCESS;
   while(!imageIterator.IsAtEnd())
    {
    imageIterator.Set(imageIterator.GetIndex()[0] - imageIterator.GetIndex()[1]);
    ++imageIterator;
    }
 
}
}
</source>
</source>

Revision as of 00:31, 18 November 2010

BilateralImageFilter.cxx

<source lang="cpp">

  1. include "itkImage.h"
  2. include "itkImageFileWriter.h"
  3. include "itkRescaleIntensityImageFilter.h"
  4. include "itkAbsImageFilter.h"
  1. include "QuickView.h"

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

static void CreateImage(FloatImageType::Pointer image);

int main(int, char *[]) {

 FloatImageType::Pointer image = FloatImageType::New();
 CreateImage(image);
 // Take the absolute value of the image
 typedef itk::AbsImageFilter <FloatImageType, FloatImageType>
         AbsImageFilterType;
 AbsImageFilterType::Pointer absFilter
         = AbsImageFilterType::New ();
 absFilter->SetInput(image);
 QuickView viewer;
 viewer.AddImage<FloatImageType>(image);
 viewer.AddImage<FloatImageType>(absFilter->GetOutput());
 viewer.Visualize();
 return EXIT_SUCCESS;

}

void CreateImage(FloatImageType::Pointer image) {

 // Create an image with negative values
 FloatImageType::RegionType region;
 FloatImageType::IndexType start;
 start[0] = 0;
 start[1] = 0;
 FloatImageType::SizeType size;
 size[0] = 200;
 size[1] = 300;
 region.SetSize(size);
 region.SetIndex(start);
 image->SetRegions(region);
 image->Allocate();
 itk::ImageRegionIterator<FloatImageType> imageIterator(image,region);
 while(!imageIterator.IsAtEnd())
   {
   imageIterator.Set(imageIterator.GetIndex()[0] - imageIterator.GetIndex()[1]);
   ++imageIterator;
   }
 

} </source>

CMakeLists.txt

<source lang="cmake"> cmake_minimum_required(VERSION 2.6)

PROJECT(BilateralImageFilter)

include_directories(/home/doriad/src/ITK/Wrapping/WrapITK/ExternalProjects/ItkVtkGlue/src/)

FIND_PACKAGE(VTK REQUIRED) INCLUDE(${VTK_USE_FILE})

FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})

ADD_EXECUTABLE(BilateralImageFilter BilateralImageFilter.cxx) TARGET_LINK_LIBRARIES(BilateralImageFilter vtkHybrid ITKBasicFilters ITKIO ITKCommon)

</source>