Use of Mask Image filter in liver segmentation


I would like to segment the liver. I used different algorithms in 3D data.
But i am unable to get exact liver part in my output. Other regions are also coming.
I tried using “maskImagefilter”. but I am getting following error.

itk::ERROR: MaskImageFilter(0x20a65e0): Inputs do not occupy the same physical space!
InputImage Origin: [-1.5567578e+02, -3.2567578e+02], InputImage_1 Origin: [0.0000000e+00, 0.0000000e+00]
Tolerance: 6.4843750e-07
InputImage Spacing: [6.4843750e-01, 6.4843750e-01], InputImage_1 Spacing: [1.0000000e+00, 1.0000000e+00]
Tolerance: 6.4843750e-07

Aborted (core dumped)

Could you please tell me the solution?
And I am unable to understand how to use this mask image filter in my confidence connected algorithm.
Also to avoid over-segmentation, is there any other solution?

Thanks in advance.

Segmenting a liver is not easy! As of today, precise and reliable segmentation of the liver is still an unsolved problem. But if you provide some demonstrative slices of your data (both input and result) along with your source code, we might be able to give some advice.

To apply mask filter to an image, the mask and the filter have to align in both index space (number of pixels/dimensions) and physical space (origin, spacing, direction). If you are sure that the mask fits your input, you can ensure alignment by using maskImage->CopyInformation(inputImage);

I was also thinking about applying ITK to liver segmentation.
But, I discovered a decent liver model under Model Zoo.
Since then, I applied inference on new CT volumes with good success.
The neural network is very large, so I use AWS with a big CPU/GPU (~69 GB between CPU/GPU).

Please see:


(I updated the Python script load and store DICOM volumes).

Please ask any questions.


Thank you for your reply.
Sorry for my late reply.
ConnectedThresholdImageFilter.cxx (5.3 KB)
IMG020 (515.3 KB)

Here I have attached my connected threshold image filter program and input slice and result.
Here its actually i am providing series but could not send you all slices of my series here and respective result.
I am getting other regions also, so how can I get rid of those regions and only get liver part?
Is mask image filter useful for it? And if yes, how to use it in my program? I am unable to understand it.
And if no, what should I use?
Thanks in advance.

The connected threshold filter is good when the structure of interest is disconnected from other structures with similar pixel intensities, or when there are no other structures with similar pixel intensities in the image. For example, it can be used to segment bones in a CT image.

But liver is a grayish tissue in CT, connected to many other grayish tissues in the abdomen, so you end up segmenting all of them.

In 2007, a challenge was organized to segment the liver. You can read more about the methods used and their results on the challenge’s website.