本文整理汇总了C++中castertype::Pointer::SetInput方法的典型用法代码示例。如果您正苦于以下问题:C++ Pointer::SetInput方法的具体用法?C++ Pointer::SetInput怎么用?C++ Pointer::SetInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类castertype::Pointer
的用法示例。
在下文中一共展示了Pointer::SetInput方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MyCastPixelType
void QmitkVirtualSurgery::MyCastPixelType(itk::Image<TPixel, VImageDimension> *itkImage, mitk::Image::Pointer *pointer)
{
std::cout<< "Function MyCastPixelType :Begin."<<std::endl;
/***************duplicate a image to clip 8 segment******************/
typedef itk::Image<TPixel, VImageDimension> TImageType;
typedef itk::ImageDuplicator< typename TImageType > DuplicatorType;
DuplicatorType::Pointer duplicator = DuplicatorType::New();
duplicator->SetInputImage( itkImage );
duplicator->Update();
typename TImageType::Pointer clonedImage = duplicator->GetOutput();
mitk::Image::Pointer resultImage = mitk::ImportItkImage( clonedImage );
mitk::DataTreeNode::Pointer newNode = mitk::DataTreeNode::New();
newNode->SetData(resultImage);
newNode->SetProperty("name", mitk::StringProperty::New("Liver Image"));
newNode->SetProperty("opacity", mitk::FloatProperty::New(0.0));
mitk::DataStorage::GetInstance()->Add( newNode );
mitk::RenderingManager::GetInstance()->RequestUpdateAll();
/*********************************************************************/
//originalPixelType = (dynamic_cast<mitk::Image *>(selectedImage->Get()->GetData()))->GetPixelType();
if (originalPixelType == typeid(float))
{
std::cout<< "Function MyCastPixelType : Origin image pixel type is float."<<std::endl;
*pointer = mitk::ImportItkImage(itkImage);
}
else
{
typedef itk::Image<TPixel, VImageDimension> InputImageType;
typedef float OutputImagePixelType;
typedef itk::Image<OutputImagePixelType, VImageDimension> OutputImageType;
typedef itk::CastImageFilter<InputImageType, OutputImageType> CasterType;
CasterType::Pointer caster = CasterType::New();
caster->SetInput(itkImage);
try
{
caster->Update();
}
catch( itk::ExceptionObject & excp )
{
std::cerr << "CastPixelType exception thrown."
<< std::endl;
std::cerr << excp << std::endl;
return ;
}
OutputImageType::Pointer output = caster->GetOutput();
*pointer = mitk::ImportItkImage(output);
}
std::cout<< "Function MyCastPixelType End."<<std::endl;
}
示例2: TemplatedConvertShCoeffs
typename itk::ShCoefficientImageImporter< float, shOrder >::QballImageType::Pointer TemplatedConvertShCoeffs(mitk::Image* mitkImg, int toolkit, bool noFlip = false)
{
typedef itk::ShCoefficientImageImporter< float, shOrder > FilterType;
typedef mitk::ImageToItk< itk::Image< float, 4 > > CasterType;
CasterType::Pointer caster = CasterType::New();
caster->SetInput(mitkImg);
caster->Update();
itk::Image< float, 4 >::Pointer itkImage = caster->GetOutput();
typename FilterType::Pointer filter = FilterType::New();
if (noFlip)
{
filter->SetInputImage(itkImage);
}
else
{
MITK_INFO << "Flipping image";
itk::FixedArray<bool, 4> flipAxes;
flipAxes[0] = true;
flipAxes[1] = true;
flipAxes[2] = false;
flipAxes[3] = false;
itk::FlipImageFilter< itk::Image< float, 4 > >::Pointer flipper = itk::FlipImageFilter< itk::Image< float, 4 > >::New();
flipper->SetInput(itkImage);
flipper->SetFlipAxes(flipAxes);
flipper->Update();
itk::Image< float, 4 >::Pointer flipped = flipper->GetOutput();
itk::Matrix< double,4,4 > m = itkImage->GetDirection(); m[0][0] *= -1; m[1][1] *= -1;
flipped->SetDirection(m);
itk::Point< float, 4 > o = itkImage->GetOrigin();
o[0] -= (flipped->GetLargestPossibleRegion().GetSize(0)-1);
o[1] -= (flipped->GetLargestPossibleRegion().GetSize(1)-1);
flipped->SetOrigin(o);
filter->SetInputImage(flipped);
}
switch (toolkit)
{
case 0:
filter->SetToolkit(FilterType::FSL);
break;
case 1:
filter->SetToolkit(FilterType::MRTRIX);
break;
default:
filter->SetToolkit(FilterType::FSL);
}
filter->GenerateData();
return filter->GetQballImage();
}
示例3: CompareImages
void CompareImages(mitk::PeakImage::ItkPeakImageType::Pointer testImage, std::string name)
{
typedef mitk::ImageToItk< mitk::PeakImage::ItkPeakImageType > CasterType;
CasterType::Pointer caster = CasterType::New();
caster->SetInput(mitk::IOUtil::Load<mitk::Image>(GetTestDataFilePath("DiffusionImaging/FiberFit/out/" + name)));
caster->Update();
mitk::PeakImage::ItkPeakImageType::Pointer refImage = caster->GetOutput();
itk::ImageRegionConstIterator< mitk::PeakImage::ItkPeakImageType > it1(testImage, testImage->GetLargestPossibleRegion());
itk::ImageRegionConstIterator< mitk::PeakImage::ItkPeakImageType > it2(refImage, refImage->GetLargestPossibleRegion());
while(!it1.IsAtEnd())
{
if (it2.Get()>0.0001)
{
if (fabs( it1.Get()/it2.Get()-1 )>0.01)
{
itk::ImageFileWriter< mitk::PeakImage::ItkPeakImageType >::Pointer writer = itk::ImageFileWriter< mitk::PeakImage::ItkPeakImageType >::New();
writer->SetInput(testImage);
writer->SetFileName(mitk::IOUtil::GetTempPath()+name);
writer->Update();
MITK_INFO << it1.Get() << " - " << it2.Get();
CPPUNIT_ASSERT_MESSAGE("Peak images should be equal 1", false);
}
}
else if (it1.Get()>0.0001)
{
itk::ImageFileWriter< mitk::PeakImage::ItkPeakImageType >::Pointer writer = itk::ImageFileWriter< mitk::PeakImage::ItkPeakImageType >::New();
writer->SetInput(testImage);
writer->SetFileName(mitk::IOUtil::GetTempPath()+name);
writer->Update();
CPPUNIT_ASSERT_MESSAGE("Peak images should be equal 2", false);
}
++it1;
++it2;
}
}
示例4: ConvertImage
// ------------------------------------------------------------------------
void OpenCVValve::ConvertImage(const ImageType::Pointer &input, MatPtr &mat)
{
// cast the image to uchar
typedef itk::Image<unsigned char, 2> OutputImageType;
typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> CasterType;
CasterType::Pointer caster = CasterType::New();
caster->SetOutputMaximum(255);
caster->SetOutputMinimum(0);
caster->SetInput(input);
caster->Update();
OutputImageType::Pointer output = caster->GetOutput();
typedef itk::ImageFileWriter<OutputImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetImageIO(itk::PNGImageIO::New());
writer->SetInput(output);
writer->SetFileName("test.png");
writer->Update();
ImageType::SizeType size = input->GetLargestPossibleRegion().GetSize();
unsigned int rows = size[1];
unsigned int cols = size[0];
mat = new MatType(rows,cols, CV_8UC1);
itk::ImageRegionConstIterator<OutputImageType> it(output, output->GetLargestPossibleRegion());
it.GoToBegin();
while(!it.IsAtEnd())
{
OutputImageType::IndexType index = it.GetIndex();
unsigned char val = it.Get();
mat->at<unsigned char>(cv::Point(index[0], index[1])) = val;
++it;
}
}
示例5: setUp
void setUp() override
{
std::vector<mitk::FiberBundle::Pointer> tracts;
tracts.push_back(LoadFib("Cluster_0.fib"));
tracts.push_back(LoadFib("Cluster_1.fib"));
tracts.push_back(LoadFib("Cluster_2.fib"));
tracts.push_back(LoadFib("Cluster_3.fib"));
tracts.push_back(LoadFib("Cluster_4.fib"));
mitk::PreferenceListReaderOptionsFunctor functor = mitk::PreferenceListReaderOptionsFunctor({"Peak Image"}, {});
mitk::PeakImage::Pointer peaks = mitk::IOUtil::Load<mitk::PeakImage>(GetTestDataFilePath("DiffusionImaging/FiberFit/csd_peak_image.nii.gz"), &functor);
typedef mitk::ImageToItk< mitk::PeakImage::ItkPeakImageType > CasterType;
CasterType::Pointer caster = CasterType::New();
caster->SetInput(peaks);
caster->Update();
mitk::PeakImage::ItkPeakImageType::Pointer peak_image = caster->GetOutput();
fitter = FitterType::New();
fitter->SetPeakImage(peak_image);
fitter->SetTractograms(tracts);
}
示例6: TemplatedConvertShCoeffs
typename itk::ShCoefficientImageImporter< float, shOrder >::QballImageType::Pointer TemplatedConvertShCoeffs(mitk::Image* mitkImg, int toolkit)
{
typedef itk::ShCoefficientImageImporter< float, shOrder > FilterType;
typedef mitk::ImageToItk< itk::Image< float, 4 > > CasterType;
CasterType::Pointer caster = CasterType::New();
caster->SetInput(mitkImg);
caster->Update();
typename FilterType::Pointer filter = FilterType::New();
switch (toolkit)
{
case 0:
filter->SetToolkit(FilterType::FSL);
break;
case 1:
filter->SetToolkit(FilterType::MRTRIX);
break;
default:
filter->SetToolkit(FilterType::FSL);
}
filter->SetInputImage(caster->GetOutput());
filter->GenerateData();
return filter->GetQballImage();
}
示例7: mitkLocalFiberPlausibilityTest
int mitkLocalFiberPlausibilityTest(int argc, char* argv[])
{
MITK_TEST_BEGIN("mitkLocalFiberPlausibilityTest");
MITK_TEST_CONDITION_REQUIRED(argc==8,"check for input data")
string fibFile = argv[1];
vector< string > referenceImages;
referenceImages.push_back(argv[2]);
referenceImages.push_back(argv[3]);
string LDFP_ERROR_IMAGE = argv[4];
string LDFP_NUM_DIRECTIONS = argv[5];
string LDFP_VECTOR_FIELD = argv[6];
string LDFP_ERROR_IMAGE_IGNORE = argv[7];
float angularThreshold = 25;
try
{
typedef itk::Image<unsigned char, 3> ItkUcharImgType;
typedef itk::Image< itk::Vector< float, 3>, 3 > ItkDirectionImage3DType;
typedef itk::VectorContainer< unsigned int, ItkDirectionImage3DType::Pointer > ItkDirectionImageContainerType;
typedef itk::EvaluateDirectionImagesFilter< float > EvaluationFilterType;
// load fiber bundle
mitk::FiberBundleX::Pointer inputTractogram = dynamic_cast<mitk::FiberBundleX*>(mitk::IOUtil::LoadDataNode(fibFile)->GetData());
// load reference directions
ItkDirectionImageContainerType::Pointer referenceImageContainer = ItkDirectionImageContainerType::New();
for (unsigned int i=0; i<referenceImages.size(); i++)
{
try
{
mitk::Image::Pointer img = dynamic_cast<mitk::Image*>(mitk::IOUtil::LoadDataNode(referenceImages.at(i))->GetData());
typedef mitk::ImageToItk< ItkDirectionImage3DType > CasterType;
CasterType::Pointer caster = CasterType::New();
caster->SetInput(img);
caster->Update();
ItkDirectionImage3DType::Pointer itkImg = caster->GetOutput();
referenceImageContainer->InsertElement(referenceImageContainer->Size(),itkImg);
}
catch(...) {
MITK_INFO << "could not load: " << referenceImages.at(i);
}
}
ItkUcharImgType::Pointer itkMaskImage = ItkUcharImgType::New();
ItkDirectionImage3DType::Pointer dirImg = referenceImageContainer->GetElement(0);
itkMaskImage->SetSpacing( dirImg->GetSpacing() );
itkMaskImage->SetOrigin( dirImg->GetOrigin() );
itkMaskImage->SetDirection( dirImg->GetDirection() );
itkMaskImage->SetLargestPossibleRegion( dirImg->GetLargestPossibleRegion() );
itkMaskImage->SetBufferedRegion( dirImg->GetLargestPossibleRegion() );
itkMaskImage->SetRequestedRegion( dirImg->GetLargestPossibleRegion() );
itkMaskImage->Allocate();
itkMaskImage->FillBuffer(1);
// extract directions from fiber bundle
itk::TractsToVectorImageFilter<float>::Pointer fOdfFilter = itk::TractsToVectorImageFilter<float>::New();
fOdfFilter->SetFiberBundle(inputTractogram);
fOdfFilter->SetMaskImage(itkMaskImage);
fOdfFilter->SetAngularThreshold(cos(angularThreshold*M_PI/180));
fOdfFilter->SetNormalizeVectors(true);
fOdfFilter->SetUseWorkingCopy(false);
fOdfFilter->SetNumberOfThreads(1);
fOdfFilter->Update();
ItkDirectionImageContainerType::Pointer directionImageContainer = fOdfFilter->GetDirectionImageContainer();
// Get directions and num directions image
ItkUcharImgType::Pointer numDirImage = fOdfFilter->GetNumDirectionsImage();
mitk::Image::Pointer mitkNumDirImage = mitk::Image::New();
mitkNumDirImage->InitializeByItk( numDirImage.GetPointer() );
mitkNumDirImage->SetVolume( numDirImage->GetBufferPointer() );
mitk::FiberBundleX::Pointer testDirections = fOdfFilter->GetOutputFiberBundle();
// evaluate directions with missing directions
EvaluationFilterType::Pointer evaluationFilter = EvaluationFilterType::New();
evaluationFilter->SetImageSet(directionImageContainer);
evaluationFilter->SetReferenceImageSet(referenceImageContainer);
evaluationFilter->SetMaskImage(itkMaskImage);
evaluationFilter->SetIgnoreMissingDirections(false);
evaluationFilter->Update();
EvaluationFilterType::OutputImageType::Pointer angularErrorImage = evaluationFilter->GetOutput(0);
mitk::Image::Pointer mitkAngularErrorImage = mitk::Image::New();
mitkAngularErrorImage->InitializeByItk( angularErrorImage.GetPointer() );
mitkAngularErrorImage->SetVolume( angularErrorImage->GetBufferPointer() );
// evaluate directions without missing directions
evaluationFilter->SetIgnoreMissingDirections(true);
evaluationFilter->Update();
EvaluationFilterType::OutputImageType::Pointer angularErrorImageIgnore = evaluationFilter->GetOutput(0);
mitk::Image::Pointer mitkAngularErrorImageIgnore = mitk::Image::New();
mitkAngularErrorImageIgnore->InitializeByItk( angularErrorImageIgnore.GetPointer() );
mitkAngularErrorImageIgnore->SetVolume( angularErrorImageIgnore->GetBufferPointer() );
mitk::Image::Pointer gtAngularErrorImageIgnore = dynamic_cast<mitk::Image*>(mitk::IOUtil::LoadDataNode(LDFP_ERROR_IMAGE_IGNORE)->GetData());
mitk::Image::Pointer gtAngularErrorImage = dynamic_cast<mitk::Image*>(mitk::IOUtil::LoadDataNode(LDFP_ERROR_IMAGE)->GetData());
mitk::Image::Pointer gtNumTestDirImage = dynamic_cast<mitk::Image*>(mitk::IOUtil::LoadDataNode(LDFP_NUM_DIRECTIONS)->GetData());
mitk::FiberBundleX::Pointer gtTestDirections = dynamic_cast<mitk::FiberBundleX*>(mitk::IOUtil::LoadDataNode(LDFP_VECTOR_FIELD)->GetData());
//.........这里部分代码省略.........
示例8: LocalDirectionalFiberPlausibility
int LocalDirectionalFiberPlausibility(int argc, char* argv[])
{
ctkCommandLineParser parser;
parser.setArgumentPrefix("--", "-");
parser.addArgument("input", "i", ctkCommandLineParser::String, "input tractogram (.fib, vtk ascii file format)", us::Any(), false);
parser.addArgument("reference", "r", ctkCommandLineParser::StringList, "reference direction images", us::Any(), false);
parser.addArgument("out", "o", ctkCommandLineParser::String, "output root", us::Any(), false);
parser.addArgument("mask", "m", ctkCommandLineParser::StringList, "mask images");
parser.addArgument("athresh", "a", ctkCommandLineParser::Float, "angular threshold in degrees. closer fiber directions are regarded as one direction and clustered together.", 25, true);
parser.addArgument("verbose", "v", ctkCommandLineParser::Bool, "output optional and intermediate calculation results");
parser.addArgument("ignore", "n", ctkCommandLineParser::Bool, "don't increase error for missing or too many directions");
map<string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
if (parsedArgs.size()==0)
return EXIT_FAILURE;
ctkCommandLineParser::StringContainerType referenceImages = us::any_cast<ctkCommandLineParser::StringContainerType>(parsedArgs["reference"]);
ctkCommandLineParser::StringContainerType maskImages;
if (parsedArgs.count("mask"))
maskImages = us::any_cast<ctkCommandLineParser::StringContainerType>(parsedArgs["mask"]);
string fibFile = us::any_cast<string>(parsedArgs["input"]);
float angularThreshold = 25;
if (parsedArgs.count("athresh"))
angularThreshold = us::any_cast<float>(parsedArgs["athresh"]);
string outRoot = us::any_cast<string>(parsedArgs["out"]);
bool verbose = false;
if (parsedArgs.count("verbose"))
verbose = us::any_cast<bool>(parsedArgs["verbose"]);
bool ignore = false;
if (parsedArgs.count("ignore"))
ignore = us::any_cast<bool>(parsedArgs["ignore"]);
try
{
RegisterDiffusionCoreObjectFactory();
RegisterFiberTrackingObjectFactory();
typedef itk::Image<unsigned char, 3> ItkUcharImgType;
typedef itk::Image< itk::Vector< float, 3>, 3 > ItkDirectionImage3DType;
typedef itk::VectorContainer< int, ItkDirectionImage3DType::Pointer > ItkDirectionImageContainerType;
typedef itk::EvaluateDirectionImagesFilter< float > EvaluationFilterType;
// load fiber bundle
mitk::FiberBundleX::Pointer inputTractogram = dynamic_cast<mitk::FiberBundleX*>(mitk::IOUtil::LoadDataNode(fibFile)->GetData());
// load reference directions
ItkDirectionImageContainerType::Pointer referenceImageContainer = ItkDirectionImageContainerType::New();
for (int i=0; i<referenceImages.size(); i++)
{
try
{
mitk::Image::Pointer img = dynamic_cast<mitk::Image*>(mitk::IOUtil::LoadDataNode(referenceImages.at(i))->GetData());
typedef mitk::ImageToItk< ItkDirectionImage3DType > CasterType;
CasterType::Pointer caster = CasterType::New();
caster->SetInput(img);
caster->Update();
ItkDirectionImage3DType::Pointer itkImg = caster->GetOutput();
referenceImageContainer->InsertElement(referenceImageContainer->Size(),itkImg);
}
catch(...){ MITK_INFO << "could not load: " << referenceImages.at(i); }
}
ItkUcharImgType::Pointer itkMaskImage = ItkUcharImgType::New();
ItkDirectionImage3DType::Pointer dirImg = referenceImageContainer->GetElement(0);
itkMaskImage->SetSpacing( dirImg->GetSpacing() );
itkMaskImage->SetOrigin( dirImg->GetOrigin() );
itkMaskImage->SetDirection( dirImg->GetDirection() );
itkMaskImage->SetLargestPossibleRegion( dirImg->GetLargestPossibleRegion() );
itkMaskImage->SetBufferedRegion( dirImg->GetLargestPossibleRegion() );
itkMaskImage->SetRequestedRegion( dirImg->GetLargestPossibleRegion() );
itkMaskImage->Allocate();
itkMaskImage->FillBuffer(1);
// extract directions from fiber bundle
itk::TractsToVectorImageFilter<float>::Pointer fOdfFilter = itk::TractsToVectorImageFilter<float>::New();
fOdfFilter->SetFiberBundle(inputTractogram);
fOdfFilter->SetMaskImage(itkMaskImage);
fOdfFilter->SetAngularThreshold(cos(angularThreshold*M_PI/180));
fOdfFilter->SetNormalizeVectors(true);
fOdfFilter->SetUseWorkingCopy(false);
fOdfFilter->Update();
ItkDirectionImageContainerType::Pointer directionImageContainer = fOdfFilter->GetDirectionImageContainer();
if (verbose)
{
// write vector field
mitk::FiberBundleX::Pointer directions = fOdfFilter->GetOutputFiberBundle();
mitk::CoreObjectFactory::FileWriterList fileWriters = mitk::CoreObjectFactory::GetInstance()->GetFileWriters();
for (mitk::CoreObjectFactory::FileWriterList::iterator it = fileWriters.begin() ; it != fileWriters.end() ; ++it)
{
if ( (*it)->CanWriteBaseDataType(directions.GetPointer()) ) {
string outfilename = outRoot;
outfilename.append("_VECTOR_FIELD.fib");
(*it)->SetFileName( outfilename.c_str() );
(*it)->DoWrite( directions.GetPointer() );
//.........这里部分代码省略.........
示例9: StartPeakExtraction
//.........这里部分代码省略.........
std::cout << "Using FSL SH-basis";
}
else if ( boost::algorithm::equals(convention, "MRtrix") )
{
toolkitConvention = 2;
std::cout << "Using MRtrix SH-basis";
}
else
std::cout << "Using MITK SH-basis";
}
else
std::cout << "Using MITK SH-basis";
ItkUcharImgType::Pointer itkMaskImage = nullptr;
if (mask.IsNotNull())
{
try{
itkMaskImage = ItkUcharImgType::New();
mitk::CastToItkImage(mask, itkMaskImage);
filter->SetMaskImage(itkMaskImage);
}
catch(...)
{
}
}
if (toolkitConvention>0)
{
std::cout << "Converting coefficient image to MITK format";
typedef itk::ShCoefficientImageImporter< float, shOrder > ConverterType;
typedef mitk::ImageToItk< itk::Image< float, 4 > > CasterType;
CasterType::Pointer caster = CasterType::New();
caster->SetInput(image);
caster->Update();
itk::Image< float, 4 >::Pointer itkImage = caster->GetOutput();
typename ConverterType::Pointer converter = ConverterType::New();
if (noFlip)
{
converter->SetInputImage(itkImage);
}
else
{
std::cout << "Flipping image";
itk::FixedArray<bool, 4> flipAxes;
flipAxes[0] = true;
flipAxes[1] = true;
flipAxes[2] = false;
flipAxes[3] = false;
itk::FlipImageFilter< itk::Image< float, 4 > >::Pointer flipper = itk::FlipImageFilter< itk::Image< float, 4 > >::New();
flipper->SetInput(itkImage);
flipper->SetFlipAxes(flipAxes);
flipper->Update();
itk::Image< float, 4 >::Pointer flipped = flipper->GetOutput();
itk::Matrix< double,4,4 > m = itkImage->GetDirection(); m[0][0] *= -1; m[1][1] *= -1;
flipped->SetDirection(m);
itk::Point< float, 4 > o = itkImage->GetOrigin();
o[0] -= (flipped->GetLargestPossibleRegion().GetSize(0)-1);
o[1] -= (flipped->GetLargestPossibleRegion().GetSize(1)-1);
flipped->SetOrigin(o);
converter->SetInputImage(flipped);
}
示例10: main
/*!
\brief Copies transformation matrix of one image to another
*/
int main(int argc, char* argv[])
{
mitkCommandLineParser parser;
parser.setTitle("Flip Peaks");
parser.setCategory("Preprocessing Tools");
parser.setDescription("Flips the peaks of the input peak image along the given dimensions.");
parser.setContributor("MIC");
parser.setArgumentPrefix("--", "-");
parser.addArgument("", "i", mitkCommandLineParser::String, "Input", "input image", us::Any(), false, false, false, mitkCommandLineParser::Input);
parser.addArgument("", "o", mitkCommandLineParser::String, "Output", "output image", us::Any(), false, false, false, mitkCommandLineParser::Output);
parser.addArgument("", "x", mitkCommandLineParser::Bool, "Flip x", "flip along x-axis");
parser.addArgument("", "y", mitkCommandLineParser::Bool, "Flip y", "flip along y-axis");
parser.addArgument("", "z", mitkCommandLineParser::Bool, "Flip z", "flip along z-axis");
std::map<std::string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
if (parsedArgs.size()==0)
return EXIT_FAILURE;
std::string imageName = us::any_cast<std::string>(parsedArgs["i"]);
std::string outImage = us::any_cast<std::string>(parsedArgs["o"]);
bool x = false;
if (parsedArgs.count("x"))
x = us::any_cast<bool>(parsedArgs["x"]);
bool y = false;
if (parsedArgs.count("y"))
y = us::any_cast<bool>(parsedArgs["y"]);
bool z = false;
if (parsedArgs.count("z"))
z = us::any_cast<bool>(parsedArgs["z"]);
try
{
mitk::PreferenceListReaderOptionsFunctor functor = mitk::PreferenceListReaderOptionsFunctor({"Peak Image"}, {});
mitk::PeakImage::Pointer image = mitk::IOUtil::Load<mitk::PeakImage>(imageName, &functor);
typedef mitk::ImageToItk< mitk::PeakImage::ItkPeakImageType > CasterType;
CasterType::Pointer caster = CasterType::New();
caster->SetInput(image);
caster->Update();
mitk::PeakImage::ItkPeakImageType::Pointer itkImg = caster->GetOutput();
itk::FlipPeaksFilter< float >::Pointer flipper = itk::FlipPeaksFilter< float >::New();
flipper->SetInput(itkImg);
flipper->SetFlipX(x);
flipper->SetFlipY(y);
flipper->SetFlipZ(z);
flipper->Update();
mitk::Image::Pointer resultImage = dynamic_cast<mitk::Image*>(mitk::PeakImage::New().GetPointer());
mitk::CastToMitkImage(flipper->GetOutput(), resultImage);
resultImage->SetVolume(flipper->GetOutput()->GetBufferPointer());
mitk::IOUtil::Save(resultImage, outImage);
}
catch (itk::ExceptionObject e)
{
std::cout << e;
return EXIT_FAILURE;
}
catch (std::exception e)
{
std::cout << e.what();
return EXIT_FAILURE;
}
catch (...)
{
std::cout << "ERROR!?!";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
示例11: TractogramAngularError
int TractogramAngularError(int argc, char* argv[])
{
ctkCommandLineParser parser;
parser.setArgumentPrefix("--", "-");
parser.addArgument("input", "i", ctkCommandLineParser::String, "input tractogram (.fib, vtk ascii file format)", us::Any(), false);
parser.addArgument("reference", "r", ctkCommandLineParser::StringList, "reference direction images", us::Any(), false);
parser.addArgument("out", "o", ctkCommandLineParser::String, "output root", us::Any(), false);
parser.addArgument("mask", "m", ctkCommandLineParser::String, "mask image");
parser.addArgument("verbose", "v", ctkCommandLineParser::Bool, "output optional and intermediate calculation results");
parser.addArgument("ignore", "n", ctkCommandLineParser::Bool, "don't increase error for missing or too many directions");
parser.addArgument("trilinear", "t", ctkCommandLineParser::Bool, "use trilinear instead of nearest neighbor interpolation");
map<string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
if (parsedArgs.size()==0)
return EXIT_FAILURE;
ctkCommandLineParser::StringContainerType referenceImages = us::any_cast<ctkCommandLineParser::StringContainerType>(parsedArgs["reference"]);
string fibFile = us::any_cast<string>(parsedArgs["input"]);
string maskImage("");
if (parsedArgs.count("mask"))
maskImage = us::any_cast<string>(parsedArgs["mask"]);
string outRoot = us::any_cast<string>(parsedArgs["out"]);
bool verbose = false;
if (parsedArgs.count("verbose"))
verbose = us::any_cast<bool>(parsedArgs["verbose"]);
bool ignore = false;
if (parsedArgs.count("ignore"))
ignore = us::any_cast<bool>(parsedArgs["ignore"]);
bool interpolate = false;
if (parsedArgs.count("interpolate"))
interpolate = us::any_cast<bool>(parsedArgs["interpolate"]);
try
{
RegisterDiffusionCoreObjectFactory();
RegisterFiberTrackingObjectFactory();
typedef itk::Image<unsigned char, 3> ItkUcharImgType;
typedef itk::Image< itk::Vector< float, 3>, 3 > ItkDirectionImage3DType;
typedef itk::VectorContainer< int, ItkDirectionImage3DType::Pointer > ItkDirectionImageContainerType;
typedef itk::EvaluateTractogramDirectionsFilter< float > EvaluationFilterType;
// load fiber bundle
mitk::FiberBundleX::Pointer inputTractogram = dynamic_cast<mitk::FiberBundleX*>(mitk::IOUtil::LoadDataNode(fibFile)->GetData());
if (!inputTractogram)
return EXIT_FAILURE;
// load reference directions
ItkDirectionImageContainerType::Pointer referenceImageContainer = ItkDirectionImageContainerType::New();
for (int i=0; i<referenceImages.size(); i++)
{
try
{
mitk::Image::Pointer img = dynamic_cast<mitk::Image*>(mitk::IOUtil::LoadDataNode(referenceImages.at(i))->GetData());
typedef mitk::ImageToItk< ItkDirectionImage3DType > CasterType;
CasterType::Pointer caster = CasterType::New();
caster->SetInput(img);
caster->Update();
ItkDirectionImage3DType::Pointer itkImg = caster->GetOutput();
referenceImageContainer->InsertElement(referenceImageContainer->Size(),itkImg);
}
catch(...) {
MITK_INFO << "could not load: " << referenceImages.at(i);
}
}
// load/create mask image
ItkUcharImgType::Pointer itkMaskImage = ItkUcharImgType::New();
if (maskImage.compare("")==0)
{
ItkDirectionImage3DType::Pointer dirImg = referenceImageContainer->GetElement(0);
itkMaskImage->SetSpacing( dirImg->GetSpacing() );
itkMaskImage->SetOrigin( dirImg->GetOrigin() );
itkMaskImage->SetDirection( dirImg->GetDirection() );
itkMaskImage->SetLargestPossibleRegion( dirImg->GetLargestPossibleRegion() );
itkMaskImage->SetBufferedRegion( dirImg->GetLargestPossibleRegion() );
itkMaskImage->SetRequestedRegion( dirImg->GetLargestPossibleRegion() );
itkMaskImage->Allocate();
itkMaskImage->FillBuffer(1);
}
else
{
mitk::Image::Pointer mitkMaskImage = dynamic_cast<mitk::Image*>(mitk::IOUtil::LoadDataNode(maskImage)->GetData());
mitk::CastToItkImage<ItkUcharImgType>(mitkMaskImage, itkMaskImage);
}
// evaluate directions
EvaluationFilterType::Pointer evaluationFilter = EvaluationFilterType::New();
evaluationFilter->SetTractogram(inputTractogram);
evaluationFilter->SetReferenceImageSet(referenceImageContainer);
evaluationFilter->SetMaskImage(itkMaskImage);
evaluationFilter->SetIgnoreMissingDirections(ignore);
evaluationFilter->SetUseInterpolation(interpolate);
evaluationFilter->Update();
//.........这里部分代码省略.........
示例12: main
//.........这里部分代码省略.........
for (auto item : fib_files)
{
if ( ist::FileIsDirectory(item) )
{
for ( auto fibFile : get_file_list(item) )
{
mitk::FiberBundle::Pointer inputTractogram = mitk::IOUtil::Load<mitk::FiberBundle>(fibFile);
if (inputTractogram.IsNull())
continue;
input_tracts.push_back(inputTractogram);
fib_names.push_back(fibFile);
}
}
else
{
mitk::FiberBundle::Pointer inputTractogram = mitk::IOUtil::Load<mitk::FiberBundle>(item);
if (inputTractogram.IsNull())
continue;
input_tracts.push_back(inputTractogram);
fib_names.push_back(item);
}
}
std::cout.rdbuf (old); // <-- restore
itk::FitFibersToImageFilter::Pointer fitter = itk::FitFibersToImageFilter::New();
mitk::BaseData::Pointer inputData = mitk::IOUtil::Load(input_image_name, &functor)[0].GetPointer();
mitk::Image::Pointer mitk_image = dynamic_cast<mitk::Image*>(inputData.GetPointer());
mitk::PeakImage::Pointer mitk_peak_image = dynamic_cast<mitk::PeakImage*>(inputData.GetPointer());
if (mitk_peak_image.IsNotNull())
{
typedef mitk::ImageToItk< mitk::PeakImage::ItkPeakImageType > CasterType;
CasterType::Pointer caster = CasterType::New();
caster->SetInput(mitk_peak_image);
caster->Update();
mitk::PeakImage::ItkPeakImageType::Pointer peak_image = caster->GetOutput();
fitter->SetPeakImage(peak_image);
}
else if (mitk::DiffusionPropertyHelper::IsDiffusionWeightedImage(mitk_image))
{
fitter->SetDiffImage(mitk::DiffusionPropertyHelper::GetItkVectorImage(mitk_image));
mitk::TensorModel<>* model = new mitk::TensorModel<>();
model->SetBvalue(1000);
model->SetDiffusivity1(0.0010);
model->SetDiffusivity2(0.00015);
model->SetDiffusivity3(0.00015);
model->SetGradientList(mitk::DiffusionPropertyHelper::GetGradientContainer(mitk_image));
fitter->SetSignalModel(model);
}
else if (mitk_image->GetDimension()==3)
{
itk::FitFibersToImageFilter::DoubleImgType::Pointer scalar_image = itk::FitFibersToImageFilter::DoubleImgType::New();
mitk::CastToItkImage(mitk_image, scalar_image);
fitter->SetScalarImage(scalar_image);
}
else
{
MITK_INFO << "Input image invalid. Valid options are peak image, 3D scalar image or raw diffusion-weighted image.";
return EXIT_FAILURE;
}
fitter->SetTractograms(input_tracts);
fitter->SetFitIndividualFibers(single_fib);
fitter->SetMaxIterations(max_iter);
fitter->SetGradientTolerance(g_tol);
fitter->SetLambda(lambda);