Hello to all,<br><br>I am reading a 3D image using a reader, then I rescale the volume using RescaleIntensityImageFilter, then extract a subregion from the rescaled volume and finally I extract slices from this subregion. But every time I am daclare the input region for the extract slice Image Filter then I get an exception I hope that someone could help me.<br>
<br>Thanks in advance<br><br> typedef float InputPixelType;<br> typedef unsigned char OutputPixelType;<br> const unsigned int Dimension = 3;<br><br> typedef itk::Image< InputPixelType, Dimension > InputImageType;<br>
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;<br><br> typedef itk::ImageFileReader< InputImageType > ReaderType;<br><br> typedef itk::RegionOfInterestImageFilter< OutputImageType, <br>
OutputImageType > FilterType_region;<br><br> typedef itk::RescaleIntensityImageFilter< <br> InputImageType, <br> OutputImageType > FilterType_rescale;<br>
typedef unsigned char InputPixelType_extract;<br> typedef unsigned char OutputPixelType_extract;<br> typedef itk::Image< InputPixelType_extract, 3 > InputImageType_extract;<br> typedef itk::Image< OutputPixelType_extract, 2 > OutputImageType_extract;<br>
typedef itk::ExtractImageFilter< InputImageType_extract, OutputImageType_extract > FilterType_extract;<br>///////////////////////////////////////////////////<br>/////////////////////////////////////<br><br><br> FilterType_rescale::Pointer filter_rescale = FilterType_rescale::New();<br>
filter_rescale->SetOutputMinimum( 0 );<br> filter_rescale->SetOutputMaximum( value_norm );<br><br>//////extract region filter<br> FilterType_region::Pointer filter_region = FilterType_region::New();<br>
OutputImageType::IndexType start_region;<br> start_region[0] = ui->doubleSpinBox_start_x->value();<br> start_region[1] = ui->doubleSpinBox_start_y->value();<br> start_region[2] = ui->doubleSpinBox_start_z->value();<br>
<br> OutputImageType::SizeType size_region;<br> size_region[0] = ui->doubleSpinBox_size_x->value();<br> size_region[1] = ui->doubleSpinBox_size_y->value();<br> size_region[2] = ui->doubleSpinBox_size_z->value();<br>
<br> OutputImageType::RegionType desiredRegion_region;<br> desiredRegion_region.SetSize( size_region );<br> desiredRegion_region.SetIndex( start_region );<br><br> filter_region->SetRegionOfInterest( desiredRegion_region );<br>
<br> ReaderType::Pointer reader = ReaderType::New();<br><br> reader->SetFileName( fileName.toStdString() );<br><br> filter_rescale->SetInput( reader->GetOutput() );<br> filter_region->SetInput( filter_rescale->GetOutput() );<br>
<br> filter_region->Update();<br><br> /////////////////////<br> FilterType_extract::Pointer filter_extract = FilterType_extract::New();<br><span style="background-color: rgb(255, 255, 51);"> </span><br style="background-color: rgb(255, 255, 51);">
<span style="background-color: rgb(255, 255, 51);"> OutputImageType::RegionType inputRegion =</span><br style="background-color: rgb(255, 255, 51);"><span style="background-color: rgb(255, 255, 51);"> filter_region->GetOutput()->GetLargestPossibleRegion();</span><br>
<br> OutputImageType::SizeType size = inputRegion.GetSize();<br> <br> // get the size of the hole 3D image<br> size_x = size[0];<br> size_y = size[1];<br> size_z = size[2];<br> <br> // get slices of z coordiante<br>
size[2] = 0; <br><br> OutputImageType::IndexType start = inputRegion.GetIndex();<br><br> ui->verticalScrollBar_z->setRange(0,size_z-1);<br> unsigned int sliceNumber = ui->verticalScrollBar_z->value();<br>
start[2] = sliceNumber;<br> <br><br> OutputImageType::RegionType desiredRegion;<br> desiredRegion.SetSize( size );<br> desiredRegion.SetIndex( start );<br><br> filter_extract->SetExtractionRegion( desiredRegion );<br>
<br> WriterType::Pointer writer = WriterType::New();<br> writer->SetFileName( "z.png" );<br> <br> filter_extract->SetInput( filter_region->GetOutput() );<br> writer->SetInput( filter_extract->GetOutput() );<br>
<br> try <br> { <br> writer->Update(); <br> } <br> catch( itk::ExceptionObject & err ) <br> { <br> std::cerr << "ExceptionObject caught !" << std::endl; <br> std::cerr << err << std::endl; <br>
} <br><div style="visibility: hidden; left: -5000px; position: absolute; z-index: 9999; padding: 0px; margin-left: 0px; margin-top: 0px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 130%;" id="avg_ls_inline_popup">
</div>