How to load image mask and apply mask?


I’m trying to load image mask for X-Ray 2D/3D registration to help improve registration performance on C-ARM shots. The image mask will help the algorithm ignore C-ARM image artifacts and focus on the vertebral body.

I want to use ExplicitMask for my application since I will be provided with an image mask. What is the correct way to initialize image mask? I noticed two functions that seemed relevant to my goasl. The first being the aforementioned ExplicitMask().

Currently I’m trying to define my ExplicityMask() using the following code block:

    std::string mask_path = "path to jpg";
    std::unique_ptr<ImFusion::MemImage> mask_mem = ImFusion::PngIO::readImage(mask_path);
    auto explicit_mask = ImFusion::ExplicitMask::convert((*mask_mem));

Unfortunately when I read the third line of this code block. It throws a [IO.PngIO] Bad file header error and crashes. What is the correct way to define an ExplicitMask()?

The other function that seems relevant to my goal is MaskEditor(). But I didn’t see any function that lets me explicitly load Mask() objects. Do I use MaskEditor(image) where image is the input mask image?

I fixed my crash. It was because I was using a jpg as input to ImFusion::PngIO::readImage(). The rest of the code block works as normal.

I then used ImFusion::SharedImageSet::setMask() and explicit_mask as input to set my mask for my ImFusion::SharedImageSet variable. Now it’s working as expected.