void GetImageStatisticsWithImageAndMaskNotConnected()
  {
    //create rules connection + add statistics to dataStorage
    auto statisticsNode = mitk::CreateImageStatisticsNode(m_statisticsContainer, "testStatistics");
    CreateNodeRelationImage(m_statisticsContainer.GetPointer(), m_image.GetPointer());
    CreateNodeRelationMask(m_statisticsContainer.GetPointer(), m_mask.GetPointer());
    auto standaloneDataStorage = mitk::StandaloneDataStorage::New();
    standaloneDataStorage->Add(statisticsNode);

    //rule: (image-->statistics, mask-->statistics), 1 connected image --> test return nullptr
    mitk::ImageStatisticsContainer::ConstPointer statisticsWithImage;
    CPPUNIT_ASSERT_NO_THROW(statisticsWithImage = mitk::ImageStatisticsContainerManager::GetImageStatistics(standaloneDataStorage.GetPointer(), m_image.GetPointer()));
    CPPUNIT_ASSERT_EQUAL(statisticsWithImage.IsNull(), true);

    //rule: (image-->statistics, mask-->statistics), 1 unconnected image, 1 unconnected mask --> test return nullptr
    mitk::ImageStatisticsContainer::ConstPointer statisticsWithImageNotConnectedAndMaskNotConnected;
    CPPUNIT_ASSERT_NO_THROW(statisticsWithImageNotConnectedAndMaskNotConnected = mitk::ImageStatisticsContainerManager::GetImageStatistics(standaloneDataStorage.GetPointer(), m_image2.GetPointer(), m_mask2.GetPointer()));
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageNotConnectedAndMaskNotConnected.IsNull(), true);

    //rule: (image-->statistics, mask-->statistics), 1 unconnected image, 1 connected mask --> test return nullptr
    mitk::ImageStatisticsContainer::ConstPointer statisticsWithImageAndMaskNotConnected;
    CPPUNIT_ASSERT_NO_THROW(statisticsWithImageAndMaskNotConnected = mitk::ImageStatisticsContainerManager::GetImageStatistics(standaloneDataStorage.GetPointer(), m_image2.GetPointer(), m_mask.GetPointer()));
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageAndMaskNotConnected.IsNull(), true);

    //rule: (image-->statistics, mask-->statistics), 1 connected image, 1 unconnected planarFigure --> test return nullptr
    mitk::ImageStatisticsContainer::ConstPointer statisticsWithImageAndPlanarFigureNotConnected;
    CPPUNIT_ASSERT_NO_THROW(statisticsWithImageAndPlanarFigureNotConnected = mitk::ImageStatisticsContainerManager::GetImageStatistics(standaloneDataStorage.GetPointer(), m_image.GetPointer(), m_planarFigure.GetPointer()));
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageAndPlanarFigureNotConnected.IsNull(), true);

    //rule: (image-->statistics, mask-->statistics), 1 unconnected image, 1 unconnected planarFigure --> test return nullptr
    mitk::ImageStatisticsContainer::ConstPointer statisticsWithImageNotConnectedAndPlanarFigureNotConnected;
    CPPUNIT_ASSERT_NO_THROW(statisticsWithImageAndPlanarFigureNotConnected = mitk::ImageStatisticsContainerManager::GetImageStatistics(standaloneDataStorage.GetPointer(), m_image2.GetPointer(), m_planarFigure.GetPointer()));
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageAndPlanarFigureNotConnected.IsNull(), true);
  }
