コード例 #1
0
// Helper function to multiplex the actual Paint function call for different
// pixel types. As it's cumbersome and ugly, you may want to avoid such
// functions by using ITK for the actual painting and use the ITK access
// macros like we did for the AwesomeImageFilter.
static void Paint(mitk::Image::Pointer image, itk::Index<3> index, unsigned int timeStep)
{
  switch (image->GetPixelType().GetComponentType())
  {
  case itk::ImageIOBase::CHAR:
    Paint<char>(image, index, timeStep);
    break;

  case itk::ImageIOBase::UCHAR:
    Paint<unsigned char>(image, index, timeStep);
    break;

  case itk::ImageIOBase::SHORT:
    Paint<short>(image, index, timeStep);
    break;

  case itk::ImageIOBase::USHORT:
    Paint<unsigned short>(image, index, timeStep);
    break;

  case itk::ImageIOBase::INT:
    Paint<int>(image, index, timeStep);
    break;

  case itk::ImageIOBase::UINT:
    Paint<unsigned int>(image, index, timeStep);
    break;

  default:
    mitkThrow();
  }
}
コード例 #2
0
        Attributes::Attributes(mitk::Image::Pointer mitkImage)
        {
            log_trace(Log::New, this);

            Pixel::ID pixelID;
            Component::ID componentID;
            unsigned int dimension;

            log_info("pixelType: " << mitkImage->GetPixelType().GetPixelTypeAsString());
            log_info("channels : " << mitkImage->GetPixelType().GetNumberOfComponents());
            log_info("component: " << mitkImage->GetPixelType().GetComponentTypeAsString());
            log_info("dimension: " << mitkImage->GetDimension());

            switch (mitkImage->GetPixelType().GetPixelType())
            {
                case itk::ImageIOBase::SCALAR:  pixelID = Pixel::ID::Scalar; break;
                case itk::ImageIOBase::RGB:     pixelID = Pixel::ID::Rgb; break;
                case itk::ImageIOBase::RGBA:    pixelID = Pixel::ID::Rgba; break;

                default: pixelID = Pixel::ID::Scalar; break;
            }

            switch ((itk::ImageIOBase::IOComponentType) mitkImage->GetPixelType().GetComponentType())
            {
                case itk::ImageIOBase::UCHAR:   componentID = Component::ID::UChar; break;
                case itk::ImageIOBase::USHORT:  componentID = Component::ID::UShort; break;
                case itk::ImageIOBase::UINT:    componentID = Component::ID::UInt; break;
                case itk::ImageIOBase::CHAR:    componentID = Component::ID::Char; break;
                case itk::ImageIOBase::SHORT:   componentID = Component::ID::Short; break;
                case itk::ImageIOBase::INT: 	componentID = Component::ID::Int; break;
                case itk::ImageIOBase::FLOAT:   componentID = Component::ID::Float; break;
                case itk::ImageIOBase::DOUBLE: 	componentID = Component::ID::Double; break;

                default: componentID = Component::ID::Double; break;
            }

            if (mitkImage->GetPixelType().GetNumberOfComponents() == 1)
            {
                pixelID = Pixel::ID::Scalar;
            }

            if (mitkImage->GetPixelType().GetNumberOfComponents() == 3)
            {
                pixelID = Pixel::ID::Rgb;
            }

            if (mitkImage->GetPixelType().GetNumberOfComponents() == 4)
            {
                pixelID = Pixel::ID::Rgba;
            }

            dimension = mitkImage->GetDimension();

            this->m_dimension = dimension;
            this->m_pixelID = pixelID;
            this->m_componentID = componentID;
        }
