[Insight-users] Read Image - extract region - use median filter - write image
john smith
mkitkinsightuser at gmail.com
Thu Feb 17 09:51:49 EST 2011
Hello,
I use visualstudio2010 and I am trying to read an image, then extract a
region from the image and finally apply a median filter on the image's
extracted area, getting the final image using a writer object. I created the
four needed objects (reader, region, median filter, writer) as it is shown
in the code bellow. But when I built my project, I get the following
failure:(* 'FilterType' : redefinition; different basic types*). I can
understand that my wrong was that I used the same FilterType for both *
itk::RegionOfInterestImageFilter* and * itk::MedianImageFilter*, but I don't
know how to solve it. Any ideas?
Thanks in advance.
--------------------------code----------------------------
----------------------------------------------------
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkRegionOfInterestImageFilter.h"
#include "itkMedianImageFilter.h"
#include "itkImage.h"
int main( int argc, char ** argv )
{
// Verify the number of parameters in the command line
if( argc < 7 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImageFile outputImageFile " <<
std::endl;
std::cerr << " startX startY sizeX sizeY" << std::endl;
return EXIT_FAILURE;
}
// set pixel and image type
typedef unsigned short InputPixelType;
typedef unsigned short OutputPixelType;
const unsigned int Dimension = 2;
typedef itk::Image< InputPixelType, Dimension > InputImageType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
// set reader and writer object
typedef itk::ImageFileReader< InputImageType > ReaderType;
typedef itk::ImageFileWriter< OutputImageType > WriterType;
typedef itk::RegionOfInterestImageFilter< InputImageType,
OutputImageType > FilterType;
FilterType::Pointer region = FilterType::New();
// Software Guide : BeginCodeSnippet
OutputImageType::IndexType start;
start[0] = atoi( argv[3] );
start[1] = atoi( argv[4] );
// Software Guide : EndCodeSnippet
// start of region
OutputImageType::SizeType size;
size[0] = atoi( argv[5] );
size[1] = atoi( argv[6] );
// size of region
OutputImageType::RegionType desiredRegion;
desiredRegion.SetSize( size );
desiredRegion.SetIndex( start );
// Set region of interest
region->SetRegionOfInterest( desiredRegion );
// Create reader and writer object
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
// Set the input and output filename on the reader and writer respectively
const char * inputFilename = argv[1];
const char * outputFilename = argv[2];
reader->SetFileName( inputFilename );
writer->SetFileName( outputFilename );
//////////////////////////////////////////////
//////////////////////////////////////////////
// Set and create median filter
typedef itk::MedianImageFilter<
InputImageType, OutputImageType > FilterType;
FilterType::Pointer filter = FilterType::New();
// set the neighborhood of median filter. Here 3x3.
InputImageType::SizeType indexRadius;
indexRadius[0] = 1; // radius along x
indexRadius[1] = 1; // radius along y
filter->SetRadius( indexRadius );
/////////////////////////////////////////////////
///////////////////////////////////////
// pipeline
region->SetInput( reader->GetOutput() );
filter->SetInput( region->GetOutput() );
writer->SetInput( filter->GetOutput() );
// try-catch update of the filters
try
{
writer->Update();
}
catch( itk::ExceptionObject & err )
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110217/2f9283eb/attachment.htm>
More information about the Insight-users
mailing list