Beispiel #2
0
static bool CompareImages(mitk::Image::Pointer mitkImage, cv::Mat openCVImage)
{
    float equal = true;
    if ((mitkImage->GetDimension(0)!=openCVImage.cols)||(mitkImage->GetDimension(1)!=openCVImage.rows))
    {
        equal = false;
    }
    for (unsigned int i=0; i<openCVImage.cols; i++)
    {
        for (unsigned int j=0; j<openCVImage.rows; j++)
        {
            mitk::Index3D currentIndex;
            currentIndex[0] = i;
            currentIndex[1] = j;
            currentIndex[2] = 0;
            float mitkImageValue = mitkImage->GetPixelValueByIndex(currentIndex);
            float openCVImageValue = openCVImage.at<float>(j,i);
            if (!mitk::Equal(mitkImageValue,openCVImageValue))
            {
                equal = false;
            }
        }
    }
    return equal;
}
void mitk::SurfaceInterpolationController::SetCurrentInterpolationSession(mitk::Image::Pointer currentSegmentationImage)
{
  if (currentSegmentationImage.GetPointer() == m_SelectedSegmentation)
    return;

  if (currentSegmentationImage.IsNull())
  {
    m_SelectedSegmentation = nullptr;
    return;
  }

  m_SelectedSegmentation = currentSegmentationImage.GetPointer();

  auto it = m_ListOfInterpolationSessions.find(currentSegmentationImage.GetPointer());
  // If the session does not exist yet create a new ContourPositionPairList otherwise reinitialize the interpolation pipeline
  if (it == m_ListOfInterpolationSessions.end())
  {
    ContourPositionInformationVec2D newList;
    m_ListOfInterpolationSessions.insert(std::pair<mitk::Image*, ContourPositionInformationVec2D>(m_SelectedSegmentation, newList));
    m_InterpolationResult = nullptr;
    m_CurrentNumberOfReducedContours = 0;

    itk::MemberCommand<SurfaceInterpolationController>::Pointer command = itk::MemberCommand<SurfaceInterpolationController>::New();
    command->SetCallbackFunction(this, &SurfaceInterpolationController::OnSegmentationDeleted);
    m_SegmentationObserverTags.insert( std::pair<mitk::Image*, unsigned long>( m_SelectedSegmentation, m_SelectedSegmentation->AddObserver( itk::DeleteEvent(), command ) ) );
  }

  this->ReinitializeInterpolation();
}
void mitk::MorphologicalOperations::FillHoles(mitk::Image::Pointer &image)
{
  MITK_INFO << "Start FillHole...";

  int timeSteps = static_cast<int>(image->GetTimeSteps());

  if (timeSteps > 1)
  {
    mitk::ImageTimeSelector::Pointer timeSelector = mitk::ImageTimeSelector::New();
    timeSelector->SetInput(image);

    for (int t = 0; t < timeSteps; ++t)
    {
      MITK_INFO << "  Processing time step " << t;

      timeSelector->SetTimeNr(t);
      timeSelector->Update();

      mitk::Image::Pointer img3D = timeSelector->GetOutput();
      img3D->DisconnectPipeline();

      AccessByItk_1(img3D, itkFillHoles, img3D);

      mitk::ImageReadAccessor accessor(img3D);
      image->SetVolume(accessor.GetData(), t);
    }
  }
  else
  {
    AccessByItk_1(image, itkFillHoles, image);
  }

  MITK_INFO << "Finished FillHole";
}
static bool CompareImages(mitk::Image::Pointer mitkImage, cv::Mat openCVImage)
{
  float equal = true;
  if (static_cast<int>(mitkImage->GetDimension(0)) != openCVImage.cols || static_cast<int>(mitkImage->GetDimension(1)) != openCVImage.rows)
  {
    equal = false;
  }
  mitk::ImagePixelReadAccessor<float,2> imageAcces(mitkImage, mitkImage->GetSliceData(0));
  for(int i=0; i<openCVImage.cols; i++)
  {
    for(int j=0; j<openCVImage.rows; j++)
    {
      itk::Index<2> currentIndex;
      currentIndex[0] = i;
      currentIndex[1] = j;
      float mitkImageValue = imageAcces.GetPixelByIndex(currentIndex);
      float openCVImageValue = openCVImage.at<float>(j,i);
      if (!mitk::Equal(mitkImageValue,openCVImageValue))
      {
        equal = false;
      }
    }
  }
  return equal;
}
void mitk::USTelemedImageSource::GetNextRawImage( mitk::Image::Pointer& image)
{
  if ( image.IsNull() ) { image = mitk::Image::New(); }

  //get the actual resolution to check if it changed. We have to do this every time because the geometry takes a few frames to adapt
  Usgfw2Lib::tagImageResolution resolutionInMetersActual;
  m_ImageProperties->GetResolution(&resolutionInMetersActual, 0);
  if (m_OldnXPelsPerUnit != resolutionInMetersActual.nXPelsPerUnit || m_OldnYPelsPerUnit != resolutionInMetersActual.nYPelsPerUnit)
    {
      //we can only update if the image exists and has a geometry
      if (m_Image.IsNotNull() && m_Image->GetGeometry() != nullptr)
     {
        m_OldnXPelsPerUnit = resolutionInMetersActual.nXPelsPerUnit;
        m_OldnYPelsPerUnit = resolutionInMetersActual.nYPelsPerUnit;
        UpdateImageGeometry();
      }

    }
  //now update image
  if ( m_Image->IsInitialized() )
  {
    m_ImageMutex->Lock();

    // copy contents of the given image into the member variable
    image->Initialize(m_Image->GetPixelType(), m_Image->GetDimension(), m_Image->GetDimensions());
    mitk::ImageReadAccessor inputReadAccessor(m_Image, m_Image->GetSliceData(0,0,0));
    image->SetSlice(inputReadAccessor.GetData());
    image->SetGeometry(m_Image->GetGeometry());

    m_ImageMutex->Unlock();
  }

}
  /**
   * @brief AddColouredOverlay - Overlays the rgbImage with an coloured overlay
   *
   * For all positions in overlayImage not zero, its value is multiplied the the colour value and added
   * to the rgbImage.
   *
   * @param rgbImage - input rgbImage to which the coloured overlay is added
   * @param overlayImage
   * @param color
   */
  void AddColouredOverlay(mitk::Image::Pointer rgbImage, mitk::Image::Pointer overlayImage, mitk::Color color)
  {
    unsigned int *dim = rgbImage->GetDimensions();
    itk::Image<PixelType,3>::Pointer itkOverlayImage = itk::Image<PixelType,3>::New();
    mitk::CastToItkImage(overlayImage.GetPointer(), itkOverlayImage);
    mitk::ImagePixelWriteAccessor<RGBPixelType ,3> writeAcc(rgbImage);

    itk::Index<3> idx;
    itk::RGBPixel<PixelType> value;
    unsigned short overlayVal=0;
    // Fill rgb image with gray values
    for (idx[2] =0; (unsigned int)idx[2] < dim[2]; idx[2]++)
    {
      for (idx[1] =0; (unsigned int)idx[1] < dim[1]; idx[1]++)
      {
        for (idx[0] =0; (unsigned int)idx[0] < dim[0]; idx[0]++)
        {
          overlayVal = 255*itkOverlayImage->GetPixel(idx);
          value = writeAcc.GetPixelByIndex(idx);
          value[0] = std::min( (int)(value[0] + overlayVal * color[0]),254*255);
          value[1] =  std::min((int)(value[1] + overlayVal * color[1]),254*255) ;
          value[2] = std::min((int)(value[2] + overlayVal * color[2]),254*255);
          writeAcc.SetPixelByIndex(idx, value);
        }
      }
    }
  }
