Home > database >  How to get the convex hull of a binary image using DIPlib in C ?
How to get the convex hull of a binary image using DIPlib in C ?

Time:09-26

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?

CodePudding user response:

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.

  • Related