[Insight-users] function arguments
Mario Ceresa
mrceresa at gmail.com
Tue Dec 15 06:05:49 EST 2009
Hello Jesus,
If you always want to use a given image type (such as itk::Image<
float, 3 > ) then you can pass the image as a pointer. You'll find an
example attached.
On the other hand, if you want to encapsulate your code into something
you can apply to various image types, then you want to create a filter
and use template programming. You can look at the developer section of
http://www.itk.org/ItkSoftwareGuide.pdf
to learn how.
Hope this helps,
Mario
2009/12/14 Jesus Piairo <jp.ineb.dsi at gmail.com>:
> Hello!!
>
> I´m trying to reorganize my code using functions but i´m having problems
> with the arguments for the functions.
>
> I have 2 functions: main function and filtroGauss
>
> In main function a read an image from a file;
>
> In filtroGaus function i want to aply an gaussian filter, the argument
> should be the image that was read in main function.
>
> How can I do this correctly??
>
> Thkns in advance!
>
> Regards.
>
> JP
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
cmake_minimum_required(VERSION 2.6)
PROJECT(test)
FIND_PACKAGE(ITK)
IF(ITK_FOUND)
INCLUDE(${ITK_USE_FILE})
ELSE(ITK_FOUND)
MESSAGE(FATAL_ERROR
"ITK not found. Please set ITK_DIR.")
ENDIF(ITK_FOUND)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
ADD_EXECUTABLE(test test.cxx)
TARGET_LINK_LIBRARIES(test ITKCommon ITKIO)
-------------- next part --------------
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkDiscreteGaussianImageFilter.h"
typedef float PixelType;
typedef itk::Image< PixelType, 3 > ImageType;
ImageType::Pointer filtroGauss(ImageType::Pointer, double , unsigned int);
int main (int argc, char **argv ) {
typedef itk::ImageFileReader < ImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
try
{
reader->Update();
}
catch( itk::ExceptionObject & err )
{
std::cerr << "ExceptionObject caught!" << std::endl;
std::cerr << err << std::endl;
return 1;
}
ImageType::Pointer pImg = reader->GetOutput();
const double gaussianVariance = atof( argv[3] );
const unsigned int maxKernelWidth = atoi( argv[4] );
// Pass a pointer to the image
ImageType::Pointer pGauss = filtroGauss(pImg, gaussianVariance, maxKernelWidth);
// Write the result
typedef itk::ImageFileWriter < ImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetInput( pGauss );
writer->SetFileName( argv[2] );
try
{
writer->Update();
}
catch( itk::ExceptionObject & err )
{
std::cerr << "ExceptionObject caught!" << std::endl;
std::cerr << err << std::endl;
return 1;
}
}
ImageType::Pointer filtroGauss(ImageType::Pointer pInputImage, double gaussianVariance, unsigned int maxKernelWidth) {
// Do something
typedef itk::DiscreteGaussianImageFilter< ImageType, ImageType > FilterType;
FilterType::Pointer filter = FilterType::New();
filter->SetInput( pInputImage );
filter->SetVariance( gaussianVariance );
filter->SetMaximumKernelWidth( maxKernelWidth );
filter->Update();
// return result
return filter->GetOutput();
}
More information about the Insight-users
mailing list