[Insight-users] 'Marching squares' -- Need to go from 2D binary
images <-> 2D 'meshes'
Karthik Krishnan
Karthik.Krishnan at kitware.com
Thu Dec 1 16:45:43 EST 2005
For whatever its worth:
I had a need to do somthing similar. (I did it in VTK, for other
reasons). Here's what I did. It might help you with the mesh to mask stuff..
Option 1:
Given a vtkPolyData containing a cell (the vtkPolyline),
PolyData -> vtkLinearExtrusionFilter -> vtkPolyDataToImageFilter ->
vtkImageStencil
should give you the mask of the contour pixels
Take a look at VTK/Examples/GUI/Tcl/ImageTracerWidget.tcl
Note that you will have dual regions issues depending on the contour
being traced clockwise or anti-clockwise..
Option 2:
Given a vtkPolyData containing a cell (the vtkPolyline), construct a
vtkPolygon from the vertices of the polyline.
Visit every pixel in the bounding box of the vtkPolyline (that info is
available to you ) and test if it is in the polygon, using the
EvaluatePosition method.
I am assuming that you are specifying the polyline in one of the
orthogonal planes. (otherwise iterating over the plane is tricky)
HTH
karthik
Zachary Pincus wrote:
> Hi folks,
>
> I'm working on a 2D application right now (might be 3D in the future)
> where I'll need to convert between:
> (a) 2D binary masks of simple shapes (with no "holes")
> (b) some sort of geometric representation of the same, e.g. a '2d
> mesh' which is I think just a closed poly-line.
> (c) rasterized outlines (not filled) of the same
>
> I'm wondering if anyone has any recommendations for the best way to
> do this in ITK.
>
> Specifically:
> First, what would be the best data structure to represent 2D shapes
> geometrically within ITK? With itk::Mesh or
> itk::PolyLineParametricPath? What are the benefits/drawbacks of each?
>
> Second, what's the best approach for the following conversions:
> (a to b: mask to mesh) I presume I'd need some sort of "marching
> squares" algorithm to do this right. Is there anything of the sort in
> ITK (or another way)? All I see is the BinaryMask3DMeshSource, which
> is, obviously, just for 3D.
>
> (a to c: mask to outline) Either go through an itk::ParametricPath
> intermediate and use the Breshenham line iterator (which I hope to be
> in ITK soon) or similar, or pre-process the binary image and use the
> itk::ZeroCrossingImageFilter to get the appropriate contour. Which
> seems best?
>
> (b to a: mesh to mask) If I'm using a 2D mesh, presumably the
> existing ITK mesh to image filters would work? Or is there a better
> 2D polygon rasterizer to use? On the other hand, is there a simple
> way to do this from the parametric path representation?
>
> (b to c: mesh to outline) If I'm using the parametric path, this
> seems easy (as above with the iterator), but hard if using a mesh.
> Are there mesh-to-surface (rather than mesh to volume) filters in ITK?
>
>
> Any thoughts on how best to approach this with ITK?
>
> Thanks,
>
> Zach Pincus
>
> Program in Biomedical Informatics and Department of Biochemistry
> Stanford University School of Medicine
>
> _______________________________________________
> 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