# Geodesic Active contour Level set image filter error

**URL:** <https://discourse.itk.org/t/geodesic-active-contour-level-set-image-filter-error/2182>\
**Category:** Uncategorized\
**Created:** [August 21, 2019, 10:58am UTC](https://discourse.itk.org/t/geodesic-active-contour-level-set-image-filter-error/2182 "2019-08-21T10:58:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pooja\_Virkar](https://discourse.itk.org/user_avatar/discourse.itk.org/pooja_virkar/32/804_2.png) [@Pooja\_Virkar](https://discourse.itk.org/u/Pooja_Virkar)\
**Post date:** [August 21, 2019, 10:58am UTC](https://discourse.itk.org/t/geodesic-active-contour-level-set-image-filter-error/2182/1 "2019-08-21T10:58:17Z")

</div>

Hello,  
I am trying to use Geodesic Active contour Level set image filter from  
[https://itk.org/ITKExamples/src/Segmentation/LevelSets/SegmentWithGeodesicActiveContourLevelSet/Documentation.html](https://itk.org/ITKExamples/src/Segmentation/LevelSets/SegmentWithGeodesicActiveContourLevelSet/Documentation.html)

First I was trying to work with only one dicom image. And now working with 3D series of slices . But got the same following error.

Exception thrown while writing the series

itk::ExceptionObject (0x558e6c20f260)  
Location: “void itk::ImageToImageFilter\<TInputImage, TOutputImage\>::VerifyInputInformation() const [with TInputImage = itk::Image\<float, 3\>; TOutputImage = itk::Image\<float, 3\>]”  
File: /usr/local/include/ITK-5.0/itkImageToImageFilter.hxx  
Line: 233  
Description: itk::ERROR: GeodesicActiveContourLevelSetImageFilter(0x558e6c203290): Inputs do not occupy the same physical space!  
InputImage Origin: [-1.9612988e+02, -3.3912988e+02, -9.7220000e+02], InputImageInitialImage Origin: [0.0000000e+00, 0.0000000e+00, 0.0000000e+00]  
Tolerance: 7.4023437e-07  
InputImage Spacing: [7.4023438e-01, 7.4023438e-01, 1.0000000e+00], InputImageInitialImage Spacing: [1.0000000e+00, 1.0000000e+00, 1.0000000e+00]  
Tolerance: 7.4023437e-07

I don’t understand why is it coming.  
Anyone knows what is the solution.  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![spic](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/ea5d25/32.png) [@spic](https://discourse.itk.org/u/spic)\
**Post date:** [August 21, 2019, 4:07pm UTC](https://discourse.itk.org/t/geodesic-active-contour-level-set-image-filter-error/2182/2 "2019-08-21T16:07:24Z")

</div>

Both the origin and spacing of your two images ‘InputImage’ and ‘InputImageInitialimage’ are different. Therefore, the error ’ inputs do not occupy the same physical space!’. I suggest you start with looking at functions [set origin](https://itk.org/Doxygen/html/classitk_1_1ImageBase.html#a5b7e6ce4460e24b2dbc6b1ac60f971cd) and [set spacing](https://itk.org/Doxygen/html/classitk_1_1ImageBase.html#abafd7d6888ce30ce02b4fe8079f754b7). Hope this helps.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [August 21, 2019, 4:50pm UTC](https://discourse.itk.org/t/geodesic-active-contour-level-set-image-filter-error/2182/3 "2019-08-21T16:50:43Z")

</div>

The example works for me with following arguments: `C:\Dev\ITKExamples\Build\src\Segmentation\LevelSets\SegmentWithGeodesicActiveContourLevelSet\BrainProtonDensitySlice.png C:/a/LeftVentricle.png 81 114 5.0 1.0 -0.5 3.0 2.0 100`

It looks like you modified the source code to run in 3D. Can you share it?

---

<div class="post-metadata">

**Author:** ![Pooja\_Virkar](https://discourse.itk.org/user_avatar/discourse.itk.org/pooja_virkar/32/804_2.png) [@Pooja\_Virkar](https://discourse.itk.org/u/Pooja_Virkar)\
**Post date:** [August 22, 2019, 9:12am UTC](https://discourse.itk.org/t/geodesic-active-contour-level-set-image-filter-error/2182/4 "2019-08-22T09:12:57Z")

</div>

the code is working with PNG file. But not with DICOM.

1. First I have tried this example with only single DICOM image. Just added GDCMIO in my code.  
These are my arguments -  
./GeodesicActiveContourLevelSet IMG075.dcm contour.dcm 81 114 5.0 1.0 -0.5 3.0 2.0 100

And I got following Error:  
itk::ExceptionObject (0x55d65388f360)  
Location: “void itk::ImageToImageFilter\<TInputImage, TOutputImage\>::VerifyInputInformation() const [with TInputImage = itk::Image\<float, 2\>; TOutputImage = itk::Image\<float, 2\>]”  
File: /usr/local/include/ITK-5.0/itkImageToImageFilter.hxx  
Line: 233  
Description: itk::ERROR: GeodesicActiveContourLevelSetImageFilter(0x55d65388e630): Inputs do not occupy the same physical space!  
InputImage Origin: [-1.9631494e+02, -3.3931494e+02], InputImageInitialImage Origin: [0.0000000e+00, 0.0000000e+00]  
Tolerance: 3.7011700e-07  
InputImage Spacing: [3.7011700e-01, 3.7011700e-01], InputImageInitialImage Spacing: [1.0000000e+00, 1.0000000e+00]  
Tolerance: 3.7011700e-07

Is it problem with my data type?  
I am getting those Output1.png, output2.png, output3.png in my directory. But not output4.png. why?  
If I am working with DICOM images, then what changes should I do in my code?

---

<div class="post-metadata">

**Author:** ![Pooja\_Virkar](https://discourse.itk.org/user_avatar/discourse.itk.org/pooja_virkar/32/804_2.png) [@Pooja\_Virkar](https://discourse.itk.org/u/Pooja_Virkar)\
**Post date:** [August 22, 2019, 9:28am UTC](https://discourse.itk.org/t/geodesic-active-contour-level-set-image-filter-error/2182/5 "2019-08-22T09:28:28Z")

</div>

Yes I have modified the code to work with Volume of DICOM slices.  
Here i have attached it.  
[GeodesicActiveContourLevelSetImageFilter3d.cxx](https://discourse.itk.org/uploads/short-url/8QUemUYHU4ZhyMGcesJ9jDwhVfB.cxx) (7.2 KB)

Could you please check the code and tell me what is wrong with it?  
Because I am getting the same error i have mentioned before. (problem with physical space)

---

<div class="post-metadata">

**Author:** ![Pooja\_Virkar](https://discourse.itk.org/user_avatar/discourse.itk.org/pooja_virkar/32/804_2.png) [@Pooja\_Virkar](https://discourse.itk.org/u/Pooja_Virkar)\
**Post date:** [August 22, 2019, 9:43am UTC](https://discourse.itk.org/t/geodesic-active-contour-level-set-image-filter-error/2182/6 "2019-08-22T09:43:21Z")

</div>

Could you please tell me how to do use those functions? Should I need to change my Input image origin and set it to 0)?  
How to do it?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [August 26, 2019, 7:46pm UTC](https://discourse.itk.org/t/geodesic-active-contour-level-set-image-filter-error/2182/7 "2019-08-26T19:46:17Z")

</div>

It is likely that your DICOM file has non-identity index to physical transform matrix, and that is causing the problem.

When I try the original example, but as an input use .nrrd file which has slightly modified meta-data, I run into the issue too.

Proposed solution is in [PR 126](https://github.com/InsightSoftwareConsortium/ITKExamples/pull/126).

---

<div class="post-metadata">

**Author:** ![Pooja\_Virkar](https://discourse.itk.org/user_avatar/discourse.itk.org/pooja_virkar/32/804_2.png) [@Pooja\_Virkar](https://discourse.itk.org/u/Pooja_Virkar)\
**Post date:** [August 27, 2019, 1:55pm UTC](https://discourse.itk.org/t/geodesic-active-contour-level-set-image-filter-error/2182/8 "2019-08-27T13:55:37Z")

</div>

Thank you. It solved the issue.  
But I am unable to understand how to set the values of sigma, alpha and beta?  
I am trying to use this geodesic active contour level set image filter to segment the liver.  
I have tried different values but still unable to achieve the good result.  
Do you have any tips for how to select the values for sigma, alpha & beta?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [August 27, 2019, 2:31pm UTC](https://discourse.itk.org/t/geodesic-active-contour-level-set-image-filter-error/2182/9 "2019-08-27T14:31:05Z")

</div>

The best advice in these kind of cases is to read the paper which the method implements, in this case [“Geodesic Active Contours”, V. Caselles, R. Kimmel and G. Sapiro. International Journal on Computer Vision, Vol 22, No. 1, pp 61-97, 1997](https://www.researchgate.net/profile/Ron_Kimmel/publication/220660519_Geodesic_Active_Contours/links/0deec5205542c8cffa000000/Geodesic-Active-Contours.pdf). Reading the paper usually helps you understand the parameters. Then you have to experiment with different values.

---

<div class="post-metadata">

**Author:** ![Pooja\_Virkar](https://discourse.itk.org/user_avatar/discourse.itk.org/pooja_virkar/32/804_2.png) [@Pooja\_Virkar](https://discourse.itk.org/u/Pooja_Virkar)\
**Post date:** [August 28, 2019, 9:08am UTC](https://discourse.itk.org/t/geodesic-active-contour-level-set-image-filter-error/2182/10 "2019-08-28T09:08:13Z")

</div>

Okay. I will check it.  
The code which I sent before which I modified to run in 3D, is it correct?  
Could you please check that, and let me know where it has mistakes or not?  
& what changes should I need to do?  
Thank you so much.

---

<div class="post-metadata">

**Author:** ![Oddone-Scatena](https://discourse.itk.org/user_avatar/discourse.itk.org/oddone-scatena/32/2651_2.png) [@Oddone-Scatena](https://discourse.itk.org/u/Oddone-Scatena)\
**Post date:** [March 15, 2022, 1:26am UTC](https://discourse.itk.org/t/geodesic-active-contour-level-set-image-filter-error/2182/11 "2022-03-15T01:26:59Z")

</div>

> [@Pooja\_Virkar](#):
>
> The code which I sent before which I modified to run in 3D, is it correct?  
> Could you please check that, and let me know where it has

Greatings I implemented your 3D code. I think it is correct since I wrote a similar code for Connected Threshold Image Filter in 3D.

I am getting segmentation fault with this one  
Should I change the parameters?

 ![geodesic](https://discourse.itk.org/uploads/default/original/2X/c/c7b8a9c1370674f9a7e82051ec9ae25d51543959.png)  
(in Portuguese)
