Ejemplo n.º 1
0
  /**
   * @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 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 }};

    }
Ejemplo n.º 3
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]";
}
Ejemplo n.º 4
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();
}
Ejemplo n.º 5
0
  /**
   * @brief ConvertToRGBImage converts a gray image to RGB by filling all three channels with the gray intensity
   * @param grayImage
   * @return
   */
  mitk::Image::Pointer ConvertToRGBImage(mitk::Image::Pointer grayImage)
  {
    mitk::Image::Pointer rgbImage = mitk::Image::New();
    unsigned int *dim = grayImage->GetDimensions();
    rgbImage->Initialize(mitk::MakePixelType<PixelType, RGBPixelType,3>(),3,dim);
    rgbImage->SetGeometry(grayImage->GetGeometry());

    itk::Image<InputPixelType,3>::Pointer itkGrayImage = itk::Image<InputPixelType,3>::New();
    mitk::CastToItkImage(grayImage, itkGrayImage);


    mitk::ImagePixelWriteAccessor<RGBPixelType,3> writeAcc(rgbImage);


    typedef itk::RescaleIntensityImageFilter< itk::Image<InputPixelType,3>, itk::Image<PixelType,3> > RescaleFilterType;
    RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
    rescaleFilter->SetInput(itkGrayImage);
    rescaleFilter->SetOutputMinimum(0);
    rescaleFilter->SetOutputMaximum(255*255);
    rescaleFilter->Update();

    itk::Index<3> idx;
    RGBPixelType value;

    // 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]++)
        {
          value.Fill(rescaleFilter->GetOutput()->GetPixel(idx));
          writeAcc.SetPixelByIndex(idx, value);
        }
      }
    }
    return rgbImage;
  }