Пример #1
0
int main(int argc, char *argv[])
{
  std::string inputFileName = argv[1];
  std::string outputPrefix = argv[2];

  std::cout << "Input: " << inputFileName << std::endl;
  std::cout << "Output prefix: " << outputPrefix << std::endl;

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

  HelpersOutput::WriteVectorImageAsRGB(reader->GetOutput(), outputPrefix + "/Image.mha");

  WriteImagePixelsToRGBSpace(reader->GetOutput(), outputPrefix + "/ImageColors.vtp");

  WriteClusteredPixelsInRGBSpace(reader->GetOutput(), 20, outputPrefix + "/ImageColorsClustered.vtp");

  FloatVectorImageType::Pointer blurred = FloatVectorImageType::New();
  //float blurVariance = 2.0f; // almost no visible blurring
  //float blurVariance = 10.0f; // slight blurring of concrete
  float blurVariance = 30.0f;
  Helpers::AnisotropicBlurAllChannels<FloatVectorImageType>(reader->GetOutput(), blurred, blurVariance);

  HelpersOutput::WriteVectorImageAsRGB(blurred, outputPrefix + "/BlurredImage.mha");

  WriteImagePixelsToRGBSpace(blurred, outputPrefix + "/BlurredImageColors.vtp");

  WriteClusteredPixelsInRGBSpace(blurred, 20, outputPrefix + "/BlurredImageColorsClustered.vtp");

  return EXIT_SUCCESS;
}
Пример #2
0
void MriWatcherGUI::LoadOverlay(const QString& filename2)
{
  ReaderType::Pointer reader = ReaderType::New();
  QString             filename = filename2;

  filename.replace( QRegExp("\\"), "/" );
  reader->SetFileName( filename.toLatin1().constData() );
  try
    {
    reader->Update();
    }
  catch( itk::ExceptionObject & e )
    {
    // std::cerr << "Exception in file reader " << std::endl;
    // std::cerr << e << std::endl;
    QMessageBox::information( this, "MriWatcher", "Unable to load file:\n" + filename);
    return;
    }
  for( unsigned int i = 0; i < m_imageframelist.size(); i++ )
    {
    m_imageframelist[i]->g_imageframe->SetInputOverlay(reader->GetOutput() );
    m_originalimage = reader->GetOutput();
    if( m_originalimage.IsNotNull() )
      {
      m_imagemanager.SetSourceOverlay(m_originalimage);
      g_slice_slider->setEnabled(true);
      g_overlay_alpha_slider->setEnabled(true);
      }
    g_loadimg->setDown(false);
    g_loadoverlay->setDown(false);
    }
}
Пример #3
0
// ------------------------------------------------------------------------
void LoadImage(const std::string &filename, ImageType::Pointer &image)
{
	typedef itk::Image<unsigned short, 4> InImageType;
	typedef itk::ImageFileReader<InImageType> ReaderType;
	ReaderType::Pointer reader = ReaderType::New();
	reader->SetFileName(filename);
	reader->SetImageIO(itk::NrrdImageIO::New());
	reader->Update();


	typedef itk::ExtractImageFilter<InImageType, ImageType> ExtractorType;
	ExtractorType::Pointer extractor = ExtractorType::New();
	extractor->SetInput(reader->GetOutput());

	InImageType::RegionType exRegion = reader->GetOutput()->GetLargestPossibleRegion();
	InImageType::SizeType exSize = exRegion.GetSize();
	InImageType::IndexType exIndex = exRegion.GetIndex();

	exSize[3] = 0;
	exIndex[3] = 0;
	exRegion.SetSize(exSize);
	exRegion.SetIndex(exIndex);

	extractor->SetExtractionRegion(exRegion);
	extractor->SetDirectionCollapseToSubmatrix();
	extractor->Update();

	image = extractor->GetOutput();



}
Пример #4
0
bool itkDataSHImageReader::read (const QString &path)
{
    this->readInformation ( path );
	
    dtkDebug() << "Read with: " << this->description();

    if (medAbstractData *medData = dynamic_cast<medAbstractData*>(this->data()) ) {

        if (medData->identifier()=="itkDataSHImageDouble3") {
            typedef itk::VectorImage<double, 3> SHImageType;

            typedef itk::ImageFileReader<SHImageType> ReaderType;

            SHImageType::Pointer image = 0;

            ReaderType::Pointer reader = ReaderType::New();
            reader->SetFileName ( path.toLatin1().constData() );
            try {
                reader->Update();
            }
            catch (itk::ExceptionObject &e) {
                dtkDebug() << e.GetDescription();
                return false;
            }
            image = reader->GetOutput();
            medData->setData (image);
        }
        else if (medData->identifier()=="itkDataSHImageFloat3") {
            typedef itk::VectorImage<float, 3> SHImageType;

            typedef itk::ImageFileReader<SHImageType> ReaderType;

            SHImageType::Pointer image = 0;

            ReaderType::Pointer reader = ReaderType::New();
            reader->SetFileName ( path.toLatin1().constData() );
            try {
                reader->Update();
            }
            catch (itk::ExceptionObject &e) {
                dtkDebug() << e.GetDescription();
                return false;
            }
            image = reader->GetOutput();
            medData->setData (image);

        }
        else {
            dtkDebug() << "Unsupported data type";
            return false;
        }
    }
    else {
        dtkDebug() << "No data set or could not create one";
        return false;
    }

    return true;
    
}
Пример #5
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();

}
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();

}
int main( int argc, char** argv )
{
  if( argc < 2 )
    {
    std::cerr << "Usage: " << argv[0] << " inputImage" << std::endl;
    return 1;
    }

  const unsigned int Dimension = 3;
  typedef float PixelType;
  typedef itk::Image< PixelType, Dimension > ImageType;

  typedef itk::ImageFileReader< ImageType > ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( argv[1] );

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

  ImageType::ConstPointer output = reader->GetOutput();

  typedef itk::BoxMeanImageFilter< ImageType, ImageType > FilterType;
  FilterType::Pointer filter = FilterType::New();
  filter->SetInput( reader->GetOutput() );

  FilterType::RadiusType radius;
  radius.Fill( 3 );
  filter->SetRadius( radius );

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

  return 0;
}
Пример #8
0
void MriWatcherGUI::LoadImg2()
{
  QString filename = QFileDialog::getOpenFileName(
      this,
      tr("Select one image files to open"),
      QDir::currentPath(),
      tr("*.jpg *.gipl* *.raw* *.hdr *.mha *.mhd* *.nhdr* *nrrd* *nii*") );

  if( filename != NULL )
    {
    ReaderType::Pointer reader = ReaderType::New();
    reader->SetFileName( filename.toLatin1().constData() );
    try
      {
      reader->Update();
      }
    catch( itk::ExceptionObject & e )
      {
      QMessageBox::information( this, "MriWatcher", "Unable to load file:\n" + filename.toLatin1() );
      return;
      }

    m_originalimage = reader->GetOutput();
    if( m_originalimage.IsNotNull() )
      {
      m_imagemanager.SetTargetImage(m_originalimage);
      g_alpha->setValue(50);
//	    g_overlay_alpha_slider->setEnabled(true);
      }
    g_loadimg2->setDown(false);
    }
}
Пример #9
0
// ------------------------------------------------------------------------
void loadImageSeries(SeriesTransform &series,
		const unsigned int &instanceNumbers)
{
	// resize the image vector
	series.images.resize(series.imageFilenames.size());

	typedef itk::GDCMImageIO IOType;
	typedef itk::ImageFileReader<ImageType> ReaderType;

	for(unsigned int i = 0; i < instanceNumbers; i++)
	{
		ReaderType::Pointer reader = ReaderType::New();
		reader->SetImageIO(IOType::New());
		reader->SetFileName(series.imageFilenames[i]);
		
		try 
		{
			reader->Update();
		}
		catch(itk::ExceptionObject &e)
		{	
			std::cout << e << std::endl;
			exit(1);
		}

		series.images[i] = reader->GetOutput();
	}
}
Пример #10
0
void PTXViewerWidget::on_actionReplaceDepthImage_activated()
{
  QString fileName = QFileDialog::getOpenFileName(this, "Open Depth Image", "", "Image Files (*.mha)");

  if(fileName.toStdString().empty())
    {
    std::cout << "Filename was empty." << std::endl;
    return;
    }

  typedef itk::ImageFileReader<PTXImage::FloatImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(fileName.toStdString());
  reader->Update();

  
  //this->PTX.ReplaceDepth(reader->GetOutput());
  QFuture<void> readerFuture = QtConcurrent::run(&PTX, &PTXImage::ReplaceDepth, reader->GetOutput());
  this->FutureWatcher.setFuture(readerFuture);
  this->ProgressDialog->setLabelText("Opening depth image...");
  this->ProgressDialog->exec();

  
  Display();
  
  this->statusBar()->showMessage("Replaced depth image.");
}
Пример #11
0
int main (int argc, char *argv[])
{
  if(argc != 4)
    {
    std::cout << "Required arguments: InputFilename(ptx) MaskFilename(png) OutputFilePrefix" << std::endl;
    return EXIT_FAILURE;
    }

  std::string inputFilename = argv[1];
  std::string maskFilename = argv[2];
  std::string outputFilePrefix = argv[3];

  typedef itk::ImageFileReader<itk::Image<unsigned char, 2> > ReaderType;
  ReaderType::Pointer maskReader = ReaderType::New();
  maskReader->SetFileName(maskFilename);
  maskReader->Update();

  PTXImage ptxImage = PTXReader::Read(inputFilename);
  ptxImage.ApplyMask(maskReader->GetOutput());

  ptxImage.WriteRGBImage(outputFilePrefix);

  std::stringstream pointsss;
  pointsss << outputFilePrefix << ".vtp";
  ptxImage.WritePointCloud(pointsss.str());

  return EXIT_SUCCESS;
}
Пример #12
0
int main(int argc, char* argv[])
{
    
    typedef itk::Image<float, 3> ImageType;
    
    
    typedef itk::ImageFileReader<ImageType> ReaderType;
    const char*  filenamereader = "/Users/Fabian/Documents/Pruebas/Prueba ITK/Archivo Binary/m1.mhd";  
    ReaderType::Pointer reader = ReaderType::New();
    reader->SetFileName(filenamereader);
    reader->Update();    
    
    typedef itk::ScalarToFractalImageFilter<ImageType,ImageType> FilterType;
    FilterType::Pointer filter = FilterType::New();
    filter->SetInput(reader->GetOutput());
    FilterType::RadiusType radius;
    radius.Fill(3);
    filter->SetNeighborhoodRadius(radius);
    filter->Update();
    
//    typedef itk::ImageFileWriter<ImageType> WriterType;
//    const char*  filenamewriter = "xy14_filter.bmp";
//    WriterType::Pointer writer = WriterType::New();
//    writer->SetFileName(filenamewriter);
//    writer->SetInput(filter->GetOutput());
//    writer->Update();
    
    return 0;
}
//read CT image
void CTImageTreeItem::retrieveITKImage(QProgressDialog *progress, int progressScale, int progressBase) {
	//define and create file reader
	typedef ReaderProgress::ReaderType ReaderType;
	ReaderType::Pointer imageReader = ReaderType::New();
	ReaderType::FileNamesContainer fc;
	//assign filenames
	fc.assign(m_fnList.begin(), m_fnList.end());
	//set ImageIO and filenames
	itk::GDCMImageIO::Pointer gdcmImageIO = itk::GDCMImageIO::New();
	imageReader->SetImageIO( gdcmImageIO );
	imageReader->SetFileNames(fc);
	//create reader progress
	ReaderProgress::Pointer progressor = ReaderProgress::New();
	if (progress) 
	{
		progressor->setDialog( progress, progressScale, progressBase );
		imageReader->AddObserver(itk::AnyEvent(), progressor);
	}
	//try to read the images
	try {
		imageReader->Update();
	}catch( itk::ExceptionObject & excep ) {
		std::cerr << "Exception caught !" << std::endl;
		std::cerr << excep << std::endl;
	}
	//assign the reader output to an image pointer
	ImageType::Pointer imagePtr =  imageReader->GetOutput();
	setITKImage(imagePtr, 1);
	//emit signal, that data has changed
	m_model->dataChanged(m_model->createIndex(childNumber(),0,parent()),m_model->createIndex(childNumber(),columnCount()-1,parent()));
}
Пример #14
0
void Form::on_btnOpen_clicked()
{
  QString fileName = QFileDialog::getOpenFileName(this, "Open File", ".", "Image Files (*.jpg *.jpeg *.bmp *.png)");

  std::cout << "Got filename: " << fileName.toStdString() << std::endl;
  if(fileName.toStdString().empty())
    {
    std::cout << "Filename was empty." << std::endl;
    return;
    }

  /*
  typedef itk::RGBPixel<unsigned char> RGBPixelType;
  typedef itk::Image<RGBPixelType> RGBImageType;
  
  typedef itk::ImageFileReader<RGBImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(fileName.toStdString());
  reader->Update();
  
  RGBImageType::Pointer itkimage = reader->GetOutput();
  */
  
  //typedef itk::VectorImage<unsigned char, 2> ImageType;
  typedef itk::VectorImage<char, 2> ImageType;
  
  typedef itk::ImageFileReader<ImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(fileName.toStdString());
  reader->Update();
  
  ImageType::Pointer itkimage = reader->GetOutput();
  
  QImage image(itkimage->GetLargestPossibleRegion().GetSize()[0], itkimage->GetLargestPossibleRegion().GetSize()[1], QImage::Format_RGB32);
  itk::ImageRegionIterator<ImageType> imageIterator(itkimage, itkimage->GetLargestPossibleRegion());
  QColor black(0,0,0);
  while(!imageIterator.IsAtEnd())
    {
    ImageType::PixelType pixel = imageIterator.Get();
    
    //QRgb qtPixel(pixel[0], pixel[1], pixel[2]);
    //image.setPixel(imageIterator.GetIndex()[0], imageIterator.GetIndex()[1], QColor(pixel[0], pixel[1], pixel[2]).rgb());
    image.setPixel(imageIterator.GetIndex()[0], imageIterator.GetIndex()[1], black.rgb());
    ++imageIterator;
    }

  
  
  //QPixmap image;
  //image.loadFromData(itkimage->GetBufferPointer());
  
  QGraphicsScene* scene = new QGraphicsScene();
  
  //scene->addPixmap(image);
  scene->addPixmap(QPixmap::fromImage(image));
  
  this->graphicsView->setScene(scene);
  
}
Пример #15
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;
}
	virtual void SetUp() {

		  m_KernelReader = ReaderType::New();
		  m_InputReader = ReaderType::New();

		  m_Rescaler = Rescaler01FilterType::New();
		  m_Rescaler->SetInput(m_InputReader->GetOutput());
		  m_Rescaler->SetOutputMinimum(0);
		  m_Rescaler->SetOutputMaximum(1);

		  m_Deconvoluter = DeconvolutionFilterType::New();
		  m_Deconvoluter->SetKernelImage( m_KernelReader->GetOutput() );
		  m_Deconvoluter->SetInput( m_Rescaler->GetOutput() );

		  m_Writer = WriterType::New();
		  m_Writer->SetInput( m_Deconvoluter->GetOutput() );

	}