void StartSimulation(FiberfoxParameters<double> parameters, FiberBundle::Pointer fiberBundle, mitk::Image::Pointer refImage, string message)
{
    itk::TractsToDWIImageFilter< short >::Pointer tractsToDwiFilter = itk::TractsToDWIImageFilter< short >::New();
    tractsToDwiFilter->SetUseConstantRandSeed(true);
    tractsToDwiFilter->SetParameters(parameters);
    tractsToDwiFilter->SetFiberBundle(fiberBundle);
    tractsToDwiFilter->Update();

    mitk::Image::Pointer testImage = mitk::GrabItkImageMemory( tractsToDwiFilter->GetOutput() );
    testImage->SetProperty( mitk::DiffusionPropertyHelper::GRADIENTCONTAINERPROPERTYNAME.c_str(), mitk::GradientDirectionsProperty::New( parameters.m_SignalGen.GetGradientDirections() ) );
    testImage->SetProperty( mitk::DiffusionPropertyHelper::REFERENCEBVALUEPROPERTYNAME.c_str(), mitk::FloatProperty::New( parameters.m_SignalGen.m_Bvalue ) );

    mitk::DiffusionPropertyHelper propertyHelper( testImage );
    propertyHelper.InitializeImage();

    if (refImage.IsNotNull())
    {
        if( static_cast<mitk::GradientDirectionsProperty*>( refImage->GetProperty(mitk::DiffusionPropertyHelper::GRADIENTCONTAINERPROPERTYNAME.c_str()).GetPointer() )->GetGradientDirectionsContainer().IsNotNull() )
        {
            ItkDwiType::Pointer itkTestImagePointer = ItkDwiType::New();
            mitk::CastToItkImage(testImage, itkTestImagePointer);
            ItkDwiType::Pointer itkRefImagePointer = ItkDwiType::New();
            mitk::CastToItkImage(refImage, itkRefImagePointer);

            bool cond = CompareDwi(itkTestImagePointer, itkRefImagePointer);
            if (!cond)
            {
                MITK_INFO << "Saving test and rference image to " << mitk::IOUtil::GetTempPath();
                mitk::IOUtil::SaveBaseData(testImage, mitk::IOUtil::GetTempPath()+"testImage.dwi");
                mitk::IOUtil::SaveBaseData(refImage, mitk::IOUtil::GetTempPath()+"refImage.dwi");
            }
            MITK_TEST_CONDITION_REQUIRED(cond, message);
        }
    }
}
void mitk::NonStaticArithmeticOperation::CallExecuteTwoImageFilter(mitk::Image::Pointer imageA, mitk::Image::Pointer imageB)
{
  if (imageA->GetDimension() != imageB->GetDimension())
  {
    mitkThrow() << "Image have different dimensions. This is not supported by mitk::ArithmeticOperation";
  }

  switch (imageA->GetDimension())
  {
  case 1:
    AccessTwoImagesFixedDimensionByItk(imageA, imageB, mitk::NonStaticArithmeticOperation::ExecuteTwoImageFilter, 1);
    break;
  case 2:
    AccessTwoImagesFixedDimensionByItk(imageA, imageB, mitk::NonStaticArithmeticOperation::ExecuteTwoImageFilter, 2);
    break;
  case 3:
    AccessTwoImagesFixedDimensionByItk(imageA, imageB, mitk::NonStaticArithmeticOperation::ExecuteTwoImageFilter, 3);
    break;
  case 4:
    AccessTwoImagesFixedDimensionByItk(imageA, imageB, mitk::NonStaticArithmeticOperation::ExecuteTwoImageFilter, 4);
    break;
  default:
    mitkThrow() << "Image Dimension of "<<imageA->GetDimension() << " is not supported";
    break;
  }
}
static bool CompareImages(mitk::Image::Pointer image1, mitk::Image::Pointer image2)
{

  unsigned int dimX = image1->GetDimension(0);
  unsigned int dimY = image1->GetDimension(1);

  //make sure images have the same dimensions
  if((dimX != image1->GetDimension(0)) || (dimY != image1->GetDimension(1)))
    return false;

  //compare all pixel values
  for(unsigned int i = 0; i<dimX; i++)
  {
    for(unsigned int j = 0; j < dimY; j++)
    {
      mitk::Index3D idx;
      idx[0] = i; idx[1] = j; idx[2] = 0;
      if(!(mitk::Equal(image1->GetPixelValueByIndex(idx), image1->GetPixelValueByIndex(idx))))
      {
        return false;
      }

    }
  }

  //all pixels have identical values
  return true;
}
  void Init()
  {

    im1 = mitk::ImageGenerator::GenerateRandomImage<double>(2,2,2,1,2,2,2,1,0);
    im2 = mitk::ImageGenerator::GenerateRandomImage<double>(3,3,3,1,3,3,3,3,2);
    im3 = mitk::ImageGenerator::GenerateRandomImage<double>(4,4,4,1,4,4,4,5,4);
    im4 = mitk::ImageGenerator::GenerateRandomImage<double>(5,5,5,1,5,5,5,7,6);

    dataCol1 = mitk::DataCollection::New();
    dataCol2 = mitk::DataCollection::New();

    dataCol1->AddData(im1.GetPointer(),"T1");

    dataCol1->AddData(im2.GetPointer(),"T2");

    dataCol2->AddData(im3.GetPointer(),"T1");
    dataCol2->AddData(im4.GetPointer(),"T2");

    col1 = mitk::DataCollection::New();

    col1->SetName("GnaBla");
    col1->AddData(dataCol1.GetPointer(), "0001");
    col1->AddData(dataCol2.GetPointer(), "0002");

    m_Collection = mitk::DataCollection::New();

    m_Collection->SetName("DummyCollection");
    m_Collection->AddData(col1.GetPointer(), "C1");


  }
