<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi,<div> I had a similar problem and that was in my case because the input i was giving the writer was an empty image. I would suggest that u make an reader->Update(), before u initialize the output image.</div><div>Cheers,</div><div>Ella<br><br>--- G G <i><greenlander1986@gmail.com></i> schrieb am <b>Di, 1.3.2011:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>Von: G G <greenlander1986@gmail.com><br>Betreff: [Insight-users] watershed segmentation in own function<br>An: "insight-users" <insight-users@itk.org><br>Datum: Dienstag, 1. März, 2011 12:17 Uhr<br><br><div id="yiv186125324">Hi Luis,<br>I tried to write funcion, which return image after image segmentation. I have this code:<br><br> typedef float
PixelType;<br> const unsigned int InputDimension = 3;<br>
<br> typedef itk::Image< PixelType, InputDimension > ImageType;<br> typedef itk::ImageFileReader< ImageType > ReaderType;<br><br> ReaderType::Pointer reader = ReaderType::New();<br>
reader->SetFileName( this->settings.getInputPath().c_str() );<br><br> const unsigned int OutputDimension = 3;<br><br> typedef itk::RGBPixel<unsigned char> RGBPixelType; // ws<br>
typedef itk::Image< RGBPixelType, OutputDimension > OutputImageType; // ws<br><br> WriterType::Pointer writer = WriterType::New();<br> writer->SetFileName( this->settings.getOutputPath().c_str() );<br>
<br> OutputImageType::Pointer output = OutputImageType::New();<br> output = this->segmentationCC<OutputImageType::Pointer, ImageType, OutputImageType, ImageType::Pointer>(reader->GetOutput());<br>
writer->SetInput(output);<br> try<br> {<br> writer->Update();<br> //writer->UpdateLargestPossibleRegion();<br> //writer->UpdateOutputData(output); <br>
}<br> catch (itk::ExceptionObject &e)<br> {<br> this->settings.setLogMessage("Chyba pri zapisu do souboru");<br> cerr << e << endl;<br> this->settings.setIsOK(false);<br>
return;<br> }<br><br><br>then I have to show function segmentationCC:<br><br> template<typename TOutputImageTypePointer, typename TImageType, typename TRGBImageType, typename TInput> TOutputImageTypePointer IOCompute::segmentationCC(TInput input)<br>
{<br> typedef itk::GradientMagnitudeRecursiveGaussianImageFilter< TImageType, TImageType > GradientMagnitudeFilterType;<br> GradientMagnitudeFilterType::Pointer gradienMagnitudeFilter = GradientMagnitudeFilterType::New();<br>
gradienMagnitudeFilter->SetInput( input );<br> gradienMagnitudeFilter->SetSigma( 1.0 );<br><br><br> typedef itk::WatershedImageFilter< TImageType > WatershedFilterType;<br> WatershedFilterType::Pointer watershedFilter = WatershedFilterType::New();<br>
watershedFilter->SetInput( gradienMagnitudeFilter->GetOutput() );<br> watershedFilter->SetThreshold( 0.01 );<br> watershedFilter->SetLevel( 0.15 );<br><br> typedef itk::Functor::ScalarToRGBPixelFunctor< unsigned long > ColorMapFunctorType;<br>
<br> typedef WatershedFilterType::OutputImageType LabeledImageType;<br><br> typedef itk::UnaryFunctorImageFilter<<br> LabeledImageType,<br> TRGBImageType,<br>
ColorMapFunctorType<br> > ColorMapFilterType;<br><br> ColorMapFilterType::Pointer colorMapFilter = ColorMapFilterType::New();<br>
<br> colorMapFilter->SetInput( watershedFilter->GetOutput() );<br><br> TOutputImageTypePointer output = colorMapFilter->GetOutput();<br> return output;<br> }<br><br><br><br>when I use writer->Update();<br>
I have exception<br><br><br>itk::ExceptionObject (00A3F388)<br>Location: "void __thiscall itk::ImageFileWriter<class itk::Image<class itk::RGBPixel<unsigned char>,3> >::Write(void)" <br>File: c:\itkrel\src\insight\code\io\itkImageFileWriter.txx<br>
Line: 271<br>Description: itk::ERROR: ImageFileWriter(00B513B8): Largest possible region does not fully contain requested paste IO regionPaste IO region: ImageIORegion (00A3F3F8)<br> Dimension: 3<br> Index: 0 0 0 <br> Size: 0 0 0 <br>
Largest possible region: ImageRegion (00A3F3DC)<br> Dimension: 3<br> Index: [0, 0, 0]<br> Size: [0, 0, 0]<br><br><br>or when I have writer->UpdateLargestPossibleRegion(); then no exception, but any writter output file :'-(<br>
<br>Please help me or give some advice, I am desperate...<br>Thanks a lot<br>
</div><br>-----Integrierter Anhang folgt-----<br><br><div class="plainMail">_____________________________________<br>Powered by www.kitware.com<br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br><br>Kitware offers ITK Training Courses, for more information visit:<br><a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br><br>Please keep messages on-topic and check the ITK FAQ at:<br><a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br></div></blockquote></b></div></td></tr></table><br>