コード例 #3
0
ファイル: mitkImageWriterTest.cpp プロジェクト: beneon/MITK
bool CompareImageMetaData( mitk::Image::Pointer image, mitk::Image::Pointer reference)
{
  // switch to AreIdentical() methods as soon as Bug 11925 (Basic comparison operators) is fixed

  if( image->GetDimension() != reference->GetDimension() )
  {
    MITK_ERROR << "The image dimension differs: IN (" << image->GetDimension() << ") REF(" << reference->GetDimension() << ")";
    return false;
  }

  // pixel type
  if( image->GetPixelType() != reference->GetPixelType()
      && image->GetPixelType().GetBitsPerComponent() != reference->GetPixelType().GetBitsPerComponent() )
  {
    MITK_ERROR << "Pixeltype differs ";
    return false;
  }

  return true;
}
コード例 #4
0
void mitk::pa::SpectralUnmixingSO2::CheckPreConditions(mitk::Image::Pointer inputHbO2, mitk::Image::Pointer inputHb)
{
  unsigned int xDimHb = inputHb->GetDimensions()[0];
  unsigned int yDimHb = inputHb->GetDimensions()[1];
  unsigned int zDimHb = inputHb->GetDimensions()[2];

  unsigned int xDimHbO2 = inputHbO2->GetDimensions()[0];
  unsigned int yDimHbO2 = inputHbO2->GetDimensions()[1];
  unsigned int zDimHbO2 = inputHbO2->GetDimensions()[2];

  if (xDimHb != xDimHbO2 || yDimHb != yDimHbO2 || zDimHb != zDimHbO2)
    mitkThrow() << "DIMENTIONALITY ERROR!";

  if (inputHbO2->GetPixelType() != mitk::MakeScalarPixelType<float>())
    mitkThrow() << "PIXELTYPE ERROR! FLOAT REQUIRED";

  if (inputHb->GetPixelType() != mitk::MakeScalarPixelType<float>())
    mitkThrow() << "PIXELTYPE ERROR! FLOAT REQUIRED";

  MITK_INFO(m_Verbose) << "CHECK PRECONDITIONS ...[DONE]";
}
コード例 #5
0
void mitk::RegistrationWrapper::ApplyTransformationToImage(mitk::Image::Pointer img, const mitk::RegistrationWrapper::RidgidTransformType &transformation,double* offset, mitk::Image* resampleReference,  bool binary)
{
  typedef mitk::DiffusionImage<short> DiffusionImageType;

  if (dynamic_cast<DiffusionImageType*> (img.GetPointer()) == NULL)
  {

    ItkImageType::Pointer itkImage = ItkImageType::New();


    MITK_ERROR << "imgCopy  0 " <<  "/" << img->GetReferenceCount();
    MITK_ERROR << "pixel type  " << img->GetPixelType().GetComponentTypeAsString();

    CastToItkImage(img, itkImage);



    typedef itk::Euler3DTransform< double > RigidTransformType;
    RigidTransformType::Pointer rtransform = RigidTransformType::New();
    RigidTransformType::ParametersType parameters(RigidTransformType::ParametersDimension);

    for (int i = 0; i<6;++i)
      parameters[i] = transformation[i];

    rtransform->SetParameters( parameters );

    mitk::Point3D origin = itkImage->GetOrigin();
    origin[0]-=offset[0];
    origin[1]-=offset[1];
    origin[2]-=offset[2];

    mitk::Point3D newOrigin = rtransform->GetInverseTransform()->TransformPoint(origin);

    itk::Matrix<double,3,3> dir = itkImage->GetDirection();
    itk::Matrix<double,3,3> transM  ( vnl_inverse(rtransform->GetMatrix().GetVnlMatrix()));
    itk::Matrix<double,3,3> newDirection = transM * dir;

    itkImage->SetOrigin(newOrigin);
    itkImage->SetDirection(newDirection);

    // Perform Resampling if reference image is provided
    if (resampleReference != NULL)
    {
      typedef itk::ResampleImageFilter<ItkImageType, ItkImageType>  ResampleFilterType;

      ItkImageType::Pointer itkReference = ItkImageType::New();
      CastToItkImage(resampleReference,itkReference);

      typedef itk::WindowedSincInterpolateImageFunction< ItkImageType, 3> WindowedSincInterpolatorType;
      WindowedSincInterpolatorType::Pointer sinc_interpolator = WindowedSincInterpolatorType::New();

      typedef itk::NearestNeighborInterpolateImageFunction< ItkImageType, double > NearestNeighborInterpolatorType;
      NearestNeighborInterpolatorType::Pointer nn_interpolator = NearestNeighborInterpolatorType::New();


      ResampleFilterType::Pointer resampler = ResampleFilterType::New();
      resampler->SetInput(itkImage);
      resampler->SetReferenceImage( itkReference );
      resampler->UseReferenceImageOn();
      if (binary)
        resampler->SetInterpolator(nn_interpolator);
      else
        resampler->SetInterpolator(sinc_interpolator);

      resampler->Update();

      GrabItkImageMemory(resampler->GetOutput(), img);
    }
    else
    {
      // !! CastToItk behaves very differently depending on the original data type
      // if the target type is the same as the original, only a pointer to the data is set
      // and an additional GrabItkImageMemory will cause a segfault when the image is destroyed
      // GrabItkImageMemory - is not necessary in this case since we worked on the original data
      // See Bug 17538.
      if (img->GetPixelType().GetComponentTypeAsString() != "double")
        img = GrabItkImageMemory(itkImage);
    }
  }
  else
  {
    DiffusionImageType::Pointer diffImages = dynamic_cast<DiffusionImageType*>(img.GetPointer());

    typedef itk::Euler3DTransform< double > RigidTransformType;
    RigidTransformType::Pointer rtransform = RigidTransformType::New();
    RigidTransformType::ParametersType parameters(RigidTransformType::ParametersDimension);

    for (int i = 0; i<6;++i)
    {
      parameters[i] = transformation[i];
    }

    rtransform->SetParameters( parameters );

    mitk::Point3D b0origin = diffImages->GetVectorImage()->GetOrigin();
    b0origin[0]-=offset[0];
    b0origin[1]-=offset[1];
    b0origin[2]-=offset[2];

    mitk::Point3D newOrigin = rtransform->GetInverseTransform()->TransformPoint(b0origin);

    itk::Matrix<double,3,3> dir = diffImages->GetVectorImage()->GetDirection();
    itk::Matrix<double,3,3> transM  ( vnl_inverse(rtransform->GetMatrix().GetVnlMatrix()));
    itk::Matrix<double,3,3> newDirection = transM * dir;

    diffImages->GetVectorImage()->SetOrigin(newOrigin);
    diffImages->GetVectorImage()->SetDirection(newDirection);
    diffImages->Modified();

    mitk::DiffusionImageCorrectionFilter<short>::Pointer correctionFilter = mitk::DiffusionImageCorrectionFilter<short>::New();

    // For Diff. Images: Need to rotate the gradients (works in-place)
    correctionFilter->SetImage(diffImages);
    correctionFilter->CorrectDirections(transM.GetVnlMatrix());
    img = diffImages;
  }
}