<div>Hi fellas!</div>
<div>I'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't solve my problem either).</div>
<div> </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> </div>
<div><strong>itk::InvalidRequestedRegionError (016DF528)<br>Location: "void __thiscall itk::DataObject::PropagateRequestedRegion(void) throw (class itk::InvalidRequestedRegionError)"<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> </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'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'm missing something or doing anything wrong. I might have some extra unnecessary function calls in there (such as excessive use of UpdateLargestPossibleRegion(), I've added them for debugging purposes to compare the image status after it is being passed to each filter):</div>
<div> </div>
<div>// Extraction of VOI</div>
<div>vtkExtractVOI *voiExtractor = vtkExtractVOI::New();<br>voiExtractor->SetVOI(minX, maxX, minY, maxY, minZ, maxZ); // the values are acquired through user interaction, but even hard-coded ones don't solve the problem<br>
voiExtractor->SetSampleRate(1,1,1);<br>voiExtractor->SetInput(stencil->GetOutput());<br>voiExtractor->ReleaseDataFlagOff();</div>
<div> </div>
<div>// Flipthe image back so it is interpreted correctly by ITK</div>
<div> vtkImageFlip *flipper = vtkImageFlip::New();<br> flipper->SetInput(voiExtractor->GetOutput());<br> flipper->SetInformationInput(voiExtractor->GetOutput());<br> flipper->SetFilteredAxis(1);<br> flipper->ReleaseDataFlagOff();<br>
flipper->UpdateWholeExtent();</div>
<div> </div>
<div>// Connecting VTK and ITK pipelines</div>
<div> vtkImageExport *exporter = vtkImageExport::New();<br> exporter->SetInput(flipper->GetOutput());<br> exporter->UpdateWholeExtent();</div>
<div> </div>
<div> typedef itk::Image<signed short, 3> ImportImageType;<br> typedef itk::VTKImageImport<ImportImageType> ImporterType;<br> ImporterType::Pointer importer = ImporterType::New();</div>
<div> </div>
<div> ConnectPipelines(exporter, importer);<br> importer->UpdateLargestPossibleRegion();</div>
<div> </div>
<div>// Casting pixel type to float</div>
<div> typedef itk::Image<float, 3> InputImageType;<br> typedef itk::CastImageFilter<ImportImageType, InputImageType> ShortToFloatFilter;</div>
<div> </div>
<div> ImportImageType::Pointer inputImage = importer->GetOutput();</div>
<div> </div>
<div> ShortToFloatFilter::Pointer caster = ShortToFloatFilter::New();</div>
<div> caster->SetInput(inputImage);<br> caster->UpdateLargestPossibleRegion();</div>
<div> </div>
<div>// This part is mostly copy/paste from ThresholdSegmentationLevelSetImageFilter.cxx example</div>
<div> typedef itk::Image< signed short, 3 > OutputImageType;<br> typedef itk::BinaryThresholdImageFilter<InputImageType, OutputImageType> ThresholdingFilterType;</div>
<div> ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();<br> thresholder->SetLowerThreshold( -1000.0 );<br> thresholder->SetUpperThreshold( 0.0 );<br> thresholder->SetOutsideValue( 0 );<br>
thresholder->SetInsideValue( 255 );</div>
<div> </div>
<div> typedef itk::FastMarchingImageFilter< InputImageType, InputImageType > FastMarchingFilterType;<br> FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();</div>
<div> </div>
<div> typedef itk::ThresholdSegmentationLevelSetImageFilter< InputImageType, InputImageType > ThresholdSegmentationLevelSetImageFilterType;<br> ThresholdSegmentationLevelSetImageFilterType::Pointer thresholdSegmentation = ThresholdSegmentationLevelSetImageFilterType::New();</div>
<div><br> thresholdSegmentation->SetPropagationScaling( 1.0 );<br> thresholdSegmentation->SetCurvatureScaling( 1.0 );<br> thresholdSegmentation->SetMaximumRMSError( 0.02 );<br> thresholdSegmentation->SetNumberOfIterations( 1200 );<br>
thresholdSegmentation->SetUpperThreshold( 800);<br> thresholdSegmentation->SetLowerThreshold( -600);<br> thresholdSegmentation->SetIsoSurfaceValue(0.0);<br> thresholdSegmentation->SetInput( fastMarching->GetOutput() );<br>
thresholdSegmentation->SetFeatureImage( caster->GetOutput() );</div><font size="2">
<p>thresholder->SetInput( thresholdSegmentation->GetOutput() );</p>
<div></div></font> typedef FastMarchingFilterType::NodeContainer NodeContainer;<br> typedef FastMarchingFilterType::NodeType NodeType;
<div><br> NodeContainer::Pointer seeds = NodeContainer::New();</div>
<div> </div>
<div> InputImageType::IndexType seedPosition;<br> seedPosition[0] = seedX;</div>
<div> seedPosition[1] = seedY;<br> seedPosition[2] = seedZ;</div>
<div> </div>
<div> const double initialDistance = 5.0;</div>
<div><br> const double seedValue = - initialDistance;</div>
<div> </div>
<div> NodeType node;<br> node.SetValue( seedValue );<br> node.SetIndex( seedPosition );</div>
<div> </div>
<div> seeds->Initialize();<br> seeds->InsertElement( 0, node );</div>
<div> </div>
<div> fastMarching->SetTrialPoints( seeds );<br> fastMarching->SetSpeedConstant( 1.0 );</div>
<div> </div>
<div>try</div>
<div>{<br> fastMarching->SetOutputSize(caster->GetOutput()->GetBufferedRegion().GetSize() );<br> thresholder->UpdateLargestPossibleRegion(); // This is where I get my exception caught</div>
<div>}</div>
<div>catch( itk::ExceptionObject & excep )<br>{<br> std::cerr << "Exception caught !" << std::endl;<br> std::cerr << excep << std::endl;<br>}</div>
<div> </div>
<div>Thanks in advance guys.</div>
<div>If you need more info on the problem, please let me know.<br>-- <br>"Then it comes to be that the soothing light at the end of your tunnel is just a freight train coming your way..." No Leaf Clover, Metallica </div>