コード例 #1
0
ファイル: sqb_trees.cpp プロジェクト: Vaa3D/vaa3d_tools
typename ImageType::Pointer swcFile2itkImage(const SwcFileContent swcFileContent, typename ImageType::Pointer &inputImage){
  // Allocate empty image
//  itk::Index<3> start; start.Fill(0);
//  itk::Size<3> size; size.Fill(100);
//  typename ImageType::RegionType region(inputImage->GetOrigin(), inputImage->GetLargestPossibleRegion().GetSize());

//  std::cout << "HereA!\n" << std::flush;

//  typename ImageType::RegionType region(inputImage->GetLargestPossibleRegion());

  std::cout << "I am HereB!\n" << std::flush;

  typedef itk::ImageDuplicator< ImageType > DuplicatorType;
  typename DuplicatorType::Pointer duplicator = DuplicatorType::New();
  duplicator->SetInputImage(inputImage);
  duplicator->Update();

  std::cout << "I am HereC!\n" << std::flush;

  typename ImageType::Pointer groundTruthImage = duplicator->GetOutput();

//  groundTruthImage->SetRegions(region);

//  std::cout << "And I am HereC!\n" << std::flush;

//  groundTruthImage->Allocate();

//  std::cout << "And I am HereD!\n" << std::flush;

//  groundTruthImage->FillBuffer(0);

  std::cout << "I am HereD!\n" << std::flush;

  return groundTruthImage;
}
コード例 #2
0
void VectorOfMitkImagesToMitkVectorImage(const itk::Image<TPixel, VImageDimension>* /*source*/, mitk::Image::Pointer &output, mitk::LabelSetImage::ConstPointer input)
{
  typedef itk::ComposeImageFilter< itk::Image<TPixel, VImageDimension> > ComposeFilterType;

  unsigned int numberOfLayers = input->GetNumberOfLayers();
  // 2015/07/01 At the time of writing MITK has problems with mitk::Images encapsulating itk::VectorImage
  // if the vector length is less than 2, which might very well happen for segmentations.
  if ( numberOfLayers > 1 )
  { // if we have only one image we do not need to create a vector
    typename ComposeFilterType::Pointer vectorImageComposer = ComposeFilterType::New();

    unsigned int activeLayer = input->GetActiveLayer();
    for (unsigned int layer(0); layer < numberOfLayers; layer++)
    {
      typename itk::Image<TPixel, VImageDimension>::Pointer itkCurrentLayer;
      // for the active layer use the current state not the saved one in the vector
      if (layer == activeLayer)
      {
        mitk::CastToItkImage(dynamic_cast<const mitk::Image*>(input.GetPointer()), itkCurrentLayer);
      }
      else
      {
        mitk::CastToItkImage(input->GetLayerImage(layer), itkCurrentLayer);
      }

      vectorImageComposer->SetInput(layer, itkCurrentLayer);
    }

    try
    {
      vectorImageComposer->Update();
    }
    catch (const itk::ExceptionObject& e)
    {
      MITK_ERROR << "Caught exception while updating compose filter: " << e.what();
    }

    output = mitk::GrabItkImageMemory(vectorImageComposer->GetOutput());
  }
  else
  {
    // we want the clone to be a mitk::Image, not a mitk::LabelSetImage
    typename itk::Image<TPixel, VImageDimension>::Pointer itkCurrentLayer;
    mitk::CastToItkImage(dynamic_cast<const mitk::Image*>(input.GetPointer()), itkCurrentLayer);
    typedef itk::ImageDuplicator< itk::Image<TPixel, VImageDimension> > DuplicatorType;
    typename DuplicatorType::Pointer duplicator = DuplicatorType::New();
    duplicator->SetInputImage(itkCurrentLayer);
    duplicator->Update();

    output = mitk::GrabItkImageMemory(duplicator->GetOutput());
  }
}
コード例 #3
0
ファイル: CLGlobalImageFeatures.cpp プロジェクト: Cdebus/MITK
static void
CreateNoNaNMask(itk::Image<TPixel, VImageDimension>* itkValue, mitk::Image::Pointer mask, mitk::Image::Pointer& newMask)
{
  typedef itk::Image< TPixel, VImageDimension>                 LFloatImageType;
  typedef itk::Image< unsigned short, VImageDimension>          LMaskImageType;
  typename LMaskImageType::Pointer itkMask = LMaskImageType::New();

  mitk::CastToItkImage(mask, itkMask);

  typedef itk::ImageDuplicator< LMaskImageType > DuplicatorType;
  typename DuplicatorType::Pointer duplicator = DuplicatorType::New();
  duplicator->SetInputImage(itkMask);
  duplicator->Update();

  auto tmpMask = duplicator->GetOutput();

  itk::ImageRegionIterator<LMaskImageType> mask1Iter(itkMask, itkMask->GetLargestPossibleRegion());
  itk::ImageRegionIterator<LMaskImageType> mask2Iter(tmpMask, tmpMask->GetLargestPossibleRegion());
  itk::ImageRegionIterator<LFloatImageType> imageIter(itkValue, itkValue->GetLargestPossibleRegion());
  while (!mask1Iter.IsAtEnd())
  {
    mask2Iter.Set(0);
    if (mask1Iter.Value() > 0)
    {
      // Is not NaN
      if (imageIter.Value() == imageIter.Value())
      {
        mask2Iter.Set(1);
      }
    }
    ++mask1Iter;
    ++mask2Iter;
    ++imageIter;
  }

  newMask->InitializeByItk(tmpMask);
  mitk::GrabItkImageMemory(tmpMask, newMask);
}