bool mitkSegmentationInterpolationTestClass::LoadTestImages()
{
  std::string filename1 = mitk::StandardFileLocations::GetInstance()->FindFile("interpolation_test_manual.pic.gz", "../mitk/Core/Testing/Data/");
  if ( filename1.empty() )
  {
    filename1 = mitk::StandardFileLocations::GetInstance()->FindFile("interpolation_test_manual.pic.gz", "Testing/Data/");
  }
  
  std::cout << "Found test image (manual slices) in '" << filename1 << "'" << std::endl;
  
  std::string filename2 = mitk::StandardFileLocations::GetInstance()->FindFile("interpolation_test_result.pic.gz", "../mitk/Core/Testing/Data/");
  if ( filename2.empty() )
  {
    filename2 = mitk::StandardFileLocations::GetInstance()->FindFile("interpolation_test_result.pic.gz", "Testing/Data/");
  }
  
  std::cout << "Found test image (reference for interpolation) in '" << filename2 << "'" << std::endl;
  
  if ( filename1.empty() || filename2.empty() )
  {
    return false;
  }
  else
  {
    m_ManualSlices = LoadImage( filename1 );
    m_InterpolatedSlices = LoadImage( filename2 );

    return ( m_ManualSlices.IsNotNull() && m_InterpolatedSlices.IsNotNull() );
  }

  return true;
}
Beispiel #13
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;
        }
