コード例 #1
0
static itk::Index<2> GetFirstPoint(const mitk::CorrectorAlgorithm::TSegData &segment, itk::Image< ipMITKSegmentationTYPE, 2 >::Pointer pic, int fillColor)
{
  int colorMode = (pic->GetPixel(segment.points[0]) == fillColor);

  std::vector< itk::Index<2> >::const_iterator indexIterator;
  std::vector< itk::Index<2> >::const_iterator indexEnd;

  indexIterator = segment.points.begin();
  indexEnd = segment.points.end();

  for (; indexIterator != indexEnd; ++indexIterator)
  {
    itk::Index<2> index;
    for (int xOffset = -1 ; xOffset < 2; ++xOffset)
    {
      for (int yOffset = -1 ; yOffset < 2; ++yOffset)
      {
        index[0] = (*indexIterator)[0] - xOffset;
        index[1] = (*indexIterator)[1] - yOffset;
        if ((pic->GetPixel(index) == fillColor) != colorMode)
        {
          return index;
        }
      }
    }
  }
  mitkThrow() << "No Starting point is found next to the curve.";
}
コード例 #2
0
  itk::Image<itk::RGBPixel<PixelType>,2>::Pointer ExtractSlice(itk::Image<itk::RGBPixel<PixelType>, 3>::Pointer itkImage, unsigned int sliceNo)
  {
    typedef itk::Image<RGBPixelType, 3> InputImageType;
    typedef itk::Image<RGBPixelType, 2> OutputImageType;

    int dim[3];
    dim[0]= itkImage->GetLargestPossibleRegion().GetSize()[0];
    dim[1]= itkImage->GetLargestPossibleRegion().GetSize()[1];
    dim[2]= itkImage->GetLargestPossibleRegion().GetSize()[2];

    itk::Index<3> desiredStart;
    itk::Size<3> desiredSize;

    //case AXIAL: // 3rd dimension fixed
    desiredStart.Fill(0);
    desiredStart[2]=sliceNo;
    desiredSize.Fill(0);
    desiredSize[0] = dim[0];
    desiredSize[1] = dim[1];
    desiredSize[2] =0;

    itk::ImageRegion<3> desiredRegion(desiredStart, desiredSize);

    // Extract slice
    itk::ExtractImageFilter<InputImageType,OutputImageType>::Pointer extractSlice = itk::ExtractImageFilter<InputImageType,OutputImageType>::New();
    extractSlice->SetInput(itkImage);
    extractSlice->SetExtractionRegion(desiredRegion);
    extractSlice->SetDirectionCollapseToIdentity();
    extractSlice->Update();

    return extractSlice->GetOutput();
  }
