[vtkusers] vtkGridTransform

zhangzhijun zjzhang at ee.cuhk.edu.hk
Thu Jan 31 11:13:42 EST 2002


Dear all:
        I want to do a deformable transformation to  several image slices. I
use the imageblend
to blend the raw image and the vtkimagegridsource, and then after the
transform, I want to
show the transformed image and the grid, there is one matter, the grid will
disappear
every time when the image number is time of 4, which is the setting of the
grid space. what
's the reason for this?
        Also I have a question on the vtkImageBlend, if I want to
superposition the grid on
the image, then after blend, the intensity of the image will be changed, cos
I cant set the
opacity of the image into 1, otherwise the grid will be invisible. then I
can only set the opacity
of the image to be less than 1, for example 0.9, then the blended image
intensity will be
only 0.9 of the original image, and is there any way to solve this?

          Here is my code, I dont know whether any of you can help me.

 int spacing=4;
 vtkImageGridSource* imageGrid=vtkImageGridSource::New();
 imageGrid->SetGridSpacing(spacing,spacing,spacing);
 imageGrid->SetGridOrigin(0,0,0);//-90,-108,-90);
 imageGrid->SetDataExtent(0,180,0,216,0,180);
 imageGrid->SetDataScalarTypeToUnsignedChar();
 imageGrid->SetLineValue(255);
 imageGrid->SetFillValue(0);
 imageGrid->SetDataSpacing(1,1,1);

 char* source_image_name="d:\\regdata\\shead\\t1\\image.bin";
 float source_width=181;//242;//
 float source_height=217;//276;//
 float source_depth=181;//252;//
 float source_x_size=1;//
 float source_y_size=1;//
 float source_z_size=1;//
 float sxorigin=0;//
 float syorigin=0;//
 float szorigin=0;//

vtkImageReader *reader=vtkImageReader::New();
 reader->SetFileName(source_image_name);
 reader->SetFileDimensionality(3);
 reader->SetDataExtent(0,source_width-1,0,source_height-1,0,source_depth-1);
 reader->SetDataOrigin(sxorigin,syorigin,szorigin);
 reader->SetDataScalarTypeToUnsignedChar();
 reader->SetDataMask(0x00ff);
 reader->SetDataSpacing(source_x_size,source_y_size,source_z_size);
 reader->SetDataByteOrderToBigEndian();
 //reader->FileLowerLeftOn();

 vtkImageBlend* blend=vtkImageBlend::New();
 blend->SetInput(0,reader->GetOutput());
 blend->SetInput(1,imageGrid->GetOutput());
 blend->Update();
 blend->SetOpacity(0,0.9);
 blend->SetOpacity(1,0.1);

 vtkImageData* grid=vtkImageData::New();

grid->SetExtent(0,180/spacing,0,216/spacing,0,180/spacing);//0,180,0,216,0,1
80);//
 grid->SetOrigin(-0.5,-0.5,-0.5);
 grid->SetSpacing(spacing,spacing,spacing);
 grid->SetScalarTypeToFloat();
 grid->SetNumberOfScalarComponents(3);
 float *p=(float*)grid->GetScalarPointer();

 int i,j,k;
 int x0=180/spacing;
 int y0=216/spacing;
 int z0=181/spacing;
 int x1,y1,z1;
 double pi=3.141592653589793;
 float max=2;
 int period=32;
 for (i=0;i<=z0;i++)
 {
  for (j=0;j<=y0;j++)
  {
   for (k=0;k<=x0;k++)
   {
    p[0]=rand();
    p[1]=rand();
    p[2]=0;
    p+=3;
   }
  }
 }

    vtkGridTransform* transform=vtkGridTransform::New();
 transform->SetDisplacementGrid(grid);
 transform->SetInterpolationModeToCubic();
 transform->Inverse();

 vtkImageReslice* reslice=vtkImageReslice::New();
 reslice->SetInput(blend->GetOutput());
 reslice->SetResliceTransform(transform);
 reslice->SetInterpolationModeToLinear();

 viewer=vtkImageViewer::New();
 //viewer->SetInput(reader->GetOutput());
 viewer->SetInput(reslice->GetOutput());
 //viewer->SetInput(imageGrid->GetOutput());
 //viewer->SetInput(blend->GetOutput());
 viewer->SetColorWindow(255);
 viewer->SetColorLevel(127.5);

best regards,
zhang zhijun




More information about the vtkusers mailing list