1 #include <tclap/CmdLine.h> 5 #include <itkVectorImage.h> 9 template <
class ImageType>
10 void performSmoothing (std::string &inStr, std::string &outStr,
double sigma,
unsigned int nThreads)
14 typename ImageType::Pointer currentImage = anima::readImage <ImageType> (inStr);
15 currentImage->DisconnectPipeline();
17 double meanSpacing = currentImage->GetSpacing()[0];
18 for (
unsigned int i = 1;i < ImageType::ImageDimension;++i)
19 meanSpacing += currentImage->GetSpacing()[i];
20 meanSpacing /= ImageType::ImageDimension;
22 typename SmoothingFilterType::Pointer smoothFilter = SmoothingFilterType::New();
24 smoothFilter->SetInput(currentImage);
25 smoothFilter->SetNumberOfWorkUnits(nThreads);
26 smoothFilter->SetSigma(sigma * meanSpacing);
28 smoothFilter->Update();
31 anima::writeImage <ImageType> (outStr,smoothFilter->GetOutput());
34 int main(
int argc,
char **argv)
36 std::string descriptionMessage =
"Performs Gaussian smoothing of an image\n";
37 descriptionMessage +=
"INRIA / IRISA - VisAGeS/Empenn Team";
39 TCLAP::CmdLine cmd(descriptionMessage,
' ',ANIMA_VERSION);
41 TCLAP::ValueArg<std::string> inArg(
"i",
"input",
"Input image",
true,
"",
"input image",cmd);
42 TCLAP::ValueArg<std::string> outArg(
"o",
"outputfile",
"output image",
true,
"",
"output image",cmd);
44 TCLAP::ValueArg<double> sigmaArg(
"s",
"sigma",
"sigma value of Gaussian kernel",
false,1.0,
"sigma value",cmd);
46 TCLAP::ValueArg<unsigned int> nbpArg(
"T",
"numberofthreads",
"Number of threads to run on (default : all cores)",
false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),
"number of threads",cmd);
52 catch (TCLAP::ArgException& e)
54 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
58 typedef itk::Image <double,3> ImageType;
59 typedef itk::VectorImage <double,3> VectorImageType;
61 itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(inArg.getValue().c_str(),
62 itk::ImageIOFactory::ReadMode);
66 std::cerr <<
"Itk could not find suitable IO factory for the input" << std::endl;
71 imageIO->SetFileName(inArg.getValue());
72 imageIO->ReadImageInformation();
74 bool vectorImage = (imageIO->GetNumberOfComponents() > 1);
77 performSmoothing<VectorImageType>(inArg.getValue(),outArg.getValue(),sigmaArg.getValue(),nbpArg.getValue());
79 performSmoothing<ImageType>(inArg.getValue(),outArg.getValue(),sigmaArg.getValue(),nbpArg.getValue());
int main(int argc, char **argv)
void performSmoothing(std::string &inStr, std::string &outStr, double sigma, unsigned int nThreads)