Пример #17
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();
}
void LidarSegmentationWidget::on_action_Selections_LoadFromImage_triggered()
{
  QString filename = QFileDialog::getOpenFileName(this,
     "Open Image", ".", "PNG Files (*.png)");

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

  typedef  itk::ImageFileReader< RGBImageType  > ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(filename.toStdString());
  reader->Update();

  RGBPixelType greenPixel;
  greenPixel.SetRed(0);
  greenPixel.SetGreen(255);
  greenPixel.SetBlue(0);
  
  RGBPixelType redPixel;
  redPixel.SetRed(255);
  redPixel.SetGreen(0);
  redPixel.SetBlue(0);
  
  itk::ImageRegionConstIterator<RGBImageType> imageIterator(reader->GetOutput(),
                                                            reader->GetOutput()->GetLargestPossibleRegion());
 
  while(!imageIterator.IsAtEnd())
    {
    if(imageIterator.Get() == greenPixel)
      {
      this->Sources.push_back(imageIterator.GetIndex());
      }
    else if(imageIterator.Get() == redPixel)
      {
      this->Sinks.push_back(imageIterator.GetIndex());
      }
 
    ++imageIterator;
    }

  UpdateSelections();
}
Пример #19
0
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;
}
Пример #20
0
bool extractPointAndNormalFromMask(string filename, CVector3 &point, CVector3 &normal1, CVector3 &normal2)
{
    ReaderType::Pointer reader = ReaderType::New();
	itk::NiftiImageIO::Pointer io = itk::NiftiImageIO::New();
	reader->SetImageIO(io);
	reader->SetFileName(filename);
    try {
        reader->Update();
    } catch( itk::ExceptionObject & e ) {
        cerr << "Exception caught while reading input image " << endl;
        cerr << e << endl;
        return false;
    }
    ImageType::Pointer image = reader->GetOutput();
    
    vector<CVector3> result;
    ImageType::IndexType ind;
    itk::Point<double,3> pnt;
    ImageIterator it( image, image->GetRequestedRegion() );
    it.GoToBegin();
    while(!it.IsAtEnd())
    {
        if (it.Get()!=0)
        {
            ind = it.GetIndex();
            image->TransformIndexToPhysicalPoint(ind, pnt);
            bool added = false;
            if (result.size() == 0) {
                result.push_back(CVector3(pnt[0],pnt[1],pnt[2]));
                added = true;
            }
            else {
                for (vector<CVector3>::iterator it=result.begin(); it!=result.end(); it++) {
                    if (pnt[2] < (*it)[2]) {
                        result.insert(it, CVector3(pnt[0],pnt[1],pnt[2]));
                        added = true;
                        break;
                    }
                }
            }
            if (!added) result.push_back(CVector3(pnt[0],pnt[1],pnt[2]));
        }
        ++it;
    }
    
    if (result.size() != 3) {
        cerr << "Error: Not enough of too many points in the binary mask. Number of point needed = 3. Detected points = " << result.size() << endl;
        return false;
    }
    point = result[1];
    normal1 = (result[0]-result[1]).Normalize();
    normal2 = (result[2]-result[1]).Normalize();
    
    return true;
}
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;
}
Пример #22
0
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();
}
int main(int argc, char *argv[])
{
  if(argc < 3)
  {
    throw std::runtime_error("Required arguments: inputFileName outputPrefix");
  }

  std::string inputFileName = argv[1];
  std::string outputPrefix = argv[2];

  std::cout << "Input: " << inputFileName << std::endl;
  std::cout << "Output prefix: " << outputPrefix << std::endl;

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

  ITKHelpers::WriteVectorImageAsRGB(reader->GetOutput(), outputPrefix + "/Image.mha");

  WriteImagePixelsToRGBSpace(reader->GetOutput(), outputPrefix + "/ImageColors.vtp");

  WriteClusteredPixelsInRGBSpace(reader->GetOutput(), 20, outputPrefix + "/ImageColorsClustered.vtp");

  FloatVectorImageType::Pointer blurred = FloatVectorImageType::New();
  //float blurVariance = 2.0f; // almost no visible blurring
  //float blurVariance = 10.0f; // slight blurring of concrete
  //float blurVariance = 30.0f;

  // TODO: Update this call to the new API
  //Helpers::AnisotropicBlurAllChannels<FloatVectorImageType>(reader->GetOutput(), blurred, blurVariance);

  ITKHelpers::WriteVectorImageAsRGB(blurred.GetPointer(), outputPrefix + "/BlurredImage.mha");

  WriteImagePixelsToRGBSpace(blurred, outputPrefix + "/BlurredImageColors.vtp");

  WriteClusteredPixelsInRGBSpace(blurred, 20, outputPrefix + "/BlurredImageColorsClustered.vtp");

  return EXIT_SUCCESS;
}
int main(int argc, char *argv[])
{
  std::string inputFileName = argv[1];
  std::string outputPrefix = argv[2];

  std::cout << "Input: " << inputFileName << std::endl;
  std::cout << "Output prefix: " << outputPrefix << std::endl;

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

  ClusterColorsAdaptive clusterColors;
  clusterColors.SetNumberOfColors(100);
  clusterColors.ConstructFromImage(reader->GetOutput());

  std::vector<ColorMeasurementVectorType> colorMeasurements = clusterColors.GetColors();

  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
  vtkSmartPointer<vtkUnsignedCharArray> colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
  colors->SetName("Colors");
  colors->SetNumberOfComponents(3);

  for(unsigned int colorId = 0; colorId < colorMeasurements.size(); ++colorId)
    {
    double point[3];
    unsigned char color[3];
    for(unsigned int component = 0; component < 3; component++)
      {
      point[component] = colorMeasurements[colorId][component];
      color[component] = colorMeasurements[colorId][component];
      }
    std::cout << "ColorId " << colorId << " : " << point[0] << " " << point[1] << " " << point[2] << std::endl;
    points->InsertNextPoint(point);
    colors->InsertNextTupleValue(color);
    }
  vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
  polyData->SetPoints(points);
  polyData->GetPointData()->SetScalars(colors);

  vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New();
  glyphFilter->SetInputConnection(polyData->GetProducerPort());
  glyphFilter->Update();

  vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
  writer->SetInputConnection(glyphFilter->GetOutputPort());
  writer->SetFileName((outputPrefix + ".vtp").c_str());
  writer->Write();

  return EXIT_SUCCESS;
}
Пример #25
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;
}
Пример #26
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];

  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[])
{
  // Verify arguments
  if(argc != 4)
  {
    std::cerr << "Required: image.png mask.fgmask output.png" << std::endl;
    return EXIT_FAILURE;
  }

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

  // This image should have white pixels indicating foreground pixels and be black elsewhere.
  std::string maskFilename = argv[2];

  std::string outputFilename = argv[3];

  // Output arguments
  std::cout << "imageFilename: " << imageFilename << std::endl
            << "maskFilename: " << maskFilename << std::endl
            << "outputFilename: " << outputFilename << std::endl;

  // The type of the image to segment
  typedef itk::Image<itk::CovariantVector<unsigned char, 3>, 2> ImageType;

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

  // Read the mask
  ForegroundBackgroundSegmentMask::Pointer mask =
      ForegroundBackgroundSegmentMask::New();
  mask->Read(maskFilename);

  // Perform the segmentation
  std::cout << "Starting GrabCut..." << std::endl;
  GrabCut<ImageType> grabCut;
  grabCut.SetImage(reader->GetOutput());
  grabCut.SetInitialMask(mask);
  grabCut.PerformSegmentation();

  // Get and write the result
  ImageType::Pointer result = ImageType::New();
  grabCut.GetSegmentedImage(result);
  ITKHelpers::WriteImage(result.GetPointer(), outputFilename);

  return 0;
}
Пример #28
0
void PTXViewerWidget::on_actionReplaceValidityImageInverted_activated()
{
  QString fileName = QFileDialog::getOpenFileName(this, "Open Mask Image", "", "Image Files (*.mha)");

  if(fileName.toStdString().empty())
    {
    std::cout << "Filename was empty." << std::endl;
    return;
    }

  typedef itk::ImageFileReader<PTXImage::UnsignedCharImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(fileName.toStdString());
  reader->Update();

  // Invert
  itk::ImageRegionIterator<PTXImage::UnsignedCharImageType> imageIterator(reader->GetOutput(), reader->GetOutput()->GetLargestPossibleRegion());

  while(!imageIterator.IsAtEnd())
    {
    if(imageIterator.Get())
      {
      imageIterator.Set(0);
      }
    else
      {
      imageIterator.Set(255);
      }

    ++imageIterator;
    }

  this->PTX.ReplaceValidity(reader->GetOutput());
  Display();

  this->statusBar()->showMessage("Replaced validity image inverted.");
}
Пример #29
0
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;
}
Пример #30
0
FilterImageType::Pointer getImage(const FileNamesContainer &filenames, DictionaryArray &dictArray) {
	typedef itk::ImageSeriesReader< FilterImageType > ReaderType;
	ReaderType::Pointer reader = ReaderType::New();
	ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
	reader->SetImageIO( gdcmImageIO );
	reader->SetFileNames(filenames);
	reader->Update();
	ReaderType::DictionaryArrayRawPointer dict;

	dict = reader->GetMetaDataDictionaryArray();
	for( ReaderType::DictionaryArrayType::const_iterator it = dict->begin(); it != dict->end(); ++it) {
		dictArray.push_back( **it );
	}
	
	return reader->GetOutput();
}