[Insight-users] problem to convert a mesh to a Binary image

Noura AZZABOU n.azzabou at institut-myologie.org
Mon Feb 15 08:13:54 EST 2010


Hi,

I am trying to convert a vtk mesh to a Binary image. I followed the examples given in the ITK software guide.  I used spatial object in order to obtain a Binary image (1 inside the mesh) 0 outside.
 Instead of that I obtained an image with 1 for the pixel belonging to the contour and 0 for the rest (inclusing the pixels that are inside the region delimited by the contour)

Does any body know if there are some condition on mesh to make the generation of binary image possible.

Here is the source code for the binary image generation.

Thanks in advance for your help



typedef itk::Mesh< double, 3 > MeshType;
      typedef itk::MeshSpatialObject< MeshType > SpatialObjectType;
      typedef itk::Image< unsigned char, 3 > ImageType;
      typedef itk::Image< double, 3> RefImageType;
      typedef itk::SpatialObjectToImageFilter< SpatialObjectType, ImageType > MeshFilterType;
      typedef itk::VTKPolyDataReader< MeshType > MeshReaderType;
      typedef itk::ImageFileWriter< ImageType > ImageWriterType;
      typedef itk::ImageFileReader< RefImageType > RefImageReaderType;

      /// load vtk mesh
      std::cout << "load vtk mesh" << std::endl;
      MeshReaderType::Pointer mesh_reader = MeshReaderType::New();
      mesh_reader->SetFileName( mesh_path );
      mesh_reader->Update();
      SpatialObjectType::Pointer mesh = SpatialObjectType::New();
      mesh->SetMesh( mesh_reader->GetOutput() );


      /// reference image
      std::cout << "load reference image" << std::endl;
      RefImageReaderType::Pointer ref_image_reader = RefImageReaderType::New();
      ref_image_reader->SetFileName( ref_image );
      ref_image_reader->Update();
      ref_image_reader->GetOutput()->Print(std::cout);

      /// image pointer
      ImageType::Pointer image;

      /// generate output image
      std::cout << "generate output image" << std::endl;
      MeshFilterType::Pointer mesh_filter = MeshFilterType::New();
      mesh_filter->SetOrigin( ref_image_reader->GetOutput()->GetOrigin() );
      mesh_filter->SetSize( ref_image_reader->GetOutput()->GetLargestPossibleRegion().GetSize() );
      mesh_filter->SetSpacing( ref_image_reader->GetOutput()->GetSpacing() );
      //mesh_filter->SetDirection( ref_image_reader->GetOutput()->GetDirection() );
      mesh_filter->SetOutsideValue(1);
      mesh_filter->SetInsideValue(23);
      mesh_filter->SetInput(mesh);
      ref_image_reader->Delete();
      try
      {
            mesh_filter->Update();
      }
      catch( itk::ExceptionObject & excep )
      {
            std::cerr << "Exception Caught !" << std::endl;
            std::cerr << excep << std::endl;
      }
      // mesh_reader->GetOutput()->Print(std::cout);
      // mesh->Print(std::cout);
      // mesh->GetMesh()->Print(std::cout);
      mesh_filter->GetInput()->Print(std::cout);
      mesh_filter->Print(std::cout);

      /// save image
      std::cout << "save image" << std::endl;
      ImageWriterType::Pointer image_writer = ImageWriterType::New();
      std::cout << "saving image: " << image_path + "/" + image_name << std::endl;
      image_writer->SetFileName( image_path + "/" + image_name );
      image_writer->SetInput( mesh_filter->GetOutput() );
      image_writer->Update();







-----------------------------------------------
Noura Azzabou, PhD
Labo RMN AIM-CEA
Institut de Myologie - Bat Babinski
G.H. Pitie-Salpetriere, 83 Bd Hopital
75651 Paris CEDEX 13, France
Tél. : 33 (0)1 42 16 58 92
Fax : 33 (0) 1 42 16 58 97

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100215/a9b2d58b/attachment-0001.htm>


More information about the Insight-users mailing list