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

Luis Ibanez luis.ibanez at kitware.com
Thu Feb 18 10:18:17 EST 2010


Hi Noura,

Thanks for letting us know that this solved the problem.


      Luis


-----------------------------------------------------------
On Thu, Feb 18, 2010 at 6:23 AM, Noura AZZABOU
<n.azzabou at institut-myologie.org> wrote:
> Hi Luiz,
>
> Thank you for you help it works now
>
>
> Noura
>
> -----Message d'origine-----
> De : Luis Ibanez [mailto:luis.ibanez at kitware.com]
> Envoyé : 17 February 2010 21:26
> À : Noura AZZABOU
> Cc : itk
> Objet : Re: [Insight-users] problem to convert a mesh to a Binary image
>
> Hi Noura,
>
> Thanks for the clarification.
>
> The filter that you need then, is called:
>
>       itkTriangleMeshToBinaryImageFilter
>
> http://www.itk.org/Doxygen/html/classitk_1_1TriangleMeshToBinaryImageFilter.html
>
>
> You will find it in the directory:
>
>            Insight/Code/BasicFilters
>
>
>    Regards,
>
>
>        Luis
>
>
> --------------------------------
> On Tue, Feb 16, 2010 at 4:25 AM, Noura AZZABOU
> <n.azzabou at institut-myologie.org> wrote:
>> Hi Luis,
>>
>> Thank you for your answer but my problem is the opposite I want to obtain a binary image from the mesh. Indeed, when I used the line code that I posted, the result was not as expected and I obtained a Binary image containing only the pixel belonging to the contour (and not those inside the contour. The result I obtained is similar (but thicker contours) to the one given by
>>
>> itk::PointSetToImageFilter<MeshType,ImageType> MeshFilterType;
>>
>> I can send you the resulting image and the corresponding mesh if it makes things more clear.
>>
>>
>> Regards
>>
>> Noura
>>
>>
>> -----Message d'origine-----
>> De : Luis Ibanez [mailto:luis.ibanez at kitware.com]
>> Envoyé : 15 February 2010 23:56
>> À : Noura AZZABOU
>> Cc : insight-users at itk.org
>> Objet : Re: [Insight-users] problem to convert a mesh to a Binary image
>>
>> 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