[Insight-users] Re: AntiAliasBinaryImageFilter

Luis Ibanez luis.ibanez at kitware.com
Tue Nov 2 15:12:27 EST 2004


Hi Alam,

Please try the second part of my email.
It will be much simpler.

For your convenience, I'm attaching the example
program to this email.

Yo will just need to create a MetaImage header
for your RAW image.


    Regards,


       Luis



-----------------------
Alam, Mohammed wrote:

> Hi Luis;
> 
> I have already tried your first part of email. I did change the typedef
> = unsigned short. I am also attaching my sample.parameters file with
> this email.
> 
> I am still getting the same error :ImageFileWriter: No ImageIO, or none
> could be created. If you want I can send you my raw image too.
> 
> Thanks
> Alam
> 
> -----Original Message-----
> From: Luis Ibanez [mailto:luis.ibanez at kitware.com] 
> Sent: Tuesday, November 02, 2004 2:44 PM
> To: Alam, Mohammed
> Cc: Insight-users at itk.org
> Subject: Re: AntiAliasBinaryImageFilter
> 
> 
> Hi Alam,
> 
> Please read the README.txt file in the directory
> 
>     InsightApplications/
>         AntiAliasBinaryImageFilter
> 
> It tells you that you have to modify the file:
> 
>      itkAntiaAliasBinaryImageFilterExample.cxx
> 
> at line 41:
> 
>      typedef char InputDataType;
> 
> if you want ot read Raw files of pixel type different
> from char.
> 
> In your particular case, you want to change
> this typedef to be:
> 
>      typedef unsigned short InputDataType;
> 
> Then you have to fill in the information of the parameter
> file, as explained in the README.txt file.
> 
> 
> --------
> 
> 
> For your convenience we just added a simple example
> on how to use this filter.
> 
> You will find this new example under
> 
> 
>     Insight/Examples/Filtering/
>                AntiAliasBinaryImageFilter.cxx
> 
> 
> It expects a 3D image as input and produces as output the
> antialiased version of the input image.
> 
> 
> You will have to update your CVS checkout in order to
> get this new example. Or, you can download it directly
> from the following link to the CVS-Web portal
> 
> http://www.itk.org/cgi-bin/viewcvs.cgi/Examples/Filtering/AntiAliasBinar
> yImageFilter.cxx?rev=1.1&root=Insight&view=log
> 
> In order to read your RAW images into this program,
> you can create a MetaImage header for those files.
> Please follow the instructions posted in the previous email:
> http://www.itk.org/pipermail/insight-users/2004-November/010906.html
> 
> 
> NOTE that you still have to make sure that the pixel
> type used in the ImageFileReader matches the pixel
> type of your files.
> 
> 
> 
> Please let us know if you have any further questions,
> 
> 
>       Thanks
> 
> 
>          Luis
> 
> 
> 
> ------------------
> 
> 
> 
> Alam, Mohammed wrote:
> 
>>Hi Luis,
>>
>>I am trying to use the AntiAliasBinaryImageFilter. I am using an
>>unsigned short raw file of total 74 images and an unsigned_Char raw
>>binary file. 
>>
>>However the program keeps terminating and says the raw file has a
> 
> syntax
> 
>>error. Can you help me with this filter? I can send you the raw files
> 
> if
> 
>>you need.
>>
>>Thanks
>>Alam
>>
>>
>>
>>
> 
> 
> 
> 
> 
====================================================



-------------- next part --------------
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: AntiAliasBinaryImageFilter.cxx,v $
  Language:  C++
  Date:      $Date: 2004/11/02 19:43:34 $
  Version:   $Revision: 1.1 $

  Copyright (c) 2002 Insight Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/


//  Software Guide : BeginLatex
//
//  This example introduces the use of the \doxygen{AntiAliasBinaryImageFilter}. This
//  filter expect a binary mask as input, and using Level Sets it smooths the
//  image by keeping the edge of the structure within 1 pixel distance from the
//  original location. It is usually desirable to run this filter before
//  extracting isocontour with surface extraction methods. 
//  
//  \index{itk::AntiAliasBinaryImageFilter|textbf}
//
//  Software Guide : EndLatex 


