コード例 #1
0
ファイル: itk_benchmark.cpp プロジェクト: ddantas/visiongl
void saveFile(char* filename, ImageType* image)
{
    WriterType::Pointer writer = WriterType::New();
    writer->SetFileName(filename);
    writer->SetInput(image);
    writer->Update();
}
コード例 #2
0
void writeMesh(MeshType* mesh, const char* filename) {
    typedef itk::MeshFileWriter<MeshType> WriterType;
    WriterType::Pointer writer = WriterType::New();
    writer->SetInput(mesh);
    writer->SetFileName(filename);
    writer->Update();
}
コード例 #3
0
ファイル: NRRDTools.cpp プロジェクト: pip010/Cleaver2
void NRRDTools::saveNRRDFile(const cleaver::FloatField *field, const std::string &name) {
  auto dims = field->dataBounds().size;
  ImageType::Pointer img = ImageType::New();
  itk::Index<3> start; start.Fill(0);
  ImageType::SizeType size;
  size[0] = static_cast<size_t>(dims[0]);
  size[1] = static_cast<size_t>(dims[1]);
  size[2] = static_cast<size_t>(dims[2]);
  ImageType::RegionType region(start, size);
  img->SetRegions(region);
  img->Allocate();
  img->FillBuffer(0);
  for (size_t i = 0; i < dims[0]; i++) {
    for (size_t j = 0; j < dims[1]; j++) {
      for (size_t k = 0; k < dims[2]; k++) {
        ImageType::IndexType pixelIndex;
        pixelIndex[0] = i;
        pixelIndex[1] = j;
        pixelIndex[2] = k;
        auto data = ((cleaver::FloatField*)field)->data();
        img->SetPixel(pixelIndex, data[i + size[0] * j + size[0] * size[1] * k]);
      }
    }
  }
  WriterType::Pointer write = WriterType::New();
  write->SetFileName(name + ((name.find_first_of(".nrrd") == std::string::npos) ? ".nrrd" : ""));
  write->SetInput(img);
  write->Update();
}
コード例 #4
0
void writeBinaryImage(BinaryImageType* image, const char* filename) {
    typedef itk::ImageFileWriter<BinaryImageType> WriterType;
    WriterType::Pointer writer = WriterType::New();
    writer->SetInput(image);
    writer->SetFileName(filename);
    writer->Update();
}
コード例 #5
0
ファイル: itkbasics.cpp プロジェクト: hmeyer/myLibs
void writeLabelImage( LabeledImageType::Pointer image, const std::string &fname) {

	try {
		ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New();
		colormapper->SetInput( image );
		colormapper->Update();
		RGBImageType::ConstPointer colorImage = colormapper->GetOutput();
		colormapper = NULL;

		typedef itk::Image< RGBPixelType, 2 > OutputImage2DType;
		typedef itk::ImageSeriesWriter< RGBImageType, OutputImage2DType > WriterType;
		WriterType::Pointer writer = WriterType::New();
		typedef itk::NumericSeriesFileNames NamesGeneratorType;
		NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();

		nameGenerator->SetSeriesFormat( fname.c_str() );
		nameGenerator->SetStartIndex( 1 );
		nameGenerator->SetEndIndex( colorImage->GetBufferedRegion().GetSize()[2] );
		writer->SetFileNames( nameGenerator->GetFileNames() );
		writer->SetInput( colorImage );
		writer->Update();

	} catch( itk::ExceptionObject & exp ) {
		std::cerr << "Exception caught !" << std::endl;
		std::cerr << exp << std::endl;
	}

}
void LidarSegmentationWidget::on_actionSaveSegmentation_triggered()
{
  // Ask the user for a filename to save the segment mask image to

  QString fileName = QFileDialog::getSaveFileName(this,
    "Save Segment Mask Image", ".", "PNG Files (*.png)");

  if(fileName.isEmpty())
  {
    return;
  }
  // Write the file (object is white)
  typedef  itk::ImageFileWriter<Mask> WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(fileName.toStdString());
  writer->SetInput(this->GraphCut.GetSegmentMask());
  writer->Update();
  
  /*
  // Write the inverted file (object is black)
  Mask::Pointer inverted = Mask::New();
  Helpers::InvertBinaryImage(this->GraphCut.GetSegmentMask(), inverted);
  
  //typedef  itk::ImageFileWriter<ImageAdaptorType> WriterType;
  typedef  itk::ImageFileWriter<Mask> WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(fileName.toStdString());
  writer->SetInput(inverted);
  writer->Update();
  */
}
void InnerWidget::actionSave_Segmentation_triggered()
{
  // Ask the user for a filename to save the segment mask image to

  QString fileName = QFileDialog::getSaveFileName(this,
    tr("Save Segment Mask Image"), "/home/doriad", tr("Image Files (*.png *.bmp)"));
/*
  // Convert the image from a 1D vector image to an unsigned char image
  typedef itk::CastImageFilter< GrayscaleImageType,
                                itk::Image<itk::CovariantVector<unsigned char, 1>, 2 > > CastFilterType;
  CastFilterType::Pointer castFilter = CastFilterType::New();
  castFilter->SetInput(this->GraphCut->GetSegmentMask());

  typedef itk::NthElementImageAdaptor< itk::Image<itk:: CovariantVector<unsigned char, 1>, 2 >,
    unsigned char> ImageAdaptorType;

  ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
  adaptor->SelectNthElement(0);
  adaptor->SetImage(castFilter->GetOutput());
*/
  // Write the file
  //typedef  itk::ImageFileWriter< ImageAdaptorType > WriterType;
  typedef  itk::ImageFileWriter<Mask> WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(fileName.toStdString());
  //writer->SetInput(adaptor);
  writer->SetInput(this->GraphCut->GetSegmentMask());
  writer->Update();

}
コード例 #8
0
int main(int argc, char *argv[])
{
  // Verify arguments
  if(argc < 6)
    {
    std::cerr << "Required: outputFilename sizeX sizeY components value" << std::endl;
    return EXIT_FAILURE;
    }

  // Parse arguments
  std::string outputFilename = argv[1];

  std::stringstream ss;
  ss << argv[2] << " " << argv[3] << " " << argv[4];

  itk::Size<2> size = {{0,0}};
  unsigned int components = 0;
  float value = 0.0f;
  ss >> size[0] >> size[1] >> components >> value;


  // Output arguments
  std::cout << "outputFilename " << outputFilename << std::endl;
  std::cout << "size " << size << std::endl;
  std::cout << "value " << value << std::endl;

  ImageType::Pointer image = ImageType::New();
  itk::Index<2> index = {{0,0}};

  itk::ImageRegion<2> region(index, size);

  image->SetRegions(region);
  image->SetNumberOfComponentsPerPixel(components);
  image->Allocate();

  typename itk::ImageRegionIterator<ImageType> imageIterator(image, image->GetLargestPossibleRegion());

  ImageType::PixelType pixel;
  pixel.SetSize(components);
  pixel.Fill(value);
  
  while(!imageIterator.IsAtEnd())
    {
    imageIterator.Set(pixel);

    ++imageIterator;
    }

  // Write the result
  typedef  itk::ImageFileWriter<ImageType> WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(outputFilename);
  writer->SetInput(image);
  writer->Update();

  return EXIT_SUCCESS;
}
コード例 #9
0
ファイル: treshhold.cpp プロジェクト: ihsanarifr/TugasKuliah
int main( int argc, char * argv[] )
{
  if( argc < 7 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << std::endl;
    std::cerr << " <InputImage> <OutputImage> <LowerThreshold>";
    std::cerr << " <UpperThreshold> <OutsideValue> <InsideValue>"
              << std::endl;
    return EXIT_FAILURE;
    }

  const unsigned int Dimension = 2;
  typedef  unsigned char  PixelType;

  const char * InputImage = argv[1];
  const char * OutputImage = argv[2];

  const PixelType LowerThreshold = static_cast<PixelType>(atoi( argv[3] ) );
  const PixelType UpperThreshold = static_cast<PixelType>(atoi( argv[4] ) );
  const PixelType OutsideValue = static_cast<PixelType>(atoi( argv[5] ) );
  const PixelType InsideValue = static_cast<PixelType>(atoi( argv[6] ) );

  typedef itk::Image< PixelType, Dimension >  ImageType;

  typedef itk::ImageFileReader< ImageType > ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( InputImage );

  typedef itk::BinaryThresholdImageFilter< ImageType, ImageType >
    FilterType;
  FilterType::Pointer filter = FilterType::New();
  filter->SetInput( reader->GetOutput() );
  filter->SetLowerThreshold( LowerThreshold );
  filter->SetUpperThreshold( UpperThreshold );
  filter->SetOutsideValue( OutsideValue );
  filter->SetInsideValue( InsideValue );

  typedef itk::ImageFileWriter< ImageType >  WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName( OutputImage );
  writer->SetInput( filter->GetOutput() );

  try
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & e )
    {
    std::cerr << "Error: " << e << std::endl;
    return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;
}
コード例 #10
0
void MriWatcherGUI::Combine()
{
  QString m_filename = QFileDialog::getSaveFileName(
      this,
      tr("Save As"),
      QDir::currentPath(),
      tr("*.gipl *.hdr *.mha *.mhd") );

  if( m_filename.isEmpty() )
    {
    g_combine->setDown(false);
    return;
    }

  if( m_filename.lastIndexOf(".") == -1 )
    {
    m_filename += ".gipl";
    }

  int xc; int yc; int zc;
  m_imagemanager.GetCrosshair(&xc, &yc, &zc);

  ImageType::Pointer m_newimage =
    CreateNewImage(m_imagesize[0], m_imagesize[1], m_numberofimages, m_imagespacing[0], m_imagespacing[1],
                   m_imagespacing[2]);
  IteratorType m_itnewimage(m_newimage, m_newimage->GetLargestPossibleRegion() );
  m_itnewimage.GoToBegin();
  for( int z = 0; z < m_numberofimages; z++ )
    {
    ImageType::Pointer m_image = m_imageframelist[z]->g_imageframe->GetInputImage2();
    IteratorType       m_itimage(m_image, m_image->GetLargestPossibleRegion() );
    m_itimage.GoToBegin();
    for( unsigned int i = 0; i < zc * m_imagesize[0] * m_imagesize[1]; i++ )
      {
      ++m_itimage;
      }
    for( unsigned int y = 0; y < m_imagesize[0]; y++ )
      {
      for( unsigned int x = 0; x < m_imagesize[1]; x++ )
        {
        m_itnewimage.Set(m_itimage.Get() );
        ++m_itimage;
        ++m_itnewimage;
        }
      }
    }

  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(m_filename.toLatin1().constData() );
  writer->SetInput(m_newimage);
  writer->Update();

  g_combine->setDown(false);
}
コード例 #11
0
int main (int argc, char *argv[])
{
  // Verify arguments
  if(argc != 3)
    {
    std::cerr << "Required arguments: InputFileName OutputFileName" << std::endl;
    return EXIT_FAILURE;
    }

  // Parse arguments
  std::string inputFileName = argv[1];
  std::string outputFileName = argv[2];

  // Output arguments
  std::cout << "Input image: " << inputFileName << std::endl;
  std::cout << "Output image: " << outputFileName << std::endl;
  
  //typedef itk::Image<unsigned char, 2> ImageType;
  
  typedef itk::RGBPixel<float> RGBFloatPixelType; // We must use float pixels so that the averaging operation does not overflow
  typedef itk::Image<RGBFloatPixelType> RGBFloatImageType;
  
  typedef itk::ImageFileReader<RGBFloatImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(inputFileName);
  reader->Update();
  
  SmallHoleFiller<RGBFloatImageType> smallHoleFiller;
  smallHoleFiller.SetImage(reader->GetOutput());
  
  RGBFloatImageType::PixelType green;
  green.SetRed(0);
  green.SetGreen(255);
  green.SetBlue(0);
  smallHoleFiller.SetHolePixel(green);

  smallHoleFiller.GenerateMaskFromImage();
  smallHoleFiller.Fill();
  
  typedef itk::RGBPixel<unsigned char> RGBUCharPixelType;
  typedef itk::Image<RGBUCharPixelType> RGBUCharImageType;
  typedef itk::CastImageFilter<RGBFloatImageType, RGBUCharImageType> CastFilterType;
  CastFilterType::Pointer castFilter = CastFilterType::New();
  castFilter->SetInput(smallHoleFiller.GetOutput());
  castFilter->Update();
  
  typedef  itk::ImageFileWriter< RGBUCharImageType  > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(outputFileName);
  writer->SetInput(castFilter->GetOutput());
  writer->Update();
    
  return EXIT_SUCCESS;
}
コード例 #12
0
// ------------------------------------------------------------------------
void DicomParser::writeSeries(const DicomSeries &series, const QString &outputFolder)
{
	// create the series name
	QString name = QString::fromStdString(series.description);
	name.replace(" ","_");
	name += "_" + QString::number(series.images.front().seriesNumber);
	name += ".nrrd";
	
	QDir path(outputFolder);
	QString fullPath = path.absoluteFilePath(name);
	

	std::vector<DicomImage> images = series.images;
	std::sort(images.begin(), images.end());

	// write and build the output images 
	typedef itk::Image<unsigned short, 3> ImageType;
	typedef itk::Image<unsigned short, 4> OutputImageType;
	typedef itk::ImageFileReader<ImageType> ReaderType;
	typedef itk::JoinSeriesImageFilter<ImageType, OutputImageType> JoinerType;

	JoinerType::Pointer joiner = JoinerType::New();
	ImageType::Pointer orig;
	for(unsigned int i = 0; i < images.size(); i++)
	{
		ReaderType::Pointer reader = ReaderType::New();
		reader->SetFileName(images[i].filename);
		std::cout << images[i].filename << std::endl;
		reader->SetImageIO(itk::GDCMImageIO::New());
		reader->Update();

		ImageType::Pointer im = reader->GetOutput();
		if(i == 0) orig = im;


		im->SetOrigin(orig->GetOrigin());
		im->SetDirection(orig->GetDirection());
		im->SetSpacing(orig->GetSpacing());

		joiner->SetInput(i, reader->GetOutput());
	}


	std::cout << joiner->GetOutput()->GetDirection() << std::endl;


	typedef itk::ImageFileWriter<OutputImageType> WriterType;
	WriterType::Pointer writer = WriterType::New();
	writer->SetInput(joiner->GetOutput());
	writer->SetFileName(fullPath.toStdString());
	writer->SetImageIO(itk::NrrdImageIO::New());
	writer->Update();

}
コード例 #13
0
ファイル: main.cpp プロジェクト: JumperWang/farsight-clone
int main(int argc, char* argv[]) 
{
	if( argc < 2 )
	{
		std::cerr<<argv[0]<<" InputImage"<<std::endl;
		return EXIT_FAILURE;
	}

	typedef RGBImageType InputImageType;
	typedef RGBImageType2D OutputImageType;

	typedef itk::ImageFileReader< InputImageType >  ReaderType;
	//typedef itk::ImageFileReader< UCharImageType >  ReaderType;
	ReaderType::Pointer reader = ReaderType::New();
	reader->SetFileName( argv[1] );
	std::cout<<argv[1]<<std::endl;
	try
	{
		reader->Update();
	}
	catch( itk::ExceptionObject & excep )
	{
		std::cerr << "Exception caught !" << std::endl;
		std::cerr << excep << std::endl;
	}
	InputImageType::Pointer in = reader->GetOutput();

	Focus *f = new Focus( in );
	f->SetRadius(10);
	//std::vector<float> vars = f->FindVariance(1.93,4.57,300);
	f->MakeVarianceImage();

	//OutputImageType::Pointer p = f->MakeProjection();
	OutputImageType::Pointer p = f->MakeProjectionColor();

	delete f;

	typedef itk::ImageFileWriter< OutputImageType >  WriterType;
	WriterType::Pointer writer = WriterType::New();
	writer->SetFileName( "best.tif" );
	writer->SetInput( p );
	try
	{
		writer->Update();
	}
	catch( itk::ExceptionObject & excep )
	{
		std::cerr << "Exception caught !" << std::endl;
		std::cerr << excep << std::endl;
	}

	std::cerr << "PRESS ENTER TO EXIT\n";
	getchar();
}
コード例 #14
0
int main(int argc, char* *argv)
{


	     GetPot   cl(argc, argv);
	     if( cl.size() == 1 || cl.search(2, "--help", "-h") )
	      {
	          std::cout << "Not enough arguments" << std::endl;
	          return -1;
	      }

	const string image_n = cl.follow("NoFile", 1, "-i");

	typedef itk::Image<float, 3> ImageType;
	typedef itk::ImageFileReader<ImageType> ReaderType;

	ReaderType::Pointer reader = ReaderType::New();

	reader->SetFileName(image_n.c_str());
	reader-> Update();
	ImageType::Pointer image = reader->GetOutput();

 	typedef itk::ImageRegionIterator<ImageType> ImageIterator;
	ImageIterator it(image, image->GetLargestPossibleRegion());

	for (it.GoToBegin(); !it.IsAtEnd(); ++it)
	{
	 	if (it.Get() < -5 )
		{
		 it.Set(1.0);
		  std::cout << it.GetIndex() << std::endl;
		}
		else if (it.Get() > 5 )
		{
		 it.Set(1.0);
		  std::cout << it.GetIndex() << std::endl;
		}
		else 
		{
			it.Set(0.0);
		}
	}	

	typedef itk::ImageFileWriter<ImageType> WriterType;
	WriterType::Pointer writer = WriterType::New();
	writer->SetFileName("Trace_mask.nii.gz");
	writer->SetInput(image);
	writer->Update();

	return 0;
}
コード例 #15
0
ファイル: Main.cpp プロジェクト: poquirion/spinalcordtoolbox
ImageType::Pointer vesselnessFilter(ImageType::Pointer im, float typeImageFactor_, double alpha, double beta, double gamma, double sigmaMinimum, double sigmaMaximum, unsigned int numberOfSigmaSteps, double sigmaDistance)
{
    typedef itk::ImageDuplicator< ImageType > DuplicatorTypeIm;
    DuplicatorTypeIm::Pointer duplicator = DuplicatorTypeIm::New();
    duplicator->SetInputImage(im);
    duplicator->Update();
    ImageType::Pointer clonedImage = duplicator->GetOutput();

    typedef itk::SymmetricSecondRankTensor< double, 3 > HessianPixelType;
    typedef itk::Image< HessianPixelType, 3 >           HessianImageType;
    typedef itk::HessianToObjectnessMeasureImageFilter< HessianImageType, ImageType > ObjectnessFilterType;
    ObjectnessFilterType::Pointer objectnessFilter = ObjectnessFilterType::New();
    objectnessFilter->SetBrightObject( 1-typeImageFactor_ );
    objectnessFilter->SetScaleObjectnessMeasure( false );
    objectnessFilter->SetAlpha( alpha );
    objectnessFilter->SetBeta( beta );
    objectnessFilter->SetGamma( gamma );
    objectnessFilter->SetObjectDimension(1);

    typedef itk::MultiScaleHessianBasedMeasureImageFilter< ImageType, HessianImageType, ImageType > MultiScaleEnhancementFilterType;
    MultiScaleEnhancementFilterType::Pointer multiScaleEnhancementFilter =
        MultiScaleEnhancementFilterType::New();
    multiScaleEnhancementFilter->SetInput( clonedImage );
    multiScaleEnhancementFilter->SetHessianToMeasureFilter( objectnessFilter );
    multiScaleEnhancementFilter->SetSigmaStepMethodToLogarithmic();
    multiScaleEnhancementFilter->SetSigmaMinimum( sigmaMinimum );
    multiScaleEnhancementFilter->SetSigmaMaximum( sigmaMaximum );
    multiScaleEnhancementFilter->SetNumberOfSigmaSteps( numberOfSigmaSteps );
    multiScaleEnhancementFilter->Update();

    ImageType::Pointer vesselnessImage = multiScaleEnhancementFilter->GetOutput();

    WriterType::Pointer writerVesselNess = WriterType::New();
    itk::NiftiImageIO::Pointer ioV = itk::NiftiImageIO::New();
    writerVesselNess->SetImageIO(ioV);
    writerVesselNess->SetInput( vesselnessImage );
    writerVesselNess->SetFileName("imageVesselNessFilter.nii.gz");
    try {
        writerVesselNess->Update();
    }
    catch( itk::ExceptionObject & e )
    {
        cout << "Exception thrown ! " << endl;
        cout << "An error ocurred during Writing 1" << endl;
        cout << "Location    = " << e.GetLocation()    << endl;
        cout << "Description = " << e.GetDescription() << endl;
    }

    return vesselnessImage;
}
コード例 #16
0
int main(int argc, char *argv[])
{
  if(argc < 3)
    {
    std::cerr << "Required: inputFilename outputFilename" << std::endl;
    return EXIT_FAILURE;
    }

  std::string inputFilename = argv[1];
  std::string outputFilename = argv[2];

  std::cout << "inputFilename " << inputFilename << std::endl;
  std::cout << "outputFilename " << outputFilename << std::endl;

  typedef itk::ImageFileReader<ImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(inputFilename);
  reader->Update();

  typedef itk::DerivativeImageFilter<ImageType, ImageType> DerivativeImageFilterType;
  DerivativeImageFilterType::Pointer xDerivativeFilter = DerivativeImageFilterType::New();
  xDerivativeFilter->SetDirection(0);
  xDerivativeFilter->SetOrder(1);
  xDerivativeFilter->SetInput(reader->GetOutput());
  xDerivativeFilter->Update();

  DerivativeImageFilterType::Pointer yDerivativeFilter = DerivativeImageFilterType::New();
  yDerivativeFilter->SetOrder(1);
  yDerivativeFilter->SetDirection(1);
  yDerivativeFilter->SetInput(reader->GetOutput());
  yDerivativeFilter->Update();

  typedef itk::ComposeImageFilter<ImageType, GradientImageType> ComposeImageFilterType;
  ComposeImageFilterType::Pointer composeFilter = ComposeImageFilterType::New();
  composeFilter->SetInput1(xDerivativeFilter->GetOutput());
  composeFilter->SetInput2(yDerivativeFilter->GetOutput());
  composeFilter->Update();

  typedef  itk::ImageFileWriter<GradientImageType> WriterType;
  WriterType::Pointer xWriter = WriterType::New();
  xWriter->SetFileName(outputFilename);
  xWriter->SetInput(composeFilter->GetOutput());
  xWriter->Update();

  return EXIT_SUCCESS;
}
コード例 #17
0
ファイル: snapshot.cpp プロジェクト: JDonner/gabbleduck
void write_snapshot_image(string fname)
{
   WriterType::Pointer writer = WriterType::New();

   writer->SetFileName(fname.c_str());

   writer->SetInput(g_snapshot_image);
   try {
      writer->Update();
      give_wide_permissions(fname.c_str());
   }
   catch (itk::ExceptionObject &err) {
      std::cout << "ExceptionObject caught !" << std::endl;
      std::cout << err << std::endl;
      assert(false);
   }
}
コード例 #18
0
ファイル: Cell.cpp プロジェクト: JumperWang/farsight-clone
void Cell::WriteImage(const std::string & filename, const itk::Image< double , 3 >::Pointer & image)
{
	std::cout << "Writing " << filename << std::endl;
	typedef itk::ImageFileWriter< itk::Image< double, 3 > > WriterType;
	WriterType::Pointer writer = WriterType::New();
	writer->SetInput(image);	//image is from function parameters!
	writer->SetFileName(filename);
	try
	{
		writer->Update();
		//ftk::TimeStampOverflowSafeUpdate( writer.GetPointer() );
	}
	catch (itk::ExceptionObject &err)
	{
		std::cerr << "writer Exception: " << filename << " " << err << std::endl;
		std::cerr << writer << std::endl;
	}
}
コード例 #19
0
void ScaleSpaceExplorer::SavePlateness(){
	QFileDialog dialog;
	dialog.setAcceptMode(QFileDialog::AcceptSave);
	dialog.setNameFilter("Image files (*.ome.tif)");
	dialog.setFileMode(QFileDialog::AnyFile);
	if(dialog.exec()){
			QString fileName = dialog.selectedFiles().first();

			typedef itk::ImageFileWriter<VertexnessImageType> WriterType;

			WriterType::Pointer writer = WriterType::New();
			itk::SCIFIOImageIO::Pointer iodriver = itk::SCIFIOImageIO::New();
			writer->SetImageIO(iodriver);
			writer->SetFileName(fileName.toStdString());
			writer->SetInput(m_PlatenessImages[m_CurrentPlateness]);
			writer->Update();

	}
}
コード例 #20
0
ファイル: dhHistogram.cpp プロジェクト: Pandolph/farsight
void Histogram::save_as(const char * fname)
{
	if(!histImage)
		return;

	typedef itk::Image< unsigned char, 3 > UcharImageType;
	typedef itk::RescaleIntensityImageFilter< HistImageType, UcharImageType > RescaleFlUcType;
	RescaleFlUcType::Pointer rescale = RescaleFlUcType::New();
	rescale->SetOutputMaximum( 255 );
	rescale->SetOutputMinimum( 0 );
	rescale->SetInput( histImage );
	rescale->Update();

	typedef itk::ImageFileWriter< UcharImageType > WriterType;
	WriterType::Pointer writer = WriterType::New();
	writer->SetFileName( fname );
	writer->SetInput( rescale->GetOutput() );
	writer->Update();
}
コード例 #21
0
ファイル: segmentation.cpp プロジェクト: zlsunsuda/QT-DEMO
void segmentation::on_filterButton_clicked()
{
    typedef    float    InputPixelType;
    typedef    float    OutputPixelType;
    typedef itk::Image< InputPixelType,  3 >   InputImageType;
    typedef itk::Image< OutputPixelType, 3>   OutputImageType;
    typedef itk::ImageFileReader< InputImageType >  ReaderType;
    typedef itk::CurvatureAnisotropicDiffusionImageFilter<
        InputImageType, OutputImageType >  FilterType;
    FilterType::Pointer filter = FilterType::New();
    ReaderType::Pointer reader = ReaderType::New();
    reader->SetFileName( inputFileName);
    filter->SetInput( reader->GetOutput() );
    const unsigned int numberOfIterations = 3;//5
    const double       timeStep =  0.0625; //timeStep=0.125(for 2D), 0.0625(for 3D)
    const double       conductance = 3;//3
    filter->SetNumberOfIterations( numberOfIterations );
    filter->SetTimeStep( timeStep );
    filter->SetConductanceParameter( conductance );
    filter->Update();//time-costing
    typedef unsigned short                        WritePixelType;//unsigned char
    typedef itk::Image< WritePixelType, 3 >        WriteImageType;
    typedef itk::RescaleIntensityImageFilter<
        OutputImageType, WriteImageType > RescaleFilterType;
    RescaleFilterType::Pointer rescaler = RescaleFilterType::New();
    rescaler->SetOutputMinimum(   0 );
    rescaler->SetOutputMaximum( 65535 );//255 for CNV,  for PED
    typedef itk::ImageFileWriter< WriteImageType >  WriterType;
    WriterType::Pointer writer = WriterType::New();
    //文件前缀名
    filePrefix = inputFileName;//char* to string
    filePrefix = filePrefix.substr(0, filePrefix.length() - 4);
    filePrefix = filePrefix + "_filter.mhd";
    strcpy(outputFileName, filePrefix.c_str());//string to char*
    writer->SetFileName(outputFileName);
    rescaler->SetInput( filter->GetOutput() );
    writer->SetInput( rescaler->GetOutput() );
    writer->Update();

    //将结果图返回主窗口显示
    emit returnOutputFileName(outputFileName);//发出信号
}
コード例 #22
0
// ------------------------------------------------------------------------
void OpenCVValve::ConvertImage(const ImageType::Pointer &input, MatPtr &mat)
{
	// cast the image to uchar 
	typedef itk::Image<unsigned char, 2> OutputImageType;
	typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> CasterType;
	CasterType::Pointer caster = CasterType::New();
	caster->SetOutputMaximum(255);
	caster->SetOutputMinimum(0);
	caster->SetInput(input);
	caster->Update();


	OutputImageType::Pointer output = caster->GetOutput();


	typedef itk::ImageFileWriter<OutputImageType> WriterType;
	WriterType::Pointer writer = WriterType::New();
	writer->SetImageIO(itk::PNGImageIO::New());
	writer->SetInput(output);
	writer->SetFileName("test.png");
	writer->Update();



	ImageType::SizeType size = input->GetLargestPossibleRegion().GetSize();
	unsigned int rows = size[1];
	unsigned int cols = size[0];

	mat = new MatType(rows,cols, CV_8UC1);


	itk::ImageRegionConstIterator<OutputImageType> it(output, output->GetLargestPossibleRegion());
	it.GoToBegin();
	while(!it.IsAtEnd())
	{
		OutputImageType::IndexType index = it.GetIndex();
		unsigned char val = it.Get();
		mat->at<unsigned char>(cv::Point(index[0], index[1])) = val;
		++it;
	}
}
コード例 #23
0
int main(int argc,char ** argv){

	typedef itk::Image<float,3> ImageType;
	typedef itk::Image<float,2> SliceType;

	typedef itk::ImageFileReader<ImageType> ReaderType;
	typedef itk::ImageFileWriter<SliceType> WriterType;

	typedef itk::BoundedReciprocalImageFilter<ImageType,ImageType> BoundedReciprocalType;
	BoundedReciprocalType::Pointer boundedReciprocal = BoundedReciprocalType::New();


	typedef ttt::AdvectiveDiffusion2DIterationImageFilter<SliceType,SliceType> AdvectionDiffusion2DIterationType;

	ReaderType::Pointer reader = ReaderType::New();
	reader->SetFileName(argv[1]);
	reader->UpdateOutputInformation();


	typedef itk::ExtractImageFilter<ImageType,SliceType> ExtractorType;

	ExtractorType::Pointer extractor = ExtractorType::New();

	ImageType::RegionType extractionRegion = reader->GetOutput()->GetLargestPossibleRegion();
	extractionRegion.SetSize(2,0);

	boundedReciprocal->SetInput(reader->GetOutput());
	extractor->SetInput(boundedReciprocal->GetOutput());
	extractor->SetExtractionRegion(extractionRegion);
	extractor->SetDirectionCollapseToIdentity();

	AdvectionDiffusion2DIterationType::Pointer advectionDiffusionIteration =AdvectionDiffusion2DIterationType::New();

	advectionDiffusionIteration->SetInput(extractor->GetOutput());
	advectionDiffusionIteration->SetNumberOfThreads(1.0);


	WriterType::Pointer sliceWriter = WriterType::New();
	sliceWriter->SetInput(extractor->GetOutput());
	sliceWriter->SetFileName(argv[2]);
	sliceWriter->Update();


	WriterType::Pointer writer = WriterType::New();
	writer->SetFileName(argv[3]);

	writer->SetInput(advectionDiffusionIteration->GetOutput());
	writer->Update();

}
void LidarSegmentationWidget::on_action_Selections_SaveAsImage_triggered()
{
  QString filename = QFileDialog::getSaveFileName(this,
     "Save Image", ".", "PNG Files (*.png)");

  if(filename.isEmpty())
    {
    return;
    }

  RGBImageType::Pointer selectionsImage = RGBImageType::New();
  
  selectionsImage->SetRegions(this->ImageRegion);
  selectionsImage->Allocate();
  
  RGBPixelType whitePixel;
  whitePixel.SetRed(255);
  whitePixel.SetGreen(255);
  whitePixel.SetBlue(255);
  
  selectionsImage->FillBuffer(whitePixel);
  
  RGBPixelType greenPixel;
  greenPixel.SetRed(0);
  greenPixel.SetGreen(255);
  greenPixel.SetBlue(0);
  ITKHelpers::SetPixels(selectionsImage.GetPointer(), this->Sources, greenPixel);
  
  RGBPixelType redPixel;
  redPixel.SetRed(255);
  redPixel.SetGreen(0);
  redPixel.SetBlue(0);
  ITKHelpers::SetPixels(selectionsImage.GetPointer(), this->Sinks, redPixel);

  typedef  itk::ImageFileWriter< RGBImageType  > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(filename.toStdString());
  writer->SetInput(selectionsImage);
  writer->Update();
}
コード例 #25
0
int main(int argc, char* argv[])
{
  typedef itk::ImageFileReader<ImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(argv[1]);
  reader->Update();
  
  typedef itk::SLICSegmentation<ImageType, LabelImageType> SLICSegmentationType;
  SLICSegmentationType::Pointer slicSegmentation = SLICSegmentationType::New();
  slicSegmentation->SetNumberOfSuperPixels(200);
  slicSegmentation->SetSpatialDistanceWeight(5.0);
  slicSegmentation->SetInput(reader->GetOutput());
  slicSegmentation->Update();
  
  typedef itk::ImageFileWriter<LabelImageType> WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(argv[2]);
  writer->SetInput(slicSegmentation->GetOutput());
  writer->Update();

  return EXIT_SUCCESS;
}
コード例 #26
0
ファイル: ResetImage.cpp プロジェクト: daviddoria/ITK_OneShot
int main(int argc, char *argv[])
{
  if(argc < 3)
    {
    std::cerr << "Required: inputFilename outputFilename" << std::endl;
    return EXIT_FAILURE;
    }

  std::string inputFilename = argv[1];
  std::string outputFilename = argv[2];

  typedef itk::ImageFileReader<ImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(inputFilename.c_str());
  reader->Update();

  ImageType::Pointer output = ImageType::New();
  output->SetNumberOfComponentsPerPixel(reader->GetOutput()->GetNumberOfComponentsPerPixel());
  output->SetRegions(reader->GetOutput()->GetLargestPossibleRegion());
  output->Allocate();
  
  itk::ImageRegionIterator<ImageType> outputIterator(output, output->GetLargestPossibleRegion());

  while(!outputIterator.IsAtEnd())
    {
    outputIterator.Set(reader->GetOutput()->GetPixel(outputIterator.GetIndex()));

    ++outputIterator;
    }

  typedef  itk::ImageFileWriter<ImageType> WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(outputFilename);
  writer->SetInput(output);
  writer->Update();

  return EXIT_SUCCESS;
}
コード例 #27
0
int main(int argc, char* argv[])
{
  typedef itk::ImageFileReader<ImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(argv[1]);
  reader->Update();
  
  typedef itk::SuperPixelSegmentation<ImageType, LabelImageType> SuperPixelSegmentationType;
  SuperPixelSegmentationType::Pointer superPixelSegmentation = SuperPixelSegmentationType::New();
  superPixelSegmentation->SetSigma(.5);
  superPixelSegmentation->SetK(500);
  superPixelSegmentation->SetMinSize(50);
  superPixelSegmentation->SetInput(reader->GetOutput());
  superPixelSegmentation->Update();
  
  typedef itk::ImageFileWriter<LabelImageType> WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(argv[2]);
  writer->SetInput(superPixelSegmentation->GetOutput());
  writer->Update();

  return EXIT_SUCCESS;
}
コード例 #28
0
int main(int argc, char** argv) {
	if(argc != 3){
		std::cout << "Usage: Test2DImage inputFilename outputFilename"; 
		return 1;
	}
	typedef signed int InputPixelType;
	const unsigned int Dimension = 2;
	typedef itk::Image<InputPixelType, Dimension> InputImageType;
	typedef itk::RGBPixel<unsigned char> RGBPixelType;
	typedef itk::Image<RGBPixelType, 2> RGBImageType;
	typedef itk::ImageFileReader<InputImageType> ReaderType;
	typedef itk::ImageFileWriter<RGBImageType> WriterType;
	typedef itk::GDCMImageIO ImageIOType;
	typedef itk::GradientAnisotropicDiffusionImageFilter<InputImageType,
	InputImageType> DiffusionFilterType;
	typedef itk::GradientMagnitudeImageFilter<InputImageType, InputImageType>
			GradientMagnitudeFilterType;
	typedef itk::Functor::ScalarToRGBPixelFunctor<int> ColorMapFunctorType;
	typedef itk::UnaryFunctorImageFilter<InputImageType,
	RGBImageType, ColorMapFunctorType> ColorMapFilterType;
	typedef itk::JPEGImageIO JImageIOType;

	ReaderType::Pointer reader = ReaderType::New();
	WriterType::Pointer writer = WriterType::New();
	ImageIOType::Pointer GDCMImageIO = ImageIOType::New();
	JImageIOType::Pointer JPEGImageIO = JImageIOType::New();
	ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New();

	reader->SetFileName(argv[1]);
	reader->SetImageIO(GDCMImageIO);

	try {
		reader->Update();
	}
	catch (itk::ExceptionObject & e) {
		std::cerr << "exception in file reader " << std::endl;
		std::cerr << e << std::endl;
		return 1;
	}
	DiffusionFilterType::Pointer diffusion = DiffusionFilterType::New();
	diffusion->SetNumberOfIterations(1);
	diffusion->SetConductanceParameter(4);
	diffusion->SetTimeStep(0.125);
	GradientMagnitudeFilterType::Pointer gradient = GradientMagnitudeFilterType::New();
	diffusion->SetInput(reader->GetOutput());
	gradient->SetInput(diffusion->GetOutput());
	gradient->Update();
	MyWatershedSegmenter<InputImageType> watershed(gradient->GetOutput());
	watershed.buildLowerCompleteImage();
	watershed.buildLabeledImage();
	colormapper->SetInput(watershed.returnFinalImage());
	writer->SetInput(colormapper->GetOutput());
	writer->UseInputMetaDataDictionaryOff();
	writer->SetImageIO(JPEGImageIO);
	writer->SetFileName(argv[2]);
	writer->Update();
}
コード例 #29
0
ファイル: ClampImage.cpp プロジェクト: daviddoria/ITK_OneShot
int main(int argc, char *argv[])
{
  // Verify arguments
  if(argc < 3)
    {
    std::cerr << "Required: inputFilename outputFilename" << std::endl;
    return EXIT_FAILURE;
    }

  // Parse arguments
  std::string inputFilename = argv[1];
  std::string outputFilename = argv[2];

  // Output arguments
  std::cout << "inputFilename " << inputFilename << std::endl;
  std::cout << "outputFilename " << outputFilename << std::endl;

  // Read file
  typedef itk::ImageFileReader<ImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(inputFilename);
  reader->Update();

  typedef itk::ClampImageFilter< ImageType, ImageType > ClampFilterType;
  ClampFilterType::Pointer clampFilter = ClampFilterType::New();
  clampFilter->SetInput(reader->GetOutput());
  clampFilter->Update();

  // Write the result
  typedef  itk::ImageFileWriter<ImageType> WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(outputFilename);
  writer->SetInput(clampFilter->GetOutput());
  writer->Update();

  return EXIT_SUCCESS;
}
コード例 #30
0
ファイル: SRmain.cpp プロジェクト: Slicer/BRAINSTools
int main(int argc, char *argv[]) {
  if (argc != 4) {
    std::cout << "ERROR: Incorrrect number of arguments <Intensity_LR> <edgement_HR> <output>" << std::endl;
  }
  FFTWInit(""); //Just use the default in the home account
  itk::TimeProbe tp;
  tp.Start();
  typedef itk::ImageFileReader<FloatImageType> ReaderType;
  typedef itk::ImageFileWriter<FloatImageType> WriterType;

  const std::string edgeFileName = argv[2];
  ReaderType::Pointer edgeReader = ReaderType::New();
  edgeReader->SetFileName(edgeFileName);
  edgeReader->Update();
  FloatImageType::Pointer highResEdgeImage = edgeReader->GetOutput();

  const std::string lriFileName = argv[1];
  ReaderType::Pointer intensityReader = ReaderType::New();
  intensityReader->SetFileName(lriFileName);
  intensityReader->Update();
  FloatImageType::Pointer lriImage = intensityReader->GetOutput();
  FloatImageType::Pointer X_lr = NormalizeDataComponent(lriImage);
  lriImage=nullptr;

  FloatImageType::Pointer SRImage = OpWeightedL2(X_lr, highResEdgeImage);

  const std::string hriFileName = argv[3];
  WriterType::Pointer hriWriter = WriterType::New();
  hriWriter->SetInput(SRImage);
  hriWriter->SetFileName(hriFileName);
  hriWriter->Update();

  tp.Stop();
  std::cout << tp.GetTotal() << tp.GetUnit() << std::endl;
  return EXIT_SUCCESS;
}