Perform graph cut

I intend to use graph cut segmentation on a VTK volume, and I saw few examples on github. But all these examples are using images (background and foreground images) as masking for graph cut … what should I use for VTK volume, because in this case I don’t have “images” as mask …

Do you know any place from where I can inspire for this task ?

Thank you.

P.S. Or, what is the best approach to cut a little piece from a vtk volume ?

Having “foreground” and “background” seeds is the essence of graph-cut methods. They can be somewhat adapted, e.g. to only have the user place one seed point in 2D or 3D.

If you don’t have seeds, you need to construct them somehow. Or just don’t use graph cuts.

You mean 3D volume? If you have a VTK image you need to convert it to ITK in order to apply ITK filters.

We might have advice if you show us example input image and desired result (you can do that manually). Or at least describe it more thoroughly.

I have a vtkVolume, and I have methods that convert vtkVolume into SimpleITK (sitk::Image) not ITK !!! because working with SimpleITK is much faster than ITK :slight_smile: .

I can take any point from 3d vtkVolume through vtkVolumePicker or vtkCellPicker, whatever … now, I don’t know how to use them into graph cut algorithm, because I’ve found on github some code from here I can inspire, but that code uses images as foreground and background, but not points…

Here is my model: https://github.com/daviddoria/ImageGraphCutSegmentation

Here is my vtkVolume sample (a CBCT):

image

I can pick a 3D point as I said before with vtkCellPicker or vtkVolumePicker, but I don’t know how to use them to cut a tooth from there … I was thinking to use graph cut …

Get 3D coordinates of the point from VTK picking, and then you should be able to use them in ITK as physical coordinates. If you are using VTK 8.2 or earlier, you will need to take special care if direction matrix is non-identity.

Use TransformPhysicalPointToIndex if you want to get ITK index. Then put a seed there or around a small neighborhood of that voxel.

1 Like

@flaviu2 before you start implementing anything, I would recommend to try existing tools in various open-source software. Once you confirmed what algorithm fulfills your needs, you can start thinking about the final implementation.

3D Slicer has many segmentation tools (automatic, semi-automatic, and manual) in its Segment Editor module that you can easily try. For example, its “Grow from seeds” effect uses a variant of grow-cut algorithm that is optimized for 3D medical image segmentation. It is expected to work better than a generic graph cut implementation. See tutorials of this and the many other segmentation tools here. You can also easily make new segmentation tools out of SimpleITK and VTK filters (you can use existing effects as examples - they are all based on ITK and VTK filters).

For bone segmentation, you’ll also need tools to solidify segments (to remove internal holes and surface discontinuities).

There are a number of Slicer forum members that are experienced in teeth and CMF bone segmentation, so it you have a specific clinical problem to solve then you may ask the experts there.

2 Likes

Thank you both for your work @lassoan and @dzenanz.

I’m trying to implement FastGrowCut for my project, using C++ in MSVC.

I’m currently using both VTK and ITK across the project, this section is in the middle of my pipeline so I could use either. I’m just having trouble building either VTK version in slicer or the ITK version that I can see @dzenanz has been working on. I think my issue is similar in both

VTK/Slicer: Using the source Andras linked previously Algorithm used for growing seeds - Support - 3D Slicer Community
I am trying to compile growcut.cxx (attached - with error message)

Using vtkimagegrowcutsegment.h and vtkimagegrowcutsegment.hxx
If I try to compile the code as is I get

  • Cannot open include file: ‘vtkSlicerSegmentationsModuleLogicExport.h’: No such file or directory

I have tried replacing:

class VTK_SLICER_SEGMENTATIONS_LOGIC_EXPORT vtkImageGrowCutSegment : public vtkImageAlgorithm
with
#include “vtkCommonExecutionModelModule.h”
//…
class VTKCOMMONEXECUTIONMODEL_EXPORT vtkImageGrowCutSegment : public vtkImageAlgorithm

and then I get the error attached.
The program compiles successfully if I comment out the growcut block of text, to just read and write a file

In ITK
Similarly the code wouldn’t compile out of the box, I removed some of the wrapping files which I don’t need and tried to simplify the CMake file
The compilation fails saying that it cannot find #include “GrowCutExport.h”

VTK_VERSION: 8.2.0
ITK 5.2
MSVC-X64
GrowCut Error.txt (2.7 KB)

I can’t locate either of these .h files on gitbub, are they not actually files with code but part of the macro exporting function? Do you have any tips on how I can get this code working

GrowCut can be compiled like any other remote module:

  1. compile ITK
  2. compile remote module pointing to the ITK build tree
  3. compile your app pointing to ITK build tree (you should be able to include/use stuff from the remote module without any issue or any additional setup)

GrowCutExport.h is a file generated during compilation of the remote module.

The header file that you miss is generated automatically (contains the export macro). If you only need to use the class in the same target then you can just remove the export macro and the include directive.

In the long term I would definitely recommend using the filter in ITK. I think currently, the ITK implementation still uses a very old version of this algorithm that is several times slower, uses much more memory, and lacks the very useful masking feature, compared than the one in Slicer.

@dzenanz it would be great if you could port all the optimizations from Slicer (or simply replace the internals of the current implementation with Slicer’s). Then we could switch to the ITK implementation and implement all further improvements there (adding spatial smoothness constraint, adding an option to provide extra cost image, improve multithreading, etc).

I definitely plan that. We are now in the funding gap between year 1 and year 2. As soon as the funding for Y2 comes, I will pick up that work.

1 Like