How to create a binary mask from coordinates (indexes or physical)

I am new to ITK , I am using SimpleITK in C#.
I have planar closed contour , a set of coordinates. What I need to do is create a binary mask with the same dimensions spacing and origin as the original ITK Image.
I am not sure which filters would be the correct ones to use for this purpose.
I have tried to perform this task using VTK with limited success

Any help and pointers would be greatly appreciated

Thank you

Hello @Ervis,

ITK and SimpleITK do not support this type of operation (polygon rasterization).

You were looking in the right place, VTK. Have you tried asking on the vtk discourse? I suspect there are other C# libraries that allow you to drawPolygon/fillPolygon.

Once you have the polygon in a buffer you can copy it over to a SimpleITK image.

1 Like

What is wrong with vtkPolyDataToImageStencil? Or its cousin vtkLassoStencilSource? Possibly relevant old discussion.

The issue with vtkPolyDataToImageStencil is that it seems to create artifacts, even thought the contour region is 100% fully closed. What seems to me to be random is entire lines missing from the contours ,for example :


You are probably better off trying to fix those bugs in VTK, than to write your own implementation.