[vtkusers] gradient module with gaussian filter

lnggg arnoramb at alumnos.ubiobio.cl
Fri Feb 5 23:48:57 EST 2010


Hi.
I am programming  surface deformable, for this is necessary the gradient
with a gaussian filter, but I couldn't get the value in a point please help
me.

I had to programme the gradient to my way

Sorry . I am newbie  in programming and english
Regards from chile.


tkDICOMImageReader *reader = vtkDICOMImageReader::New();
	reader->SetDirectoryName("C:/Users/Lng/Desktop/sphere1/sphere1");
	reader->SetDataExtent(0,32,0,32,0,32); 
	reader->SetDataSpacing(0.1/32,0.1/32,0.1/32); 
	reader->SetDataOrigin(0,0,0);
	reader->Update();



  double mag_grad[40][40][40];
  double dxadt,dyadt,dzadt;
  int max_i=31;   //uno menos ya que empieza desde cero
  int max_j=31;
  int max_k=31;
  int i,j,k;
  double max_grad=0;
  for(i=0;i<=max_i;i++)
  {
	  for(j=0;j<=max_j;j++)
	  {
		  for(k=0;k<=max_k;k++)
		  {
		
			if(i==0||j==0 || k==0)
				mag_grad[i][j][k]=0;
			else if(i==max_i||j==max_j || k==max_k)
				mag_grad[i][j][k]=0;
			else
			{
			
dxadt=(reader->GetOutput()->GetScalarComponentAsDouble(i+1,j,k,0)-reader->GetOutput()->GetScalarComponentAsDouble(i-1,j,k,0))*0.5;
			
dyadt=(reader->GetOutput()->GetScalarComponentAsDouble(i,j+1,k,0)-reader->GetOutput()->GetScalarComponentAsDouble(i,j-1,k,0))*0.5;
			
dzadt=(reader->GetOutput()->GetScalarComponentAsDouble(i,j,k+1,0)-reader->GetOutput()->GetScalarComponentAsDouble(i,j,k-1,0))*0.5;
				mag_grad[i][j][k]=(dxadt*dxadt)+(dyadt*dyadt)+(dzadt*dzadt);
				mag_grad[i][j][k]=sqrt(mag_grad[i][j][k]);
			}
			if(mag_grad[i][j][k]>max_grad)
				max_grad=mag_grad[i][j][k];
		  }
	  }
  }


  for(i=0;i<=max_i;i++)
  {
	  for(j=0;j<=max_j;j++)
	  {
		  for(k=0;k<=max_k;k++)
		  {
			 
reader->GetOutput()->SetScalarComponentFromDouble(i,j,k,0,mag_grad[i][j][k]);
		  }
	  }
  }


  vtkImageGaussianSmooth *smooth = vtkImageGaussianSmooth::New(); 
  smooth->SetDimensionality(3);
  smooth->SetStandardDeviations(3.0, 3.0, 3.0); 
  smooth->SetRadiusFactors(3.0, 3.0,3.0);
  smooth->SetInput( reader->GetOutput() ); 
  
  double intermedio;
  intermedio=smooth->GetOutput()->GetScalarComponentAsFloat(15,15,15,0); 
//ERROR , say "not in memory"
-- 
View this message in context: http://old.nabble.com/gradient-module-with-gaussian-filter-tp27476693p27476693.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list