void mitk::SurfaceInterpolationController::SetCurrentInterpolationSession(mitk::Image::Pointer currentSegmentationImage)
{
  if (currentSegmentationImage.GetPointer() == m_SelectedSegmentation)
    return;

  m_ReduceFilter->Reset();
  m_NormalsFilter->Reset();
  m_InterpolateSurfaceFilter->Reset();

  if (currentSegmentationImage.IsNull())
  {
    m_SelectedSegmentation = 0;
    return;
  }
  ContourListMap::iterator it = m_ListOfInterpolationSessions.find(currentSegmentationImage.GetPointer());

  m_SelectedSegmentation = currentSegmentationImage.GetPointer();

  itk::ImageBase<3>::Pointer itkImage = itk::ImageBase<3>::New();
  AccessFixedDimensionByItk_1( m_SelectedSegmentation, GetImageBase, 3, itkImage );
  m_InterpolateSurfaceFilter->SetReferenceImage( itkImage.GetPointer() );

  if (it == m_ListOfInterpolationSessions.end())
  {
    ContourPositionPairList newList;
    m_ListOfInterpolationSessions.insert(std::pair<mitk::Image*, ContourPositionPairList>(m_SelectedSegmentation, newList));
    m_InterpolationResult = 0;
    m_CurrentNumberOfReducedContours = 0;

    itk::MemberCommand<SurfaceInterpolationController>::Pointer command = itk::MemberCommand<SurfaceInterpolationController>::New();
    command->SetCallbackFunction(this, &SurfaceInterpolationController::OnSegmentationDeleted);
    m_SegmentationObserverTags.insert( std::pair<mitk::Image*, unsigned long>( m_SelectedSegmentation, m_SelectedSegmentation->AddObserver( itk::DeleteEvent(), command ) ) );

  }
  else
  {
    for (unsigned int i = 0; i < m_ListOfInterpolationSessions[m_SelectedSegmentation].size(); i++)
    {
      m_ReduceFilter->SetInput(i, m_ListOfInterpolationSessions[m_SelectedSegmentation].at(i).contour);
    }

    m_ReduceFilter->Update();

    m_CurrentNumberOfReducedContours = m_ReduceFilter->GetNumberOfOutputs();

    for (unsigned int i = 0; i < m_CurrentNumberOfReducedContours; i++)
    {
      m_NormalsFilter->SetInput(i, m_ReduceFilter->GetOutput(i));
      m_InterpolateSurfaceFilter->SetInput(i, m_NormalsFilter->GetOutput(i));
    }
  }
  Modified();
}
static void Paint(mitk::Image::Pointer image, itk::Index<3> index, unsigned int timeStep)
{
  // As soon as the ImagePixelWriteAccessor object goes out of scope at the
  // end of this function, the image will be unlocked again (RAII).
  mitk::ImagePixelWriteAccessor<T> writeAccessor(image, image->GetVolumeData(timeStep));
  writeAccessor.SetPixelByIndex(index, std::numeric_limits<T>::min());

  // Don't forget to update the modified time stamp of the image. Otherwise,
  // everything downstream wouldn't recognize that the image changed,
  // including the rendering system.
  image->Modified();
}
    void setUp() override
    {
        m_ReferenceImage = mitk::IOUtil::LoadImage(GetTestDataFilePath("Pic3D.nrrd"));
        CPPUNIT_ASSERT_MESSAGE("Failed to load image for test: [Pic3D.nrrd]", m_ReferenceImage.IsNotNull());

        m_InterpolationController = mitk::SegmentationInterpolationController::GetInstance();

        // Create empty segmentation
        // Surely there must be a better way to get an image with all zeros?
        m_SegmentationImage = mitk::Image::New();
        const mitk::PixelType pixelType(mitk::MakeScalarPixelType<mitk::Tool::DefaultSegmentationDataType>());
        m_SegmentationImage->Initialize(pixelType, m_ReferenceImage->GetDimension(), m_ReferenceImage->GetDimensions());
        m_SegmentationImage->SetClonedTimeGeometry(m_ReferenceImage->GetTimeGeometry());
        unsigned int size = sizeof(mitk::Tool::DefaultSegmentationDataType);
        for (unsigned int dim = 0; dim < m_SegmentationImage->GetDimension(); ++dim)
        {
            size *= m_SegmentationImage->GetDimension(dim);
        }
        mitk::ImageWriteAccessor imageAccessor(m_SegmentationImage);
        memset(imageAccessor.GetData(), 0, size);

        // Work in the center of the image (Pic3D)
        m_CenterPoint = {{ 127, 127, 25 }};

    }
/**
 * @brief RemapIntoVectorImage Take a 3d+t image and reinterpret it as vector image
 * @return vectoriamge
 */