コード例 #3
0
itk::Statistics::ListSample< itk::Vector< double, 1 > >::Pointer pdp::EMClassification::prepareSample(itk::Image<float, 3>::Pointer img, itk::Image<unsigned char, 3>::Pointer mask)
{

	typedef itk::Vector< double, 1 > MeasurementVectorType;
	typedef itk::Statistics::ListSample< MeasurementVectorType > SampleType;
	typedef itk::Image<unsigned char, 3> MaskType;
	typedef itk::Image<float, 3> ImageType;

	SampleType::Pointer sample = SampleType::New();

	typedef itk::ImageRegionConstIterator< ImageType > ImageIteratorType;
	ImageIteratorType imgIt(img, img->GetLargestPossibleRegion());

	typedef itk::ImageRegionConstIterator< MaskType> MaskIteratorType;
	MaskIteratorType maskIt( mask, mask->GetLargestPossibleRegion());

	MeasurementVectorType mv;
	for ( imgIt.GoToBegin(), maskIt.GoToBegin(); !maskIt.IsAtEnd(); ++maskIt, ++imgIt)
	{

		if (maskIt.Get() == 255)
		{
			mv[0] = imgIt.Get();
			sample->PushBack( mv );
		}
	}

	return sample;
}
コード例 #4
0
static void ComputeIntensityProfile(itk::Image<TPixel, VImageDimension>* image, itk::PolyLineParametricPath<3>::Pointer path, unsigned int numSamples, InterpolateImageFunction::Enum interpolator, IntensityProfile::Pointer intensityProfile)
{
  typename itk::InterpolateImageFunction<itk::Image<TPixel, VImageDimension> >::Pointer interpolateImageFunction = CreateInterpolateImageFunction<itk::Image<TPixel, VImageDimension> >(interpolator);
  interpolateImageFunction->SetInputImage(image);

  const itk::PolyLineParametricPath<3>::InputType startOfInput = path->StartOfInput();
  const itk::PolyLineParametricPath<3>::InputType delta = 1.0 / (numSamples - 1);

  IntensityProfile::MeasurementVectorType measurementVector;

  for (unsigned int i = 0; i < numSamples; ++i)
  {
    measurementVector[0] = interpolateImageFunction->EvaluateAtContinuousIndex(path->Evaluate(startOfInput + i * delta));
    intensityProfile->PushBack(measurementVector);
  }
}
コード例 #5
0
static void ColorSegment(const mitk::CorrectorAlgorithm::TSegData &segment, itk::Image< ipMITKSegmentationTYPE, 2 >::Pointer pic, int fillColor, int eraseColor)
{
  int colorMode = (pic->GetPixel(segment.points[0]) == fillColor);
  int color = 0;
  if (colorMode)
    color = eraseColor;
  else
    color = fillColor;

  std::vector< itk::Index<2> >::const_iterator indexIterator;
  std::vector< itk::Index<2> >::const_iterator indexEnd;

  indexIterator = segment.points.begin();
  indexEnd = segment.points.end();

  for (; indexIterator != indexEnd; ++indexIterator)
  {
    pic->SetPixel(*indexIterator, color);
  }
}
//Compute the translation vector that moves the center of the image into 0,0,0
itk::Vector< double , 3 > ComputeTranslationToCenter( itk::Image< unsigned short , 3 >::Pointer image )
{
  typedef itk::Image< unsigned short , 3 > ImageType ;
  ImageType::IndexType index ;
  ImageType::SizeType size ;
  size = image->GetLargestPossibleRegion().GetSize() ;
  for( int i = 0 ; i < 3 ; i++ )
  {
    index[ i ] = size[ i ] - 1 ;
  }
  ImageType::PointType corner ;
  image->TransformIndexToPhysicalPoint( index , corner ) ;
  ImageType::PointType origin ;
  origin = image->GetOrigin() ;
  itk::Vector< double , 3 > translation ;
  for( int i = 0 ; i < 3 ; i++ )
  {
    translation[ i ] = ( corner[ i ] + origin[ i ] ) / 2.0 ;
  }
  return translation ;
}
コード例 #7
0
static void OverwriteImage(itk::Image< ipMITKSegmentationTYPE, 2 >::Pointer source, itk::Image< ipMITKSegmentationTYPE, 2 >::Pointer target)
{
  typedef itk::Image< ipMITKSegmentationTYPE, 2 > ItkImageType;
  typedef itk::ImageRegionIterator<ItkImageType> ImageIteratorType;

  ImageIteratorType sourceIter(source, source->GetLargestPossibleRegion());
  ImageIteratorType targetIter(target, target->GetLargestPossibleRegion());
  while ( ! sourceIter.IsAtEnd())
  {
    targetIter.Set(sourceIter.Get());
    ++sourceIter;
    ++targetIter;
  }
}
コード例 #8
0
std::string DICOMVolumeLoader::read_header_field(const itk::Image<int,2>::Pointer& image, const std::string& key)
{
	const itk::MetaDataDictionary& dict = image->GetMetaDataDictionary();

	const itk::MetaDataObjectBase *baseVal = dict[key];
	if(!baseVal) throw Exception("No such key in image header: " + key);

	const itk::MetaDataObject<std::string> *strVal = dynamic_cast<const itk::MetaDataObject<std::string>*>(baseVal);
	if(!strVal) throw Exception("The value associated with " + key + " isn't a string");

	std::string ret = strVal->GetMetaDataObjectValue();
	boost::trim(ret);
	return ret;
}
コード例 #9
0
itk::Image<unsigned char, 3>::Pointer pdp::EMClassification::classify(itk::Image<float, 3>::Pointer img, itk::Image<unsigned char, 3>::Pointer mask)
{
	typedef itk::Vector< double, 1 > MeasurementVectorType;
	typedef itk::Image<unsigned char, 3> MaskType;
	typedef itk::Image<float, 3> ImageType;

	typedef itk::ImageRegionConstIterator< ImageType > ImageIteratorType;
	ImageIteratorType imgIt(img, img->GetLargestPossibleRegion());

	typedef itk::ImageRegionConstIterator< MaskType> MaskIteratorType;
	MaskIteratorType maskIt( mask, mask->GetLargestPossibleRegion());

	MaskType::Pointer correctImage = MaskType::New();
	correctImage->CopyInformation(mask);
	MaskType::RegionType outputRegion = mask->GetLargestPossibleRegion();
	correctImage->SetRegions( outputRegion );
	correctImage->Allocate();
	typedef itk::ImageRegionIterator<MaskType> IteratorType;
	IteratorType outputIt( correctImage, outputRegion);

	MeasurementVectorType mv;
	for ( imgIt.GoToBegin(), maskIt.GoToBegin(), outputIt.GoToBegin(); !maskIt.IsAtEnd(); ++maskIt, ++imgIt, ++outputIt)
	{

		if (maskIt.Get() == 255)
		{
			mv[0] = imgIt.Get();
			if (genLabel(mv) == 3)
			{
				outputIt.Set(255);
			}
		}
	}

	return correctImage;
}
コード例 #10
0
void mitk::SurfaceInterpolationController::GetImageBase(itk::Image<TPixel, VImageDimension>* input, itk::ImageBase<3>::Pointer& result)
{
  result->Graft(input);
}
コード例 #11
0
bool mitk::CorrectorAlgorithm::ImprovedHeimannCorrectionAlgorithm(itk::Image< ipMITKSegmentationTYPE, 2 >::Pointer pic)
{
/*!
Some documentation (not by the original author)

TobiasHeimannCorrectionAlgorithm will be called, when the user has finished drawing a freehand line.

There should be different results, depending on the line's properties:

1. Without any prior segmentation, the start point and the end point of the drawn line will be
connected to a contour and the area enclosed by the contour will be marked as segmentation.

2. When the whole line is inside a segmentation, start and end point will be connected to
a contour and the area of this contour will be subtracted from the segmentation.

3. When the line starts inside a segmentation and ends outside with only a single
transition from segmentation to no-segmentation, nothing will happen.

4. When there are multiple transitions between inside-segmentation and
outside-segmentation, the line will be divided in so called segments. Each segment is
either fully inside or fully outside a segmentation. When it is inside a segmentation, its
enclosed area will be subtracted from the segmentation. When the segment is outside a
segmentation, its enclosed area it will be added to the segmentation.

The algorithm is described in full length in Tobias Heimann's diploma thesis
(MBI Technical Report 145, p. 37 - 40).
*/

  ContourModel::Pointer projectedContour = mitk::ContourModelUtils::ProjectContourTo2DSlice( m_WorkingImage, m_Contour, true, false );

  bool firstPointIsFillingColor = false;

  if (projectedContour.IsNull() ||
    projectedContour->GetNumberOfVertices() < 2 )
  {
    return false;
  }

  // Read the first point of the contour
  ContourModel::VertexIterator contourIter = projectedContour->Begin();
  if (contourIter == projectedContour->End())
    return false;
  itk::Index<2> previousIndex;
  previousIndex[0] = (*contourIter)->Coordinates[0];
  previousIndex[1] = (*contourIter)->Coordinates[1];
  ++contourIter;

  int currentColor = ( pic->GetPixel(previousIndex) == m_FillColor);
  firstPointIsFillingColor = currentColor;
  TSegData currentSegment;
  int countOfSegments = 1;


  bool firstSegment = true;
  ContourModel::VertexIterator contourEnd = projectedContour->End();
  for (; contourIter != contourEnd; ++contourIter)
  {
    // Get current point
    itk::Index<2> currentIndex;
    currentIndex[0] = (*contourIter)->Coordinates[0] +0.5;
    currentIndex[1] = (*contourIter)->Coordinates[1] +0.5;

    // Calculate length and slope
    double slopeX = currentIndex[0] - previousIndex[0];
    double slopeY = currentIndex[1] - previousIndex[1];
    double length = std::sqrt(slopeX * slopeX + slopeY * slopeY);
    double deltaX = slopeX / length;
    double deltaY = slopeY / length;

    for (double i = 0; i <= length && length > 0; i+=1)
    {
      itk::Index<2> temporaryIndex;
      temporaryIndex[0] = previousIndex[0] + deltaX * i;
      temporaryIndex[1] = previousIndex[1] + deltaY * i;
      if ( ! pic->GetLargestPossibleRegion().IsInside(temporaryIndex))
        continue;
      if ( (pic->GetPixel(temporaryIndex) == m_FillColor) != currentColor)
      {
        currentSegment.points.push_back(temporaryIndex);
        if ( ! firstSegment)
        {
          ModifySegment( currentSegment, pic);
        } else
        {
          firstSegment = false;
        }
        currentSegment = TSegData();
        ++countOfSegments;
        currentColor = (pic->GetPixel(temporaryIndex) == m_FillColor);
      }
      currentSegment.points.push_back(temporaryIndex);
    }
    previousIndex = currentIndex;
  }

  // Check if only on Segment
  if (firstSegment && currentSegment.points.size() > 0)
  {
      ContourModel::Pointer projectedContour = mitk::ContourModelUtils::ProjectContourTo2DSlice( m_WorkingImage, m_Contour, true, false );
      projectedContour->Close();
      if (firstPointIsFillingColor)
      {
        ContourModelUtils::FillContourInSlice(projectedContour, 0, m_WorkingImage, m_EraseColor);
      } else
      {
        ContourModelUtils::FillContourInSlice(projectedContour, 0, m_WorkingImage, m_FillColor);
      }
  }
  return true;
}
コード例 #12
0
static std::vector<itk::Index<2> > FindSeedPoints(const mitk::CorrectorAlgorithm::TSegData &segment, itk::Image< ipMITKSegmentationTYPE, 2 >::Pointer pic, int fillColor)
{
  typedef itk::Image< ipMITKSegmentationTYPE, 2 > ItkImageType;
  typedef itk::Image< ipMITKSegmentationTYPE, 2 >::Pointer ItkImagePointerType;

  int colorMode = (pic->GetPixel(segment.points[0]) == fillColor);
  std::vector<itk::Index<2> > seedPoints;

  try
  {
    itk::Index<2> firstPoint = GetFirstPoint(segment,  pic, fillColor);
    seedPoints.push_back(firstPoint);
  }
  catch (mitk::Exception e)
  {
    return seedPoints;
  }

  if (segment.points.size() < 4)
    return seedPoints;

  std::vector< itk::Index<2> >::const_iterator indexIterator;
  std::vector< itk::Index<2> >::const_iterator indexEnd;

  indexIterator = segment.points.begin();
  indexEnd = segment.points.end();

  ItkImagePointerType listOfPoints = CloneImage(pic);
  listOfPoints->FillBuffer(0);
  listOfPoints->SetPixel(seedPoints[0],1);
  for (; indexIterator != indexEnd; ++indexIterator)
  {
    listOfPoints->SetPixel(*indexIterator, 2);
  }
  indexIterator = segment.points.begin();
  indexIterator++;
  indexIterator++;
  indexEnd--;
  indexEnd--;
  for (; indexIterator != indexEnd; ++indexIterator)
  {
    bool pointFound = true;
    while (pointFound)
    {
      pointFound = false;
      itk::Index<2> index;
      itk::Index<2> index2;
      for (int xOffset = -1 ; xOffset < 2; ++xOffset)
      {
        for (int yOffset = -1 ; yOffset < 2; ++yOffset)
        {
          index[0] = (*indexIterator)[0] - xOffset;
          index[1] = (*indexIterator)[1] - yOffset;
          index2 = index;

          if (listOfPoints->GetPixel(index2) > 0)
            continue;

          index[0]--;
          if (listOfPoints->GetPixel(index) == 1)
          {
            pointFound = true;
            seedPoints.push_back(index2);
            listOfPoints->SetPixel(index2,1);
            continue;
          }
          index[0]=index[0] + 2;
          if (listOfPoints->GetPixel(index) == 1)
          {
            pointFound = true;
            seedPoints.push_back(index2);
            listOfPoints->SetPixel(index2,1);
            continue;
          }
          index[0]--;
          index[1]--;
          if (listOfPoints->GetPixel(index) == 1)
          {
            pointFound = true;
            seedPoints.push_back(index2);
            listOfPoints->SetPixel(index2,1);
            continue;
          }
          index[1]=index[1] + 2;
          if (listOfPoints->GetPixel(index) == 1)
          {
            pointFound = true;
            seedPoints.push_back(index2);
            listOfPoints->SetPixel(index2,1);
            continue;
          }
        }
      }
    }
  }
  return seedPoints;
}
コード例 #13
0
ファイル: Cell.cpp プロジェクト: JumperWang/farsight-clone
void Cell::SplitITKCovariantVectorImage(const itk::Image< itk::CovariantVector< double, 3 >, 3 >::Pointer & covar_image, itk::Image< double, 3>::Pointer & x_image, itk::Image< double, 3>::Pointer & y_image, itk::Image< double, 3>::Pointer & z_image)
{
	//Separate the covar image into its components
	typedef itk::Image< itk::CovariantVector< double, 3 >, 3 > CovarVectorImageType;
	typedef itk::Image< double, 3 > ComponentImageType;

	ComponentImageType::SizeType size = covar_image->GetLargestPossibleRegion().GetSize();
	ComponentImageType::IndexType start;
	start.Fill(0);
	ComponentImageType::RegionType region(start, size);

	x_image->SetRegions(region);
	y_image->SetRegions(region);
	z_image->SetRegions(region);

	x_image->Allocate();
	y_image->Allocate();
	z_image->Allocate();

	itk::ImageRegionConstIterator< CovarVectorImageType > covar_image_iter(covar_image, covar_image->GetLargestPossibleRegion());
	itk::ImageRegionIterator< ComponentImageType > x_image_iter(x_image, x_image->GetLargestPossibleRegion());
	itk::ImageRegionIterator< ComponentImageType > y_image_iter(y_image, y_image->GetLargestPossibleRegion());
	itk::ImageRegionIterator< ComponentImageType > z_image_iter(z_image, z_image->GetLargestPossibleRegion());

	while (!covar_image_iter.IsAtEnd())
	{
		CovarVectorImageType::PixelType vector = covar_image_iter.Get();

		x_image_iter.Set(vector[0]);
		y_image_iter.Set(vector[1]);
		z_image_iter.Set(vector[2]);

		++covar_image_iter;
		++x_image_iter;
		++y_image_iter;
		++z_image_iter;
	}
}