# Contouring with having initial curve using filters in Simple ITK module?

**URL:** <https://discourse.slicer.org/t/contouring-with-having-initial-curve-using-filters-in-simple-itk-module/20810>\
**Category:** Support\
**Created:** [November 27, 2021, 1:41pm UTC](https://discourse.slicer.org/t/contouring-with-having-initial-curve-using-filters-in-simple-itk-module/20810 "2021-11-27T13:41:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahrokh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shahrokh/32/1499_2.png) [@shahrokh](https://discourse.slicer.org/u/shahrokh)\
**Post date:** [November 27, 2021, 1:41pm UTC](https://discourse.slicer.org/t/contouring-with-having-initial-curve-using-filters-in-simple-itk-module/20810/1 "2021-11-27T13:41:33Z")

</div>

**Hello Dear Developers and Users**

I want to segment or contour the pelvis.  
Consider the following figure. This screenshot contains a 2D image of EPID, named _EPID_.

 ![EPID](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/1/e171204995ecc74235b674f60b8a7c227dc6707f.png)

Consider the following figure. This screenshot contains the contour of the pelvic bone extracted from the DRR image named _contourDRR_, using filters such as **ClosingByReconstructionImageFilter** , **OpeningByReconstructionImageFilter** and **ZeroCrossingBasedEdgeDetectionImageFilter** in **Simple ITK** module.

 ![contourDRR](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/f/1f26e2462539c4323887706667ad3e93652c1e10.png)

 ![contourANDEPID](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/8/183e2b23d01b31389b6391ac7d39c0130a4dd3de.png)

I would like to consider this contour (_contourDRR_) as a starting point (initial contour) and using, for example, the filter of **geodesicActiveContourLevelSetImageFilter** in **Simple ITK** module, it is deformable to match the edge of the pelvis in the EPID image (_EPID_).  
In other words, I want to use active contour with matching this initial contour (_contourDRR_) on the edges of pelvis in _EPID_.  
Unfortunately, after using this filter, I took an output image that had all the pixels equal to one.

How can I do this contouring with initial contour?  
Please guide me to do it.  
Best regards.

Shahrokh

---

<div class="post-metadata">

**Author:** ![shahrokh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shahrokh/32/1499_2.png) [@shahrokh](https://discourse.slicer.org/u/shahrokh)\
**Post date:** [November 27, 2021, 2:30pm UTC](https://discourse.slicer.org/t/contouring-with-having-initial-curve-using-filters-in-simple-itk-module/20810/2 "2021-11-27T14:30:14Z")

</div>

Details:

EPID information:  
Image Dimension: 611 576 1  
Image Spacing: 0.25mm 0.25mm 1.00mm

contourDRR Information:  
Image Dimension: 270 256 1  
Image Spacing: 0.5859mm 0.5859mm 1.0000mm

With these specifactions, at firstly I made the same type these volumes (EPID and contourDRR) to Double. Then I applied **geodesicActiveContourLevelSetImageFilter.** I get the following error message:

_Exception thrown in SimpleITK GeodesicActiveContourLevelSetImageFilter\_Execute: /work/Preview/Slicer-0-build/SimpleITK/Code/BasicFilters/src/sitkImageFilter.cxx:63:_

_sitk::ERROR: Input “featureImage” for “GeodesicActiveContourLevelSetImageFilter” has size of [270, 256, 1] which does not match the primary input’s size of [611, 576, 1]!_

So I use the module of **General Registration (ANTs)** to unify the specifications of these volumes (EPID and contourDRR).

**Inputs:**  
Fixed Image: EPID  
Moving Image: contourDRR  
Stages (Presets): Rigid  
**Setting:**  
Computation Precision: double  
**Outputs:**  
Transformed Volume: ContourDRRTRansformed

I get the following result:  
EPID information:  
Image Dimension: 611 576 1  
Image Spacing: 0.25mm 0.25mm 1.00mm  
ContourDRRTRansformed Information:  
Image Dimension: 611 576 1  
Image Spacing: 0.25mm 0.25mm 1.0000mm

At now, I run **geodesicActiveContourLevelSetImageFilter** on these volumes: EPID and ContourDRRTRansformed nodes.I get the following error message:

_Exception thrown in SimpleITK GeodesicActiveContourLevelSetImageFilter\_Execute: /work/Preview/Slicer-0-build/ITK/Modules/Filtering/ImageFilterBase/include/itkRecursiveSeparableImageFilter.hxx:227:_

_ITK ERROR: RecursiveGaussianImageFilter(0x7f8d78567a40): The number of pixels along direction 2 is less than 4. This filter requires a minimum of four pixels along the dimension to be processed._

I do not know to add three slices (exactly one or copy) in the direction of IS in 3DSlicer. For doing it, I save these volumes ( **EPID and ContourDRRTRansformed** ) in nifti format and use **medcon** for example with following commands:

```auto
$ cp ContourDRRTRansformed.nii ContourDRRTRansformed1.nii
$ cp ContourDRRTRansformed.nii ContourDRRTRansformed2.nii
$ cp ContourDRRTRansformed.nii ContourDRRTRansformed3.nii
$ cp ContourDRRTRansformed.nii ContourDRRTRansformed3.nii
$ medcon -f ContourDRRTRansformed1.nii ContourDRRTRansformed2.nii ContourDRRTRansformed3.nii ContourDRRTRansformed4.nii -stack3d -c nii
...
$ cp EPID.nii EPID1.nii
$ cp EPID.nii EPID2.nii
$ cp EPID.nii EPID3.nii
$ cp EPID.nii EPID3.nii
$ medcon -f EPID1.nii EPID2.nii EPID3.nii EPID4.nii -stack3d -c nifti

```

**Result:**  
EPID information:  
Image Dimension: 611 576 4  
Image Spacing: 0.25mm 0.25mm 1.00mm  
contourDRR Information:  
Image Dimension: 611 576 4  
Image Spacing: 0.25mm 0.25mm 1.00mm

After doing it, I again I run **geodesicActiveContourLevelSetImageFilter** on these volumes: EPID and ContourDRRTRansformed. As mentioned in my previous message, unfortunately, after using this filter, I took an output image that had all the pixels equal to one.

Please guide me to solving this problem.  
Thanks.  
Shahrokh

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 28, 2021, 5:32am UTC](https://discourse.slicer.org/t/contouring-with-having-initial-curve-using-filters-in-simple-itk-module/20810/3 "2021-11-28T05:32:17Z")

</div>

You can use “Resample Scalar/Vector/DWI Volume” to resample the contourDRR image to match the geometry of the EPID image, but setting the contourDRR as input image and the EPID as reference image.

---

<div class="post-metadata">

**Author:** ![shahrokh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shahrokh/32/1499_2.png) [@shahrokh](https://discourse.slicer.org/u/shahrokh)\
**Post date:** [November 28, 2021, 10:48am UTC](https://discourse.slicer.org/t/contouring-with-having-initial-curve-using-filters-in-simple-itk-module/20810/4 "2021-11-28T10:48:11Z")

</div>

Thanks a lot for your guidance.

I used the module of **Resample Scalar/Vector/DWI Volume** to match the geometry of _contourDRR_ image with _EPID_ image (as you mentioned, I set _contourDRR_ and _EPID_ as Input Volume and Reference Volume respectively). After running it, I have new volume node with the name of _contourDRR2_ which is geometrically matched with the _EPID_ image.

But I’m sorry, I still have two major and minor problems:

_ **Major problem:** _  
How can I use a binary image containing the contour of an organ (such as _contourDRR2_) as the initial curve using **Simple ITK** filter, based on the **active contour** technique, to extract the contour in a gray scale image (_EPID_)? As mentioned above, I have two images _contourDRR2_ (binary images) and _EPID_ (graycale image) which are geometrically matched with ‌each other. I used the filter of **geodesicActiveContourLevelSetImageFilter** to deform this initial contour so that the result of this deformation (for example using this filter) is a contour that matches the edge of the pelvis in the _EPID_ image.

_ **Minor problem:** _  
How do I generate four axial slices that are exactly the same as a original slice and are in a row in the IS direction?  
For example, I have ContourDRR2 with the following specifications:  
Image Dimension: 611 576 1  
…  
How can I convert this image with the following specifications:  
Image Dimension: 611 576 4  
…  
Best regards.  
Shahrokh

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 28, 2021, 12:53pm UTC](https://discourse.slicer.org/t/contouring-with-having-initial-curve-using-filters-in-simple-itk-module/20810/5 "2021-11-28T12:53:58Z")

</div>

> [@shahrokh](#):
>
> How can I use a binary image containing the contour of an organ (such as _contourDRR2_ ) as the initial curve

Probably the best would be to ask this from the developers of these algorithms on the [ITK forum](https://discourse.itk.org).

> [@shahrokh](#):
>
> How do I generate four axial slices that are exactly the same as a original slice and are in a row in the IS direction?

You can use a resampling module for this, setting the spacing along IS direction to 1/4 of the original and the IS extent of the image to 4.

---

<div class="post-metadata">

**Author:** ![shahrokh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shahrokh/32/1499_2.png) [@shahrokh](https://discourse.slicer.org/u/shahrokh)\
**Post date:** [November 28, 2021, 1:27pm UTC](https://discourse.slicer.org/t/contouring-with-having-initial-curve-using-filters-in-simple-itk-module/20810/6 "2021-11-28T13:27:29Z")

</div>

Thank a lot for your guidance and refer to ITK forum. I raise my problem there.  
Best regards.  
Shahrokh