mitk::DiffusionImageCreationFilter::VectorImageType::Pointer
mitk::DiffusionImageCreationFilter::RemapIntoVectorImage( mitk::Image::Pointer input)
{
  typedef itk::Image<mitk::DiffusionPropertyHelper::DiffusionPixelType, 3> ImageVolumeType;
  typedef itk::ComposeImageFilter< ImageVolumeType > ComposeFilterType;

  ComposeFilterType::Pointer vec_composer = ComposeFilterType::New();
  mitk::ImageTimeSelector::Pointer t_selector = mitk::ImageTimeSelector::New();
  t_selector->SetInput( input );

  for( unsigned int i=0; i< input->GetTimeSteps(); i++)
  {
    t_selector->SetTimeNr(i);
    t_selector->Update();

    ImageVolumeType::Pointer singleImageItk;
    mitk::CastToItkImage( t_selector->GetOutput(), singleImageItk );

    vec_composer->SetInput( i, singleImageItk );
  }

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

  mitk::DiffusionImageCreationFilter::VectorImageType::Pointer vector_image = vec_composer->GetOutput();
  vector_image->GetPixelContainer()->ContainerManageMemoryOff();

  return vector_image;
}
void ConvertIplImageForthAndBack(mitk::Image::Pointer inputForIpl, std::string imageFileName)
{
  // now we convert it to OpenCV IplImage
  mitk::ImageToOpenCVImageFilter::Pointer toOCvConverter = mitk::ImageToOpenCVImageFilter::New();
  toOCvConverter->SetImage(inputForIpl);
  IplImage* iplTestImage = toOCvConverter->GetOpenCVImage();

  MITK_TEST_CONDITION_REQUIRED( iplTestImage != NULL, "Conversion to OpenCv IplImage successful!");

  mitk::OpenCVToMitkImageFilter::Pointer toMitkConverter = mitk::OpenCVToMitkImageFilter::New();
  toMitkConverter->SetOpenCVImage(iplTestImage);
  toMitkConverter->Update();

  // initialize the image with the input image, since we want to test equality and OpenCV does not feature geometries and spacing
  mitk::Image::Pointer result = inputForIpl->Clone();
  mitk::ImageReadAccessor resultAcc(toMitkConverter->GetOutput(), toMitkConverter->GetOutput()->GetSliceData());
  result->SetImportSlice(const_cast<void*>(resultAcc.GetData()));

  if( result->GetPixelType().GetNumberOfComponents() == 1 )
  {
    MITK_TEST_EQUAL( result, inputForIpl, "Testing equality of input and output image of IplImage conversion  for " << imageFileName );
  }
  else if( result->GetPixelType().GetNumberOfComponents() == 3 )
  {
    MITK_TEST_EQUAL( result, inputForIpl, "Testing equality of input and output image of cv::Mat conversion for " << imageFileName );
  }
  else
  {
    MITK_WARN << "Unhandled number of components used to test equality, please enhance test!";
  }
}
void mitk::ToFVisualizationFilter::InitImage(mitk::Image::Pointer image)
{
  unsigned int dimensions[2];
  dimensions[0] = this->m_ImageWidth;
  dimensions[1] = this->m_ImageHeight;
  image->Initialize(mitk::PixelType(mitkIpPicUInt, 24, 3), 2, dimensions); //unsigned char RGB
}
Beispiel #20
0
mitk::pa::Volume::Volume(mitk::Image::Pointer image)
{
  MITK_INFO << "Initialized by mitk::Image";

  if (image.IsNull())
    mitkThrow() << "You may not initialize a mitk::Volume with a null reference to an mitk image";

  unsigned int* dimensions = image->GetDimensions();
  m_YDim = dimensions[0];
  m_XDim = dimensions[1];
  m_ZDim = dimensions[2];

  m_InternalMitkImage = image;

  m_FastAccessDataPointer = GetData();
}
// 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();
  }
}
Beispiel #22
0
void ReadMitkProjectImageAndMask(std::string input_file, mitk::Image::Pointer & raw_image, mitk::Image::Pointer & class_mask, mitk::Image::Pointer & brain_mask)
{
  auto so = mitk::IOUtil::Load(input_file);

  std::map<uint, uint> map;

  mitk::CLUtil::CountVoxel(dynamic_cast<mitk::Image *>(so[1].GetPointer()), map);

  raw_image = map.size() <= 7 ? dynamic_cast<mitk::Image *>(so[0].GetPointer()) : dynamic_cast<mitk::Image *>(so[1].GetPointer());
  class_mask = map.size() <= 7 ? dynamic_cast<mitk::Image *>(so[1].GetPointer()) : dynamic_cast<mitk::Image *>(so[0].GetPointer());

  std::map<uint, uint> merge_instructions;// = {{0,0},{1,1},{2,1},{3,1},{4,2},{5,3},{6,3}};
  merge_instructions[0] = 0;
  merge_instructions[1] = 1;
  merge_instructions[2] = 1;
  merge_instructions[3] = 1;
  merge_instructions[4] = 2;
  merge_instructions[5] = 3;
  merge_instructions[6] = 3;
  mitk::CLUtil::MergeLabels(class_mask, merge_instructions);

  brain_mask = class_mask->Clone();
  //merge_instructions = {{0,0},{1,1},{2,1},{3,1},{4,1},{5,1},{6,1}};
  merge_instructions[0] = 0;
  merge_instructions[1] = 1;
  merge_instructions[2] = 1;
  merge_instructions[3] = 1;
  merge_instructions[4] = 1;
  merge_instructions[5] = 1;
  merge_instructions[6] = 1;
  mitk::CLUtil::MergeLabels(brain_mask, merge_instructions);
}
Beispiel #23
0
void
ResampleImage(itk::Image<TPixel, VImageDimension>* itkImage, float resolution, mitk::Image::Pointer& newImage)
{
  typedef itk::Image<TPixel, VImageDimension> ImageType;
  typedef itk::ResampleImageFilter<ImageType, ImageType> ResampleFilterType;

  typename ResampleFilterType::Pointer resampler = ResampleFilterType::New();
  auto spacing = itkImage->GetSpacing();
  auto size = itkImage->GetLargestPossibleRegion().GetSize();

  for (unsigned int i = 0; i < VImageDimension; ++i)
  {
    size[i] = size[i] / (1.0*resolution)*(1.0*spacing[i])+1.0;
  }
  spacing.Fill(resolution);

  resampler->SetInput(itkImage);
  resampler->SetSize(size);
  resampler->SetOutputSpacing(spacing);
  resampler->SetOutputOrigin(itkImage->GetOrigin());
  resampler->SetOutputDirection(itkImage->GetDirection());
  resampler->Update();

  newImage->InitializeByItk(resampler->GetOutput());
  mitk::GrabItkImageMemory(resampler->GetOutput(), newImage);
}
  /**
  * This test takes a generated gradient mitk image. Then an IGTL Message is produced
  * using the ImageToIGTLMessageFilter. In the end it is tested, wether the image data in both images is equivalent.
  */
  void Equal_ContentOfIGTLImageMessageAndMitkImage_True(unsigned int dim)
  {
    m_TestImage = mitk::ImageGenerator::GenerateGradientImage<unsigned char>(dim, dim, 1u);

    m_ImageToIGTLMessageFilter->SetInput(m_TestImage);

    m_ImageToIGTLMessageFilter->GenerateData();

    mitk::IGTLMessage::Pointer resultMessage = m_ImageToIGTLMessageFilter->GetOutput();

    CPPUNIT_ASSERT_MESSAGE("Output of ImageToIGTLMessageFilter was null", resultMessage != nullptr);

    igtl::MessageBase::Pointer msgBase = resultMessage->GetMessage();
    igtl::ImageMessage* igtlImageMessage = (igtl::ImageMessage*)(msgBase.GetPointer());

    CPPUNIT_ASSERT_MESSAGE("Output of ImageToIGTLMessageFilter was not of type igtl::ImageMessage", igtlImageMessage != nullptr);

    const void* outputBuffer = igtlImageMessage->GetScalarPointer();

    CPPUNIT_ASSERT_MESSAGE("Output Buffer was null", outputBuffer != nullptr);

    mitk::ImageReadAccessor readAccess(m_TestImage, m_TestImage->GetChannelData(0));
    const void* inputBuffer = readAccess.GetData();

    CPPUNIT_ASSERT_MESSAGE("Input Buffer was null", inputBuffer != nullptr);

    CPPUNIT_ASSERT_MESSAGE("Images were not identical", memcmp(inputBuffer, outputBuffer, dim*dim) == 0);
  }
