Esempio n. 1
0
void StrokeMask::
Write(const std::string& filename,
      const TPixel& strokeValue)
{
  typedef itk::Image<TPixel, 2> ImageType;
  typename ImageType::Pointer image = ImageType::New();

  image->SetRegions(this->GetLargestPossibleRegion());
  image->Allocate();

  itk::ImageRegionConstIteratorWithIndex<StrokeMask>
      maskIterator(this,
                   this->GetLargestPossibleRegion());
  while(!maskIterator.IsAtEnd())
  {
    if(maskIterator.Get() == StrokeMaskPixelTypeEnum::STROKE)
    {
      image->SetPixel(maskIterator.GetIndex(),
                      strokeValue);
    }
    else
    {
      image->SetPixel(maskIterator.GetIndex(), itk::NumericTraits<TPixel>::Zero);
    }

    ++maskIterator;
  }

  typedef  itk::ImageFileWriter<ImageType> WriterType;
  typename WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(filename);
  writer->SetInput(image);
  writer->Update();

}
void ForegroundBackgroundSegmentMask::
Write(const std::string& filename,
      const ForegroundPixelValueWrapper<TPixel>& foregroundValue,
      const BackgroundPixelValueWrapper<TPixel>& backgroundValue)
{
  typedef itk::Image<TPixel, 2> ImageType;
  typename ImageType::Pointer image = ImageType::New();

  image->SetRegions(this->GetLargestPossibleRegion());
  image->Allocate();

  itk::ImageRegionConstIteratorWithIndex<ForegroundBackgroundSegmentMask>
      maskIterator(this,
                   this->GetLargestPossibleRegion());
  while(!maskIterator.IsAtEnd())
  {
    if(maskIterator.Get() == ForegroundBackgroundSegmentMaskPixelTypeEnum::FOREGROUND)
    {
      image->SetPixel(maskIterator.GetIndex(),
                      foregroundValue.Value);
    }
    else if(maskIterator.Get() == ForegroundBackgroundSegmentMaskPixelTypeEnum::BACKGROUND)
    {
      image->SetPixel(maskIterator.GetIndex(), backgroundValue.Value);
    }

    ++maskIterator;
  }

  typedef  itk::ImageFileWriter<ImageType> WriterType;
  typename WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(filename);
  writer->SetInput(image);
  writer->Update();

}
Esempio n. 3
0
SEXP addNeighborhoodToImageHelper(
  SEXP r_antsimage,
  SEXP r_center,
  SEXP r_rad,
  SEXP r_vec)
{
  typedef typename ImageType::Pointer  ImagePointerType;
  const unsigned int ImageDimension = ImageType::ImageDimension;
  typedef float                        PixelType;
  typename ImageType::Pointer image =
    Rcpp::as< ImagePointerType >( r_antsimage );
  Rcpp::NumericVector center( r_center );
  Rcpp::NumericVector rad( r_rad );
  Rcpp::NumericVector intvec( r_vec );
  if ( center.size() != ImageDimension )
    Rcpp::stop("addNeighborhoodToImageHelper dim error.");
  typename itk::NeighborhoodIterator<ImageType>::SizeType nSize;
  typename ImageType::IndexType ind;
  ind.Fill( 0 );
  for ( unsigned int i=0; i<ImageDimension; i++ )
    {
    nSize[i] = rad[i];
    ind[i] = center[i]; // R coords to ITK
    }
  itk::NeighborhoodIterator<ImageType> nit( nSize, image,
    image->GetLargestPossibleRegion() ) ;
// for each location in nitSearch, compute the correlation
// of the intvec with the nit neighborhood
  nit.SetLocation( ind );
  for( unsigned int i = 0; i < nit.Size(); i++ )
    {
    typename ImageType::IndexType ind2 = nit.GetIndex(i);
    PixelType lval = image->GetPixel( ind2 );
    image->SetPixel( ind2, lval + intvec[i] );
    }
  return 0;
}