1

I have a stack of binary images of an open porous structure and I want to get a binary mask which covers the whole volume of the structure (the structure itself and the void contained in the structure). I think a good way to achieve my goal would be to calculate the convex hull of the image. This works fine in Python using skimage.morphology.convex_hull_image (see images).

input

result

But I need this functionality in C++ and I want to use the DIPlib library. Unfortunately I'm struggeling with the correct implementation since the documentation confuses me a bit.

  1. Could you provide a minimal example which explains how to derive the the convex hull of a binary object as an image?
  2. Does the DIPlib implementation also handle 3D images?
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
Phtagen
  • 121
  • 10
  • Why not use a C++ library that deals with Delaunay Triangles and insert the white pixels as points? It will give you the convex hull. – alvrm Sep 23 '22 at 19:51

1 Answers1

1

You'd want to use the function dip::MakeRegionsConvex2D(). For example:

dip::Image img = dip.ImageRead('yIFuP.jpg');
dip::Image bin = img > 128;  // assuming img is scalar
dip::MakeRegionsConvex2D(bin, bin);

This function is explicitly written for 2D images, and will not work for 3D images.

For a 3D image, I would get a list of the coordinates of all set pixels (use dip::Find), and pass that into a quickhull algorithm implementation such as the one in CGAL, then draw the resulting 3D polyhedron into the image. This last step might be the most challenging one (I don't know if CGAL has functionality to render a polyhedron to an image). The quick and dirty solution would be to iterate over all pixels, and for each do a in/out test, set the pixel if it's inside the polyhedron.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
  • 1
    Thank you very much, this really helps a lot. I would like to mention that this feature seems to have been implemented only recently in the latest version of DIPlib, namely version 3.3. I still was on version 3.1 or so and wondered why it didn't work at first. But upgrading to the latest version solved the issue. – Phtagen Sep 24 '22 at 17:34