static bool CompareImages(mitk::Image::Pointer image1, mitk::Image::Pointer image2)
{
  //check if epsilon is exceeded
  unsigned int sliceDimension = image1->GetDimension(0)*image1->GetDimension(1);
  bool picturesEqual = true;

  float* floatArray1 = (float*)image1->GetSliceData(0, 0, 0)->GetData();
  float* floatArray2 = (float*)image2->GetSliceData(0, 0, 0)->GetData();
  for(unsigned int i = 0; i < sliceDimension; i++)
  {
    if(!(mitk::Equal(floatArray1[i], floatArray2[i])))
    {
      picturesEqual = false;
    }
  }
  return picturesEqual;
}
bool mitkSegmentationInterpolationTestClass::ClearSegmentation()
{
  int* p = (int*)m_Image->GetData(); // pointer to pixel data
  int size = dim[0]*dim[1]*dim[2];
  for(int i=0; i<size; ++i, ++p) *p=0; // fill image with zeros
  
  return true;
}
  void GetImageStatisticsWithImageConnected()
  {
    //create rules connection
    auto statisticsNode = mitk::CreateImageStatisticsNode(m_statisticsContainer, "testStatistics");
    CreateNodeRelationImage(m_statisticsContainer.GetPointer(), m_image.GetPointer());
    auto standaloneDataStorage = mitk::StandaloneDataStorage::New();
    standaloneDataStorage->Add(statisticsNode);

    //rule: (image-->statistics), 1 connected image --> test return image statistics
    mitk::ImageStatisticsContainer::ConstPointer statisticsWithImage;
    CPPUNIT_ASSERT_NO_THROW(statisticsWithImage = mitk::ImageStatisticsContainerManager::GetImageStatistics(standaloneDataStorage.GetPointer(), m_image.GetPointer()));
    CPPUNIT_ASSERT_EQUAL(statisticsWithImage->GetUID(), m_statisticsContainer->GetUID());

    //new rule: (image2-->statistics2 AND mask --> statistics2)
    CreateNodeRelationImage(m_statisticsContainer2.GetPointer(), m_image2.GetPointer());
    CreateNodeRelationMask(m_statisticsContainer2.GetPointer(), m_mask.GetPointer());

    auto statisticsNode2 = mitk::CreateImageStatisticsNode(m_statisticsContainer2, "testStatistics2");
    standaloneDataStorage->Add(statisticsNode2);

    //--> test return (still) image statistics (!= statistics2)
    mitk::ImageStatisticsContainer::ConstPointer statisticsWithImageAgain;
    CPPUNIT_ASSERT_NO_THROW(statisticsWithImageAgain = mitk::ImageStatisticsContainerManager::GetImageStatistics(standaloneDataStorage.GetPointer(), m_image.GetPointer()));
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageAgain->GetUID(), m_statisticsContainer->GetUID());
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageAgain->GetUID() != m_statisticsContainer2->GetUID(), true);

    //--> test return image statistics 2
    CPPUNIT_ASSERT_NO_THROW(statisticsWithImageAgain = mitk::ImageStatisticsContainerManager::GetImageStatistics(standaloneDataStorage.GetPointer(), m_image2.GetPointer(), m_mask.GetPointer()));
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageAgain->GetUID(), m_statisticsContainer2->GetUID());
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageAgain->GetUID() != m_statisticsContainer->GetUID(), true);

    //add another newer statistic: should return this newer one
    auto statisticsContainerNew = mitk::ImageStatisticsContainer::New();
    CreateNodeRelationImage(statisticsContainerNew.GetPointer(), m_image.GetPointer());

    auto statisticsNodeNew = mitk::CreateImageStatisticsNode(statisticsContainerNew, "testStatisticsNew");
    standaloneDataStorage->Add(statisticsNodeNew);
    statisticsContainerNew->Modified();

    mitk::ImageStatisticsContainer::ConstPointer statisticsWithImageNew;
    CPPUNIT_ASSERT_NO_THROW(statisticsWithImageNew = mitk::ImageStatisticsContainerManager::GetImageStatistics(standaloneDataStorage.GetPointer(), m_image.GetPointer()));
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageNew->GetUID(), statisticsContainerNew->GetUID());
    CPPUNIT_ASSERT_EQUAL(statisticsWithImageNew->GetUID() != m_statisticsContainer->GetUID(), true);
  }
