Beispiel #1
0
int runGrAnisDiff(unsigned char* imgIn, int r, int c, int z, int iter, int timeStep, int comductance)
{
	
	//pixel types
	typedef unsigned char InputPixelType;
	typedef float OutputPixelType;
	typedef itk::Image< InputPixelType, 3 > InputImageType;
	typedef itk::Image< OutputPixelType, 3 > OutputImageType;
	
	//create an ITK image from the input image
	OutputImageType::Pointer im;
	im = OutputImageType::New();
	OutputImageType::PointType origin;
    origin[0] = 0.; 
    origin[1] = 0.;    
	origin[2] = 0.;    
    im->SetOrigin( origin );

    OutputImageType::IndexType start;
    start[0] =   0;  // first index on X
    start[1] =   0;  // first index on Y    
	start[2] =   0;  // first index on Z    
    OutputImageType::SizeType  size;
    size[0]  = c;  // size along X
    size[1]  = r;  // size along Y
	size[2]  = z;  // size along Z
  
    OutputImageType::RegionType region;
    region.SetSize( size );
    region.SetIndex( start );
    
 //   double spacing[3];
	//spacing[0] = 1; //spacing along x
	//spacing[1] = 1; //spacing along y
	//spacing[2] = sampl_ratio; //spacing along z

    im->SetRegions( region );
	//im->SetSpacing(spacing);
    im->Allocate();
    im->FillBuffer(0);
	im->Update();	
	
	//copy the input image into the ITK image
	typedef itk::ImageRegionIteratorWithIndex< OutputImageType > IteratorType;
	IteratorType iterator1(im,im->GetRequestedRegion());
	
	for(int i=0; i<r*c*z; i++)
	{					
		iterator1.Set((float)imgIn[i]);
		++iterator1;		
	}

	//apply gradient anisotropic diffusion
	typedef itk::GradientAnisotropicDiffusionImageFilter< OutputImageType, OutputImageType > FilterType;
	FilterType::Pointer filter = FilterType::New();
	filter->SetInput( im );

	filter->SetNumberOfIterations( iter );
	filter->SetTimeStep( timeStep );
	filter->SetConductanceParameter( comductance );

	try
	{
		filter->Update();
	}
	catch( itk::ExceptionObject & err ) 
    { 
		std::cerr << err << std::endl;
		return 0;
	}

	typedef itk::RescaleIntensityImageFilter< OutputImageType, InputImageType > RescaleFilterType;

	RescaleFilterType::Pointer rescaler = RescaleFilterType::New();
	rescaler->SetOutputMinimum(   0 );
	rescaler->SetOutputMaximum( 255 );
	rescaler->SetInput( filter->GetOutput() );
	rescaler->Update();

	//overwrite the input image for now in order to save space
	typedef itk::ImageRegionIteratorWithIndex< InputImageType > IteratorType2;
	IteratorType2 iterator2(rescaler->GetOutput(),rescaler->GetOutput()->GetRequestedRegion());
	
	for(int i=0; i<r*c*z; i++)
	{					
		imgIn[i] = iterator2.Get();
		++iterator2;		
	}

	return 1;
}
void IntrinsicFeatureCalculator::GetDistanceToSurfaceMeasures(vtkSmartPointer<vtkTable> table, std::vector< ftk::Object::Point > surfacePoints)
{
	typedef itk::Image< IPixelT, 3 > InputImageType;
	typedef itk::Image< LPixelT, 3 > OutputImageType;
	typedef itk::DanielssonDistanceMapImageFilter< OutputImageType, OutputImageType > DanielssonFilterType;
	typedef itk::RescaleIntensityImageFilter< OutputImageType, OutputImageType > RescalerType;
	typedef itk::ImageFileReader< InputImageType  >  ReaderType;
	typedef itk::ImageFileWriter< InputImageType >  InputWriterType;
	typedef itk::ImageFileWriter< OutputImageType >  WriterType;
	typedef itk::LineIterator< OutputImageType > LineIteratorType;

	vtkSmartPointer<vtkDoubleArray> column = vtkSmartPointer<vtkDoubleArray>::New();
	column->SetName( "Dist_To_Surface" );
	column->SetNumberOfValues( table->GetNumberOfRows() );
	table->AddColumn(column);	

	OutputImageType::Pointer im;
	im = OutputImageType::New();
	OutputImageType::PointType origin;
    origin[0] = 0; 
    origin[1] = 0;    
	origin[2] = 0;    
    im->SetOrigin( origin );

    OutputImageType::IndexType start;
    start[0] =   0;  // first index on X
    start[1] =   0;  // first index on Y    
	start[2] =   0;  // first index on Z    
    
	OutputImageType::Pointer temp_image = labelImage->GetItkPtr< LPixelT >(0,0);
	itk::Size<3> im_size = temp_image->GetBufferedRegion().GetSize();
	im_size[2] = 1;
  
    InputImageType::RegionType region;
    region.SetSize( im_size );
    region.SetIndex( start );
    
    im->SetRegions( region );
    im->Allocate();
    im->FillBuffer(0);
	im->Update();
	
	//copy the input image into the ITK image
	for(int p = 1; p < (int)surfacePoints.size(); ++p)
	{
		itk::Index<3> indx,indy;
		indx[0] = surfacePoints[p-1].x;
		indx[1] = surfacePoints[p-1].y;
		indx[2] = 0;
		indy[0] = surfacePoints[p].x;
		indy[1] = surfacePoints[p].y;
		indy[2] = 0;
		LineIteratorType it( im, indx, indy );
		//it.GoToBegin();
		//while(!it.IsAtEnd())
		for(it.GoToBegin(); !it.IsAtEnd(); ++it)
		{
			it.Set(255);			
		}
	}

	DanielssonFilterType::Pointer danielssonFilter = DanielssonFilterType::New();	
	WriterType::Pointer writer = WriterType::New();	
	danielssonFilter->SetInput( im );
	writer->SetFileName( "DistanceMap.tif" );
	danielssonFilter->InputIsBinaryOn();
	danielssonFilter->Update();
	OutputImageType::Pointer distMap = danielssonFilter->GetOutput();
	writer->SetInput( distMap );
	writer->Update();
	
	for(int row=0; row<(int)table->GetNumberOfRows(); ++row)
	{
		OutputImageType::IndexType indx;
		indx[0] = table->GetValue(row, 1).ToInt();
		indx[1] = table->GetValue(row, 2).ToInt();
		indx[2] = 0;
		int dist = distMap->GetPixel(indx);
		table->SetValueByName(row, "Dist_To_Surface", vtkVariant(dist));
	}



}