ITK  5.2.0
Insight Toolkit
SphinxExamples/src/Filtering/ImageStatistics/ComputePCAShapeFromSample/Code.cxx
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
/*
Author: Juan Cardelino <juan dot cardelino at gmail dot com>
*/
// ITK
#include "itkCommand.h"
#include "itkImage.h"
// VNL
#include "vnl/vnl_sample.h"
int
main(int argc, char * argv[])
{
if (argc < 5)
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " nbTrain trainFilePattern";
std::cerr << " nbModes modeFilePattern";
std::cerr << std::endl;
return 1;
}
for (int i = 0; i < argc; i++)
{
std::cout << "id: " << i << " arg: " << argv[i] << std::endl;
}
constexpr unsigned int Dimension = 2;
using my_PixelType = float;
using ReaderType = itk::ImageFileReader<ImageType>;
using WriterType = itk::ImageFileWriter<ImageType>;
unsigned int nb_train = atoi(argv[1]);
std::vector<ImageType::Pointer> trainingImages(nb_train);
fileNamesCreator->SetStartIndex(0);
fileNamesCreator->SetEndIndex(nb_train - 1);
fileNamesCreator->SetSeriesFormat(argv[2]);
const std::vector<std::string> & shapeModeFileNames = fileNamesCreator->GetFileNames();
for (unsigned int k = 0; k < nb_train; k++)
{
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(shapeModeFileNames[k].c_str());
reader->Update();
trainingImages[k] = reader->GetOutput();
}
my_Estimatortype::Pointer filter = my_Estimatortype::New();
filter->SetNumberOfTrainingImages(nb_train);
filter->SetNumberOfPrincipalComponentsRequired(2);
for (unsigned int k = 0; k < nb_train; k++)
{
filter->SetInput(k, trainingImages[k]);
}
unsigned int nb_modes = atoi(argv[3]);
fileNamesOutCreator->SetStartIndex(0);
fileNamesOutCreator->SetEndIndex(nb_modes - 1);
fileNamesOutCreator->SetSeriesFormat(argv[4]);
const std::vector<std::string> & outFileNames = fileNamesOutCreator->GetFileNames();
ScaleType::Pointer scaler = ScaleType::New();
filter->Update();
my_Estimatortype::VectorOfDoubleType v = filter->GetEigenValues();
double sv_mean = sqrt(v[0]);
for (unsigned int k = 0; k < nb_modes; k++)
{
double sv = sqrt(v[k]);
double sv_n = sv / sv_mean;
// double sv_n=sv;
std::cout << "writing: " << outFileNames[k] << std::endl;
std::cout << "svd[" << k << "]: " << sv << " norm: " << sv_n << std::endl;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outFileNames[k].c_str());
scaler->SetInput(filter->GetOutput(k));
scaler->SetConstant(sv_n);
writer->SetInput(scaler->GetOutput());
writer->Update();
}
return EXIT_SUCCESS;
}
itkSpatialFunctionImageEvaluatorFilter.h
itkEuler2DTransform.h
itkImagePCAShapeModelEstimator.h
itkImageFileReader.h
itkImage.h
itk::SmartPointer< Self >
itk::ImagePCAShapeModelEstimator
Base class for ImagePCAShapeModelEstimator object.
Definition: itkImagePCAShapeModelEstimator.h:76
itkFastMarchingImageFilter.h
itk::ImageFileReader
Data source that reads image data from a single file.
Definition: itkImageFileReader.h:75
itkNumericSeriesFileNames.h
itkCurvatureAnisotropicDiffusionImageFilter.h
itk::ImageFileWriter
Writes image data to a single file.
Definition: itkImageFileWriter.h:87
itkBoundedReciprocalImageFilter.h
itkOnePlusOneEvolutionaryOptimizer.h
itkMultiplyImageFilter.h
itkRescaleIntensityImageFilter.h
itk::NumericSeriesFileNames::New
static Pointer New()
itkImageFileWriter.h
itkNormalVariateGenerator.h
itkShapePriorMAPCostFunction.h
itkBinaryThresholdImageFilter.h
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86
itkGeodesicActiveContourShapePriorLevelSetImageFilter.h
itk::MultiplyImageFilter
Pixel-wise multiplication of two images.
Definition: itkMultiplyImageFilter.h:43
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44
itkCommand.h
itkChangeInformationImageFilter.h
itkPCAShapeSignedDistanceFunction.h
itkGradientMagnitudeRecursiveGaussianImageFilter.h