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

Luis Ibanez luis.ibanez at kitware.com
Mon Feb 15 17:56:19 EST 2010


Hi Noura,

If you only want your binary mask to only have the pixels that
are touched by the mesh, you can take the current binary mask
that you got from the rasterization process and you can pass it
as input to the

               itkSimpleContourExtractorImageFilter

That should give you as output a binary mask that only contains
the pixelized surface of the mesh.

---

You can achieve a similar result by eroding the mask and
subtracting it from the original one.


    Regards,


            Luis



---------------------------------------------------------------------------------
On Mon, Feb 15, 2010 at 8:13 AM, Noura AZZABOU
<n.azzabou at institut-myologie.org> wrote:
> 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
>
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>


More information about the Insight-users mailing list