<div>Hi fellas!</div>
<div>I&#39;m working on my software graduation project at the University of Wollongong, and I have to present it on a trade show in 2 weeks.</div>
<div>This problem has been giving me headaches for the last 2 weeks, and so far I only got a possible cause, but have no idea how to fix it.</div>
<div>I have a volume in DICOM format (768x768x75) which I acquire using ITK classes.</div>
<div>When the volume is imported from hard disk, I pipeline it to VTK in order to display and apply some user interaction (such as selection of ROI, placement of a seed pixel for segmentation, etc.).</div>
<div>I also extract the volume of interest using vtkExtractVOI filter (itk::ExtractImageFilter and itk::CropImageFilter work as well, but they don&#39;t solve my problem either).</div>
<div>&nbsp;</div>
<div>When I run the application, select a region, place a seed pixel and then try to apply segmentation (threshold level set), I get the following exception message:</div>
<div>&nbsp;</div>
<div><strong>itk::InvalidRequestedRegionError (016DF528)<br>Location: &quot;void __thiscall itk::DataObject::PropagateRequestedRegion(void) throw (class itk::InvalidRequestedRegionError)&quot;<br>File: ..\..\..\InsightToolkit-3.4.0\Code\Common\itkDataObject.cxx<br>
Line: 397<br>Description: Requested region is (at least partially) outside the largest possible region.</strong></div>
<div>&nbsp;</div>
<div>It seems that one of the filters involved in segmentation applies the coordinates to a global space, not a local coordinate system of the extracted volume. BTW when I don&#39;t apply extaction of the VOI, segmentation and visualization works like a charm.</div>

<div>Is there a way to fix it?<br>Please check out part of my code below and tell me if I&#39;m missing something or doing anything wrong. I might have some extra unnecessary function calls in there (such as excessive use of UpdateLargestPossibleRegion(), I&#39;ve added them for debugging purposes to compare the image status after it is being passed to each filter):</div>

<div>&nbsp;</div>
<div>// Extraction of VOI</div>
<div>vtkExtractVOI *voiExtractor = vtkExtractVOI::New();<br>voiExtractor-&gt;SetVOI(minX, maxX, minY, maxY, minZ, maxZ);&nbsp; // the values are acquired through user interaction, but even hard-coded ones don&#39;t solve the problem<br>
voiExtractor-&gt;SetSampleRate(1,1,1);<br>voiExtractor-&gt;SetInput(stencil-&gt;GetOutput());<br>voiExtractor-&gt;ReleaseDataFlagOff();</div>
<div>&nbsp;</div>
<div>// Flipthe image back so it is interpreted correctly by ITK</div>
<div>&nbsp;vtkImageFlip *flipper = vtkImageFlip::New();<br>&nbsp;flipper-&gt;SetInput(voiExtractor-&gt;GetOutput());<br>&nbsp;flipper-&gt;SetInformationInput(voiExtractor-&gt;GetOutput());<br>&nbsp;flipper-&gt;SetFilteredAxis(1);<br>&nbsp;flipper-&gt;ReleaseDataFlagOff();<br>
&nbsp;flipper-&gt;UpdateWholeExtent();</div>
<div>&nbsp;</div>
<div>// Connecting VTK and ITK pipelines</div>
<div>&nbsp;vtkImageExport *exporter = vtkImageExport::New();<br>&nbsp;exporter-&gt;SetInput(flipper-&gt;GetOutput());<br>&nbsp;exporter-&gt;UpdateWholeExtent();</div>
<div>&nbsp;</div>
<div>&nbsp;typedef itk::Image&lt;signed short, 3&gt; ImportImageType;<br>&nbsp;typedef itk::VTKImageImport&lt;ImportImageType&gt; ImporterType;<br>&nbsp;ImporterType::Pointer importer = ImporterType::New();</div>
<div>&nbsp;</div>
<div>&nbsp;ConnectPipelines(exporter, importer);<br>&nbsp;importer-&gt;UpdateLargestPossibleRegion();</div>
<div>&nbsp;</div>
<div>// Casting pixel type to float</div>
<div>&nbsp;typedef itk::Image&lt;float, 3&gt; InputImageType;<br>&nbsp;typedef itk::CastImageFilter&lt;ImportImageType, InputImageType&gt; ShortToFloatFilter;</div>
<div>&nbsp;</div>
<div>&nbsp;ImportImageType::Pointer inputImage = importer-&gt;GetOutput();</div>
<div>&nbsp;</div>
<div>&nbsp;ShortToFloatFilter::Pointer caster = ShortToFloatFilter::New();</div>
<div>&nbsp;caster-&gt;SetInput(inputImage);<br>&nbsp;caster-&gt;UpdateLargestPossibleRegion();</div>
<div>&nbsp;</div>
<div>// This part is mostly copy/paste from ThresholdSegmentationLevelSetImageFilter.cxx example</div>
<div>&nbsp;typedef itk::Image&lt; signed short, 3 &gt; OutputImageType;<br>&nbsp;typedef itk::BinaryThresholdImageFilter&lt;InputImageType, OutputImageType&gt; ThresholdingFilterType;</div>
<div>&nbsp;ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();<br>&nbsp;thresholder-&gt;SetLowerThreshold( -1000.0 );<br>&nbsp;thresholder-&gt;SetUpperThreshold(&nbsp;&nbsp;&nbsp;&nbsp; 0.0 );<br>&nbsp;thresholder-&gt;SetOutsideValue(&nbsp; 0&nbsp; );<br>
&nbsp;thresholder-&gt;SetInsideValue(&nbsp; 255 );</div>
<div>&nbsp;</div>
<div>&nbsp;typedef&nbsp; itk::FastMarchingImageFilter&lt; InputImageType, InputImageType &gt; FastMarchingFilterType;<br>&nbsp;FastMarchingFilterType::Pointer&nbsp; fastMarching = FastMarchingFilterType::New();</div>
<div>&nbsp;</div>
<div>&nbsp;typedef&nbsp; itk::ThresholdSegmentationLevelSetImageFilter&lt; InputImageType, InputImageType &gt; ThresholdSegmentationLevelSetImageFilterType;<br>&nbsp;ThresholdSegmentationLevelSetImageFilterType::Pointer thresholdSegmentation = ThresholdSegmentationLevelSetImageFilterType::New();</div>

<div><br>&nbsp;thresholdSegmentation-&gt;SetPropagationScaling( 1.0 );<br>&nbsp;thresholdSegmentation-&gt;SetCurvatureScaling( 1.0 );<br>&nbsp;thresholdSegmentation-&gt;SetMaximumRMSError( 0.02 );<br>&nbsp;thresholdSegmentation-&gt;SetNumberOfIterations( 1200 );<br>
&nbsp;thresholdSegmentation-&gt;SetUpperThreshold( 800);<br>&nbsp;thresholdSegmentation-&gt;SetLowerThreshold( -600);<br>&nbsp;thresholdSegmentation-&gt;SetIsoSurfaceValue(0.0);<br>&nbsp;thresholdSegmentation-&gt;SetInput( fastMarching-&gt;GetOutput() );<br>
&nbsp;thresholdSegmentation-&gt;SetFeatureImage( caster-&gt;GetOutput() );</div><font size="2">
<p>thresholder-&gt;SetInput( thresholdSegmentation-&gt;GetOutput() );</p>
<div></div></font>&nbsp;typedef FastMarchingFilterType::NodeContainer NodeContainer;<br>&nbsp;typedef FastMarchingFilterType::NodeType NodeType;
<div><br>&nbsp;NodeContainer::Pointer seeds = NodeContainer::New();</div>
<div>&nbsp;</div>
<div>&nbsp;InputImageType::IndexType&nbsp; seedPosition;<br>&nbsp;seedPosition[0] =&nbsp;seedX;</div>
<div>&nbsp;seedPosition[1] =&nbsp;seedY;<br>&nbsp;seedPosition[2] = seedZ;</div>
<div>&nbsp;</div>
<div>&nbsp;const double initialDistance = 5.0;</div>
<div><br>&nbsp;const double seedValue = - initialDistance;</div>
<div>&nbsp;</div>
<div>&nbsp;NodeType node;<br>&nbsp;node.SetValue( seedValue );<br>&nbsp;node.SetIndex( seedPosition );</div>
<div>&nbsp;</div>
<div>&nbsp;seeds-&gt;Initialize();<br>&nbsp;seeds-&gt;InsertElement( 0, node );</div>
<div>&nbsp;</div>
<div>&nbsp;fastMarching-&gt;SetTrialPoints(&nbsp; seeds&nbsp; );<br>&nbsp;fastMarching-&gt;SetSpeedConstant( 1.0 );</div>
<div>&nbsp;</div>
<div>try</div>
<div>{<br>&nbsp;&nbsp;fastMarching-&gt;SetOutputSize(caster-&gt;GetOutput()-&gt;GetBufferedRegion().GetSize() );<br>&nbsp;&nbsp;thresholder-&gt;UpdateLargestPossibleRegion();&nbsp;&nbsp; // This is where I get my exception caught</div>
<div>}</div>
<div>catch( itk::ExceptionObject &amp; excep )<br>{<br>&nbsp;&nbsp;&nbsp;std::cerr &lt;&lt; &quot;Exception caught !&quot; &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp;std::cerr &lt;&lt; excep &lt;&lt; std::endl;<br>}</div>
<div>&nbsp;</div>
<div>Thanks in advance guys.</div>
<div>If you need more info on the problem, please let me know.<br>-- <br>&quot;Then it comes to be that the soothing light at the end of your tunnel is just a freight train coming your way...&quot; No Leaf Clover, Metallica </div>