<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi,<div>&nbsp;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-&gt;Update(), before u initialize the output image.</div><div>Cheers,</div><div>Ella<br><br>--- G G <i>&lt;greenlander1986@gmail.com&gt;</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 &lt;greenlander1986@gmail.com&gt;<br>Betreff: [Insight-users] watershed segmentation in own function<br>An: "insight-users" &lt;insight-users@itk.org&gt;<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>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; typedef float&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 &nbsp;&nbsp;&nbsp; &nbsp; PixelType;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; const&nbsp;&nbsp; unsigned int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputDimension = 3;<br>
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; typedef itk::Image&lt; PixelType,&nbsp; InputDimension &gt;&nbsp;&nbsp;&nbsp; &nbsp;ImageType;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; typedef&nbsp; itk::ImageFileReader&lt; ImageType &gt;&nbsp;&nbsp; ReaderType;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ReaderType::Pointer reader = ReaderType::New();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; reader-&gt;SetFileName( this-&gt;settings.getInputPath().c_str() );<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; const&nbsp;&nbsp; unsigned int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OutputDimension = 3;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; typedef itk::RGBPixel&lt;unsigned char&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RGBPixelType;&nbsp;&nbsp;&nbsp; // ws<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; typedef itk::Image&lt; RGBPixelType, OutputDimension &gt;&nbsp; OutputImageType; // ws<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; WriterType::Pointer writer = WriterType::New();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; writer-&gt;SetFileName( this-&gt;settings.getOutputPath().c_str() );<br>
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; OutputImageType::Pointer output = OutputImageType::New();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output = this-&gt;segmentationCC&lt;OutputImageType::Pointer, ImageType, OutputImageType, ImageType::Pointer&gt;(reader-&gt;GetOutput());<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; writer-&gt;SetInput(output);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; try<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; writer-&gt;Update();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //writer-&gt;UpdateLargestPossibleRegion();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //writer-&gt;UpdateOutputData(output);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; catch (itk::ExceptionObject &amp;e)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;settings.setLogMessage("Chyba pri zapisu do souboru");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cerr &lt;&lt; e &lt;&lt; endl;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;settings.setIsOK(false);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br><br><br>then I have to show function segmentationCC:<br><br>&nbsp;&nbsp;&nbsp; template&lt;typename TOutputImageTypePointer, typename TImageType, typename TRGBImageType, typename TInput&gt; TOutputImageTypePointer IOCompute::segmentationCC(TInput input)<br>
&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; typedef&nbsp;&nbsp; itk::GradientMagnitudeRecursiveGaussianImageFilter&lt; TImageType, TImageType &gt; GradientMagnitudeFilterType;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; GradientMagnitudeFilterType::Pointer gradienMagnitudeFilter = GradientMagnitudeFilterType::New();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; gradienMagnitudeFilter-&gt;SetInput( input );<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; gradienMagnitudeFilter-&gt;SetSigma( 1.0 );<br><br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; typedef&nbsp; itk::WatershedImageFilter&lt; TImageType &gt; WatershedFilterType;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; WatershedFilterType::Pointer watershedFilter = WatershedFilterType::New();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; watershedFilter-&gt;SetInput( gradienMagnitudeFilter-&gt;GetOutput() );<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; watershedFilter-&gt;SetThreshold( 0.01 );<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; watershedFilter-&gt;SetLevel(&nbsp;&nbsp;&nbsp;&nbsp; 0.15 );<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; typedef itk::Functor::ScalarToRGBPixelFunctor&lt; unsigned long &gt; ColorMapFunctorType;<br>
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; typedef WatershedFilterType::OutputImageType&nbsp; LabeledImageType;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; typedef itk::UnaryFunctorImageFilter&lt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; LabeledImageType,<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; TRGBImageType,<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ColorMapFunctorType<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &gt; ColorMapFilterType;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; ColorMapFilterType::Pointer colorMapFilter = ColorMapFilterType::New();<br>
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; colorMapFilter-&gt;SetInput(&nbsp; watershedFilter-&gt;GetOutput() );<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; TOutputImageTypePointer output = colorMapFilter-&gt;GetOutput();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; return output;<br>&nbsp;&nbsp;&nbsp; }<br><br><br><br>when I use writer-&gt;Update();<br>
I have exception<br><br><br>itk::ExceptionObject (00A3F388)<br>Location: "void __thiscall itk::ImageFileWriter&lt;class itk::Image&lt;class itk::RGBPixel&lt;unsigned char&gt;,3&gt; &gt;::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>&nbsp; Dimension: 3<br>&nbsp; Index: 0 0 0 <br>&nbsp; Size: 0 0 0 <br>
Largest possible region: ImageRegion (00A3F3DC)<br>&nbsp; Dimension: 3<br>&nbsp; Index: [0, 0, 0]<br>&nbsp; Size: [0, 0, 0]<br><br><br>or when I have writer-&gt;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>