Hello Rupinder, <br><br>Could it be that your CastFilter&#39;s output is of OutputImageType <br>and your Writer&#39;s input is of InputImageType and you connect<br>the cast filter&#39;s output to the writer filter ? Templating the ImageFileWriter<br>
over the OutputImageType might solve your problem. That is instead of<br><font style="font-size: 11px;" color="#2d2cfa"> typedef  itk::ImageFileWriter&lt; InputImageType &gt;  WriterType;<br></font>try <br><font style="font-size: 11px;" color="#2d2cfa">typedef  itk::ImageFileWriter&lt; OutputImageType &gt;  WriterType;<br>
</font><br>PS. You can attach the error to the email for a better diagnosis.<br><br>Regards, <br>Cagatay<br><br><div class="gmail_quote">On Mon, Oct 31, 2011 at 10:03 PM, Rupinder Singh <span dir="ltr">&lt;<a href="mailto:rupinder.singh123@yahoo.com">rupinder.singh123@yahoo.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word;">I&#39;m having difficulty understanding why the following function throws an<br>
exception at &#39;writer-&gt;Update()&#39; whenever it&#39;s called.<br><br><font style="font-size: 11px;" color="#2d2cfa">const     unsigned int    Dimension = 2;<br>typedef   unsigned char   InputPixelType;<br>typedef   unsigned char   OutputPixelType;<br>
<br>typedef itk::Image&lt; InputPixelType,    Dimension &gt;   InputImageType;<br>typedef itk::Image&lt; OutputPixelType,   Dimension &gt;   OutputImageType;<br><br>void saveITKImage(InputImageType *image)<br>{<br>   typedef  itk::RescaleIntensityImageFilter&lt; InputImageType,<br>
OutputImageType &gt; CastFilterType;<br>   typedef  itk::ImageFileWriter&lt; InputImageType &gt;                                         <br>WriterType;<br><br>   WriterType::Pointer      writer = WriterType::New();<br>   CastFilterType::Pointer  caster = CastFilterType::New();<br>
<br>   writer-&gt;SetFileName(&quot;/Users/usr/Desktop/test.jpg&quot;);<br>   caster-&gt;SetOutputMinimum(   0 );<br>   caster-&gt;SetOutputMaximum( 255 );<br><br>   // Define Pipeline<br>   caster-&gt;SetInput( image );<br>
   writer-&gt;SetInput( caster-&gt;GetOutput() );<br>   writer-&gt;Update();<br><br>   return;<br>}</font><br><br>I know I&#39;m doing something right because the following bit of code works perfectly when called.<br><br>
<span style="font-size: 11px;"><font color="#2d2cfa">void saveITKImage(InputImageType *image)<br>{<br>   typedef  itk::ImageFileWriter&lt; InputImageType &gt; WriterType;<br><br>   WriterType::Pointer  writer = WriterType::New();<br>
<br>   writer-&gt;SetFileName(&quot;/Users/usr/Desktop/test.jpg&quot;);<br><br>   // Define Pipeline<br>   writer-&gt;SetInput( image);<br>   writer-&gt;Update();<br><br>   return;<br>}</font></span><br><br>Does anyone know what I&#39;m doing wrong?<div>
<br></div><div>Thank you in advance for your help!</div></div><br>_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><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>
<br></blockquote></div><br>