#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkCastImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"


//  Software Guide : BeginLatex
//
//  The first step required for using this filter is to include its header file
//
//  \index{itk::AntiAliasBinaryImageFilter!header}
//
//  Software Guide : EndLatex 


// Software Guide : BeginCodeSnippet
#include "itkAntiAliasBinaryImageFilter.h"
// Software Guide : EndCodeSnippet


int main(int argc, char** argv)
{
  if( argc < 3 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " inputImage outputImage [RMS] [numberOfIterations]" << std::endl;
    return -1;
    }
   
  const char * inputFilename  = argv[1];
  const char * outputFilename = argv[2];
  double maximumRMSError = 0.01;
  unsigned int numberOfIterations = 50;

  if( argc > 3 )
    {
    maximumRMSError = atof( argv[3] );
    }

  if( numberOfIterations > 4 )
    {
    numberOfIterations = atoi( argv[4] );
    }


  typedef unsigned char    CharPixelType;  //  IO
  typedef double           RealPixelType;  //  Operations
  const   unsigned int     Dimension = 3;

  typedef itk::Image<CharPixelType, Dimension>    CharImageType;
  typedef itk::Image<RealPixelType, Dimension>    RealImageType;

  typedef itk::ImageFileReader< CharImageType >  ReaderType;
  typedef itk::ImageFileWriter< CharImageType >  WriterType;




  //  Software Guide : BeginLatex
  //
  //  This filter operates on image of pixel type float. It is then necessary
  //  to cast the type of the input images that are usually of integer type.
  //  The \doxygen{CastImageFilter} is used here for that purpose. Its image 
  //  template parameters are defined for casting from the input type to the
  //  float type using for processing.
  //
  //  Software Guide : EndLatex

  // Software Guide : BeginCodeSnippet
  typedef itk::CastImageFilter< CharImageType, RealImageType> CastToRealFilterType;
  // Software Guide : EndCodeSnippet



  typedef itk::RescaleIntensityImageFilter<RealImageType, CharImageType > RescaleFilter;


  //  Software Guide : BeginLatex
  //
  //  The \doxygen{AntiAliasBinaryImageFilter} is instantiated using the float image type.
  //
  //  \index{itk::AntiAliasBinaryImageFilter|textbf}
  //
  //  Software Guide : EndLatex


  typedef itk::AntiAliasBinaryImageFilter<RealImageType, RealImageType> AntiAliasFilterType;

  //Setting the IO

  ReaderType::Pointer reader = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();

  CastToRealFilterType::Pointer toReal = CastToRealFilterType::New();
  RescaleFilter::Pointer rescale = RescaleFilter::New();

  //Setting the ITK pipeline filter

  // Software Guide : BeginCodeSnippet
  AntiAliasFilterType::Pointer antiAliasFilter = AntiAliasFilterType::New();

  reader->SetFileName( inputFilename  );
  writer->SetFileName( outputFilename );

  //The output of an edge filter is 0 or 1
  rescale->SetOutputMinimum(   0 );
  rescale->SetOutputMaximum( 255 );

  toReal->SetInput( reader->GetOutput() );

  antiAliasFilter->SetInput( toReal->GetOutput() );
  
  antiAliasFilter->SetMaximumRMSError( maximumRMSError );
  antiAliasFilter->SetNumberOfIterations( numberOfIterations );
  antiAliasFilter->SetNumberOfLayers( 2 );
  
  rescale->SetInput( antiAliasFilter->GetOutput() );
  writer->SetInput( rescale->GetOutput() );

  try 
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & err ) 
    { 
    std::cout << "ExceptionObject caught !" << std::endl; 
    std::cout << err << std::endl; 
    return -1;
    } 

  // Software Guide : EndCodeSnippet

  return 0;

}


More information about the Insight-users mailing list