[Insight-users] BinaryMask3DMeshSource and AntiAliasBinaryImageFilter

Luis Ibanez luis.ibanez at kitware.com
Sun Nov 25 11:52:46 EST 2007


Hi Pawel,

The AntiAliasBinaryImageFilter is indeed very effective in smoothing
the isosurface of an image before you extract it.

What you may want to do is to save the output of the AntiAlias filter
in to a MetaImage file or a VTK file. Simply use a .mhd or a .vtk
extension.

Then load the file into ParaView (www.paraview.org) and use the
Contour filter on it. In this way you will be able to visualize
the iso-surface extracted from the image.


You may also want to look at the ITK+VTK visualization example:

        InsightApplications/Auxiliary/vtk/
            itkReadITKImage3DSegmentShowVTK.cxx

where the output of an image segmentation is converted into
a vtkImageData and then visualized by extracting its iso-surface.


A similar combination was used for generating all the surfaces
in the cover of the ITK Software Guide.



   Regards,


      Luis



-----------------------------
Paweł Andruszkiewicz wrote:
> Hello
> 
> I'm using some segmentation routine to generate list of points being the
> contour of 3D object. From this list I'm creating a binary image, which is
> passed to BinaryMask3DMeshSource and using the output mesh to visualize the object
> in OpenGL. However, the resulting object is not very smooth. I've read the
> mailing list, and some of the posts mention the AntiAliasBinaryImageFilter as
> a solution for this issue. When I try to apply this filter before the
> BinaryMask3DMeshSource, I get 0 cells. What is the better way to acquire smooth
> object? (note, that using the VTK is not possible). Also, if somebody can confirm
> if my code iterating through the cells is correct, I'll be grateful.
> 
> The code:
> 
> typedef signed short PixelType;
> typedef double DoublePixelType;
> const unsigned int Dimension = 3;
> typedef itk::Image<PixelType, Dimension> ImageType;
> typedef itk::Image<DoublePixelType, Dimension> DoubleImageType;
> 
> typedef itk::AntiAliasBinaryImageFilter<DoubleImageType, DoubleImageType>
> AntiAliasFilterType;
> typedef itk::BinaryMask3DMeshSource<ImageType, MeshType> MeshSourceType;
> typedef itk::CastImageFilter<DoubleImageType, ImageType>
> CastToShortFilterType;
> typedef itk::CastImageFilter<ImageType, DoubleImageType>
> CastToDoubleFilterType;
> 
> typedef itk::Mesh<double, Dimension> MeshType;
> typedef MeshType::CellsContainer::ConstIterator CellIterator;
> typedef MeshType::CellType CellType;
> typedef itk::TriangleCell<CellType> TriangleType;
> 
> //...
> ImageType::Pointer image;
> //...
> //image is filled with 0's and the pixels containing the border are set to
> 1
> //...
> CastToDoubleFilterType::Pointer castToDouble =
> CastToDoubleFilterType::New();
> castToDouble->SetInput(image);
> 
> AntiAliasFilterType::Pointer antiAliasFilter = AntiAliasFilterType::New();
> antiAliasFilter->SetMaximumRMSError(0.07);
> antiAliasFilter->SetNumberOfIterations(30);
> antiAliasFilter->SetNumberOfLayers(2);
> antiAliasFilter->SetInput(castToDouble->GetOutput());
> 	
> CastToShortFilterType::Pointer castToShort = CastToShortFilterType::New();
> castToShort->SetInput(antiAliasFilter->GetOutput());
> 	
> MeshSourceType::Pointer meshSource = MeshSourceType::New();
> meshSource->SetObjectValue(1);
> meshSource->SetInput(castToShort->GetOutput());
> 
> try {
>     meshSource->Update();
>     MeshType::Pointer mesh = meshSource->GetOutput();
>     //...
>     glBegin(GL_TRIANGLES);
> 
>     CellIterator cellIterator = mesh->GetCells()->Begin();
>     CellIterator cellEnd = mesh->GetCells()->End();
> 
>     while(cellIterator != cellEnd) {
>         CellType *cell = cellIterator.Value();
>         if(cell->GetType() == CellType::TRIANGLE_CELL) {
>             TriangleType *triangle = dynamic_cast<TriangleType *>(cell);
>             TriangleType::PointIdIterator pit = triangle->PointIdsBegin();
>             MeshType::PointType p;
> 
>             mesh->GetPoint(*pit++, &p);
>             GLdouble y = computeY(p[2]);
>             GLdouble x = computeX(p[0]);
>             GLdouble z = computeZ(p[1]);
>             glVertex3d(x, y, z);
>     		
>             mesh->GetPoint(*pit++, &p);
>             y = computeY(p[2]);
>             x = computeX(p[0]);
>             z = computeZ(p[1]);
>             glVertex3d(x, y, z);
> 
>             mesh->GetPoint(*pit++, &p);
>             y = computeY(p[2]);
>             x = computeX(p[0]);
>             z = computeZ(p[1]);
>             glVertex3d(x, y, z);
>         }
>     	
>         ++cellIterator;
>     }
> 
>     glEnd();
> } catch( itk::ExceptionObject & ex ){
> //report the error
> }
> 
> kind regards, Pawel Andruszkiewicz
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 


More information about the Insight-users mailing list