title: How to use region-growing algorithms to define a region of interest?
body: <p>I am working on DICOM images (CT scans) &amp; would like to isolate some structures of interest in my picture such as human organs (like the aorta, cf the image enclosed). I am coding in C++ with the help of ITK &amp; VTK.</p>
  
  <p><a href="https://i.stack.imgur.com/d0UYX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d0UYX.png" alt="The bright tube describes a sick aorta and corresponds to the structure that I would like to isolate. "></a></p>
  
  <p>Let's assume these organs have a particular brightness intensity, therefore I can automatically identify them by using a region-growing algorithm (code below). In order to do so, I previously computed some threshold values based on the mean &amp; standard deviation values of the voxels belonging to the organ. </p>
  
  <p><strong>How can I only keep the aorta in my image with the help of ITK/VTK features?</strong> I guess that what I'm looking for is a filter that would do the exact opposite of the <a href="https://itk.org/Doxygen/html/classitk_1_1MaskImageFilter.html" rel="nofollow noreferrer">ITK mask image filter</a>.</p>
  
  <p>Please find the (pseudo) code corresponding to the organ isolation below. I computed a 5 voxels dilation on the result of the region-growing to be sure to include all voxels of the organ and to have a sufficient margin around the organ after cropping.</p>
  
  <pre><code>typedef short InputPixelType;
  typedef unsigned char OutputPixelType; 
  const int Dimension = 3;
  
  typedef itk::Image&lt; InputPixelType, Dimension &gt; InputImageType;
  typedef itk::Image&lt; OutputPixelType, Dimension &gt; OutputImageType;
  
  // Region growing
  typedef itk::ConnectedThresholdImageFilter&lt; InputImagetype, 
  OutputImagetype &gt; ConnectedFilterType;
  
  ConnectedFilterType::Pointer connectedThreshold = ConnectedFilterType::New();
  
  connectedThreshold-&gt;SetInput(input);
  connectedThreshold-&gt;SetUpper(upperThreshold);
  connectedThreshold-&gt;SetLower(lowerThreshold);
  
  //Initializing seed
  InternalImagetype::IndexType index;
  index[0] = seed_x; 
  index[1] = seed_y;
  connectedThreshold-&gt;SetSeed(index);
  
  // Dilate the resulting region-growing of 5 voxels for safety
  typedef itk::BinaryBallStructuringElement&lt; OutputImageType, 
  Dimension &gt; StructuringElementType;
  typedef itk::BinaryDilateImageFilter&lt; OutputImageType, 
  OutputImageType, StruturingElementType &gt; DilateFilterType;
  
  StructuringElementType structuringElement;
  structuringElement.SetRadius(5);
  structuringElement.CreateStructuringElement();
  
  DilateFilterType::Pointer dilateFilter = DilateFilterType::New();
  dilateFilter-&gt;SetInput(connectedThreshold-&gt;GetOutput());
  dilatefilter-&gt;SetKernel(structuringElement);
  
  // Saving the results of the RG+dilation
  typedef itk::ImageFileWriter&lt; OutputImageType &gt; WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer-&gt;SetInput(dilateFilter-&gt;GetOutput());
  writer-&gt;SetFileName("organ-segmented-with-dilation.mhd");
  try {
      writer-&gt;Update();
  } catch(itk::ExceptionObject&amp; err) {
      std::cerr &lt;&lt; "Exception caught! " &lt;&lt; err.what() &lt;&lt; std::endl;
      return EXIT_FAILURE;
  }
  
  // What to do next to crop the input image with this region-growing? 
  </code></pre>
  
  <p>Any help or remark is welcomed.</p>