void QmitkImageStatisticsCalculationThread::Initialize( mitk::Image::Pointer image, mitk::Image::Pointer binaryImage, mitk::PlanarFigure::Pointer planarFig )
{
  // reset old values
  if( this->m_StatisticsImage.IsNotNull() )
    this->m_StatisticsImage = 0;

  if( this->m_BinaryMask.IsNotNull() )
    this->m_BinaryMask = 0;

  if( this->m_PlanarFigureMask.IsNotNull())
    this->m_PlanarFigureMask = 0;

  // set new values if passed in
  if(image.IsNotNull())
    this->m_StatisticsImage = image->Clone();
  if(binaryImage.IsNotNull())
    this->m_BinaryMask = binaryImage->Clone();
  if(planarFig.IsNotNull())
    this->m_PlanarFigureMask = dynamic_cast<mitk::PlanarFigure*>(planarFig.GetPointer()); // once clone methods for planar figures are implemented, copy the data here!
}
Beispiel #29
0
 void ToFOpenCVImageGrabber::MapScalars( mitk::Image::Pointer mitkImage, IplImage* openCVImage)
 {
   unsigned int numOfPixel = m_ImageGrabber->GetCaptureWidth()*m_ImageGrabber->GetCaptureHeight();
   float* floatData = (float*)mitkImage->GetSliceData(0, 0, 0)->GetData();
   vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = vtkColorTransferFunction::New();
   vtkSmartPointer<vtkFloatArray> floatArrayInt;
   floatArrayInt = vtkFloatArray::New();
   floatArrayInt->Initialize();
   floatArrayInt->SetArray(floatData, numOfPixel, 0);
   mitk::ScalarType min = mitkImage->GetScalarValueMin();
   mitk::ScalarType max = mitkImage->GetScalarValueMaxNoRecompute();
   MITK_INFO<<"Minimum: "<<min;
   MITK_INFO<<"Maximum: "<<max;
   colorTransferFunction->RemoveAllPoints();
   colorTransferFunction->AddRGBPoint(min, 0, 0, 0);
   colorTransferFunction->AddRGBPoint(max, 1, 1, 1);
   colorTransferFunction->SetColorSpaceToHSV();
   //TODO other depth values
   colorTransferFunction->MapScalarsThroughTable(floatArrayInt, (unsigned char*)openCVImage->imageData, VTK_LUMINANCE);
 }
void QmitkImageStatisticsCalculationThread::Initialize( mitk::Image::Pointer image, mitk::Image::Pointer binaryImage, mitk::PlanarFigure::Pointer planarFig )
{
  // reset old values
  if( this->m_StatisticsImage.IsNotNull() )
    this->m_StatisticsImage = 0;

  if( this->m_BinaryMask.IsNotNull() )
    this->m_BinaryMask = 0;

  if( this->m_PlanarFigureMask.IsNotNull())
    this->m_PlanarFigureMask = 0;

  // set new values if passed in
  if(image.IsNotNull())
    this->m_StatisticsImage = image->Clone();
  if(binaryImage.IsNotNull())
    this->m_BinaryMask = binaryImage->Clone();
  if(planarFig.IsNotNull())
    this->m_PlanarFigureMask = planarFig->Clone();
}