コード例 #1
0
bool CreateRandomDistanceImage(unsigned int dimX, unsigned int dimY, ItkImageType_2D::Pointer& itkImage, mitk::Image::Pointer& mitkImage) //TODO warum ITK image?
{

  //initialize ITK output image
  ItkImageType_2D::IndexType start;
  start[0] = 0;
  start[1] = 0;
  ItkImageType_2D::SizeType size;
  size[0] = dimX;
  size[1] = dimY;
  ItkImageType_2D::RegionType region;
  region.SetSize(size);
  region.SetIndex( start);
  ItkImageType_2D::SpacingType spacing;
  spacing[0] = 1.0;
  spacing[1] = 1.0;

  itkImage->SetRegions( region );
  itkImage->SetSpacing ( spacing );
  itkImage->Allocate();


  ItkImageRegionIteratorType2D imageIterator(itkImage,itkImage->GetLargestPossibleRegion());
  imageIterator.GoToBegin();
  itk::Statistics::MersenneTwisterRandomVariateGenerator::Pointer randomGenerator = itk::Statistics::MersenneTwisterRandomVariateGenerator::New();


  while (!imageIterator.IsAtEnd())
  {
    ToFScalarType pixelValue = randomGenerator->GetUniformVariate(0.0,1000.0);
    imageIterator.Set(pixelValue);
    ++imageIterator;
  }

  mitk::CastToMitkImage(itkImage,mitkImage);

  return true;
}
コード例 #2
0
static bool ApplyTemporalMedianFilter(mitk::Image::Pointer& image, ItkImageType_2D::Pointer& itkImage2D)
{

  //initialize ITK output image
  unsigned int dimX = image->GetDimension(0);
  unsigned int dimY = image->GetDimension(1);
  unsigned int nbSlices = image->GetDimension(2);

  ItkImageType_2D::SizeType size;
  size[0] = dimX;
  size[1] = dimY;

  ItkImageType_2D::RegionType region;
  region.SetSize(size);

  ItkImageType_2D::SpacingType spacing;
  spacing[0] = 1.0;
  spacing[1] = 1.0;

  itkImage2D->SetRegions( region );
  itkImage2D->SetSpacing ( spacing );
  itkImage2D->Allocate();

  //initialize median filtering
  std::vector<ToFScalarType> allDistances;
  mitk::Index3D curIdx3D;
  ItkImageType_2D::IndexType curIdx2D;

  //compute median over time for each (x,y)
  for(unsigned int i = 0; i<dimX; i++)
  {
    for(unsigned int j = 0; j < dimY; j++)
    {
      allDistances.clear();

      curIdx3D[0] = i; curIdx3D[1] = j;
      curIdx2D[0] = i; curIdx2D[1] = j;
      //gather all distances for one pixel
      for(unsigned int k = 0; k < nbSlices; k++)
      {
        curIdx3D[2] = k;
        allDistances.push_back(image->GetPixelValueByIndex(curIdx3D));
      }

      //sort distances and compute median
      std::sort(allDistances.begin(),allDistances.end());
      unsigned int median_idx = nbSlices/2;
      if(nbSlices%2 == 1) //i.e., there is an odd number of slices
      {
        itkImage2D->SetPixel(curIdx2D,allDistances[median_idx]);
      } else
      {
        ToFScalarType upper = allDistances[median_idx];
        ToFScalarType lower = allDistances[median_idx+1];
        itkImage2D->SetPixel(curIdx2D,(upper+lower)/2.0);
      }
    }
  }
  return true;

}