# How to segment the thin skin edge of body parts?

**URL:** <https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078>\
**Category:** Uncategorized\
**Created:** [July 22, 2019, 5:21pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078 "2019-07-22T17:21:57Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![srbn.ghosh89](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@srbn.ghosh89](https://discourse.itk.org/u/srbn.ghosh89)\
**Post date:** [July 22, 2019, 5:21pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/1 "2019-07-22T17:21:57Z")

</div>

I have 3D image slices of chest. I only want to get the outer skin surface of the chest which will exclude all the organs inside. What kind of segmentation can be applied to get only the skin surface? ![chest](https://discourse.itk.org/uploads/default/original/1X/09e6120b6773ea93970ea6b1d5707d13968b0fde.png)

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [July 22, 2019, 6:07pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/2 "2019-07-22T18:07:58Z")

</div>

One option is to propagate the skin boundary, found with thresholding, from boundary with a fast marching or level set filter.

---

<div class="post-metadata">

**Author:** ![srbn.ghosh89](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@srbn.ghosh89](https://discourse.itk.org/u/srbn.ghosh89)\
**Post date:** [July 22, 2019, 6:29pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/3 "2019-07-22T18:29:16Z")

</div>

The pixel values of boundary and pixel values of internal organs same. There is no limit difference of pixel values.

Still your approach is possible?

---

<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:** [July 22, 2019, 7:46pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/4 "2019-07-22T19:46:47Z")

</div>

You could do threshold segmentation, shrink it using [morphological erosion](https://itk.org/Doxygen/html/classitk_1_1BinaryErodeImageFilter.html), then subtract the two - you should be left with a single layer corresponding to outermost part of skin.

If you want your skin to have varying thickness, you could do a few iterations of seeded region growing, starting from the thin skin. You would probably need to modify some existing filters to accomplish this.

Or you could provide even more eroded version of the torso as negative seeds for [IsolatedConnectedImageFilter](https://itk.org/Doxygen/html/classitk_1_1IsolatedConnectedImageFilter.html).

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [July 22, 2019, 9:53pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/5 "2019-07-22T21:53:04Z")

</div>

> [@srbn.ghosh89](#):
>
> The pixel values of boundary and pixel values of internal organs same. There is no limit difference of pixel values.
> 
> Still your approach is possible?

The skin edges can be used to constrain the segmentation.

---

<div class="post-metadata">

**Author:** ![srbn.ghosh89](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@srbn.ghosh89](https://discourse.itk.org/u/srbn.ghosh89)\
**Post date:** [July 23, 2019, 9:24pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/6 "2019-07-23T21:24:37Z")

</div>

Thank You. How to subtract two images. Is there any example in itk?

---

<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:** [July 23, 2019, 9:44pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/7 "2019-07-23T21:44:54Z")

</div>

[SubtractImageFilter](https://itk.org/Doxygen/html/classitk_1_1SubtractImageFilter.html)’s documentation links to many examples.

---

<div class="post-metadata">

**Author:** ![srbn.ghosh89](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@srbn.ghosh89](https://discourse.itk.org/u/srbn.ghosh89)\
**Post date:** [July 24, 2019, 8:20pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/8 "2019-07-24T20:20:58Z")

</div>

I used BinaryErodeImageFilter on the image and then did the subtraction from the original to BinaryErodeImageFiltered one using the following code. I am getting the same output. Can you please check what I am doing wrong?

```auto
int main( int argc, char *argv[] )
{

  const unsigned int Dimension = 3;
  typedef signed short PixelType;
  typedef itk::Image< PixelType, Dimension >FixedImageType;
  typedef itk::Image< PixelType, Dimension >MovingImageType;

  // Software Guide : EndCodeSnippet
  typedef itk::ImageFileReader< FixedImageType >FixedImageReaderType;
  typedef itk::ImageFileReader< MovingImageType >MovingImageReaderType;
  FixedImageReaderType::Pointer fixedImageReader = FixedImageReaderType::New();
  MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New();
  fixedImageReader->SetFileName( "E:\\Programs\\Morphological Erosion\\input.nii" );
  movingImageReader->SetFileName( "E:\\Programs\\Morphological Erosion\\output.nii" );
  typedef itk::SubtractImageFilter<
                                  FixedImageType,
                                  FixedImageType,
                                  FixedImageType >DifferenceFilterType;
  DifferenceFilterType::Pointer difference = DifferenceFilterType::New();
  difference->SetInput1( fixedImageReader->GetOutput() );
  difference->SetInput2( movingImageReader->GetOutput() );

  typedef signed short OutputPixelType;
  typedef itk::Image< OutputPixelType, Dimension >OutputImageType;
  typedef itk::ImageFileWriter< OutputImageType >WriterType;
  WriterType::Pointer writer = WriterType::New();

  writer->SetFileName( "diff.nii");

  writer->SetInput( difference->GetOutput() );
  writer->Update();

  return EXIT_SUCCESS;
}

```

---

<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:** [July 24, 2019, 8:25pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/9 "2019-07-24T20:25:49Z")

</div>

In your code snippet, you only show the subtraction. That looks OK.

Can you show us the code for erosion? And an interesting slice (e.g. one from the first post) from stages: input, segmentation, erosion and subtraction?

---

<div class="post-metadata">

**Author:** ![srbn.ghosh89](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@srbn.ghosh89](https://discourse.itk.org/u/srbn.ghosh89)\
**Post date:** [July 24, 2019, 8:27pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/10 "2019-07-24T20:27:29Z")

</div>

Thank you for your response. This is the code of the morphological erosion.

```auto
int main(int argc, char *argv[])
{
 
  unsigned int radius = 2;
  typedef itk::Image<unsigned char, 3>ImageType;
  typedef itk::ImageFileReader<ImageType>ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName("input.nii");
  typedef itk::BinaryBallStructuringElement<
    ImageType::PixelType, 3>StructuringElementType;
  StructuringElementType structuringElement;
  structuringElement.SetRadius(radius);
  structuringElement.CreateStructuringElement();
  typedef itk::BinaryErodeImageFilter <ImageType, ImageType, StructuringElementType>BinaryErodeImageFilterType;
  BinaryErodeImageFilterType::Pointer erodeFilter
    = BinaryErodeImageFilterType::New();
  erodeFilter->SetInput(reader->GetOutput());
  erodeFilter->SetKernel(structuringElement);
  typedef itk::ImageFileWriter<ImageType>WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName("output.nii");
  writer->SetInput (erodeFilter->GetOutput());
  writer->Update();

  /*QuickView viewer;
  viewer.AddImage(reader->GetOutput());
  viewer.AddImage(erodeFilter->GetOutput());
  viewer.Visualize();*/
  return EXIT_SUCCESS;
}

```

---

<div class="post-metadata">

**Author:** ![srbn.ghosh89](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@srbn.ghosh89](https://discourse.itk.org/u/srbn.ghosh89)\
**Post date:** [July 24, 2019, 8:29pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/11 "2019-07-24T20:29:18Z")

</div>

![slice](https://discourse.itk.org/uploads/default/original/1X/1fd01ec3e25cb916c67d3b9d2bf282eee0dd6713.png)

Here the same slice I got as output.

---

<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:** [July 24, 2019, 8:31pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/12 "2019-07-24T20:31:48Z")

</div>

That’s the problem. You need a binary segmentation, you seem to be just plugging grayscale image into erosion. Try [BinaryThresholdImageFilter](https://itk.org/Doxygen/html/classitk_1_1BinaryThresholdImageFilter.html) with -100 HU as the lower threshold, and pass the output of that into the erosion.

---

<div class="post-metadata">

**Author:** ![srbn.ghosh89](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@srbn.ghosh89](https://discourse.itk.org/u/srbn.ghosh89)\
**Post date:** [July 25, 2019, 3:04pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/13 "2019-07-25T15:04:47Z")

</div>

I have binarized and then applied the erosion. and then used the subtraction. But I got this kind of output.  
 ![slice2](https://discourse.itk.org/uploads/default/original/1X/bf6efd333e87d86e3bf4e21f4bb180658fc53dd4.png)

---

<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:** [July 25, 2019, 3:10pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/14 "2019-07-25T15:10:30Z")

</div>

It is pretty noisy, so try a higher threshold. Maybe 0 HU, or 50 HU, or 150 HU etc. Maybe apply connected component filter, and just keep the largest component.

What is your ultimate goal? Segmenting the skin sounds like an intermediate goal.

---

<div class="post-metadata">

**Author:** ![srbn.ghosh89](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@srbn.ghosh89](https://discourse.itk.org/u/srbn.ghosh89)\
**Post date:** [July 25, 2019, 4:32pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/15 "2019-07-25T16:32:13Z")

</div>

after the segmentation, I am going to calculate these differences. ![slice2](https://discourse.itk.org/uploads/default/original/1X/4b2eafb7fa8f9d8825e7e2cc7edbf13525ebbbed.png)

---

<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:** [July 25, 2019, 6:27pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/16 "2019-07-25T18:27:58Z")

</div>

Trying to measure degree of _pectus excavatum_? Or something else? Either way, you will also have to deal with the patient bed somehow. Simple threshold cannot remove it.

---

<div class="post-metadata">

**Author:** ![srbn.ghosh89](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@srbn.ghosh89](https://discourse.itk.org/u/srbn.ghosh89)\
**Post date:** [July 26, 2019, 2:29pm UTC](https://discourse.itk.org/t/how-to-segment-the-thin-skin-edge-of-body-parts/2078/17 "2019-07-26T14:29:51Z")

</div>

Yes. I am gonna measure the degree. I don’t mind even the patient bed is appearing. I just need the outer skin surface.
