<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I'm having difficulty understanding why the following function throws an<br>exception at 'writer-&gt;Update()' whenever it's called.<br><br><font class="Apple-style-span" color="#2d2cfa" style="font-size: 11px;">const &nbsp;&nbsp;&nbsp;&nbsp;unsigned int &nbsp;&nbsp;&nbsp;Dimension = 2;<br>typedef &nbsp;&nbsp;unsigned char &nbsp;&nbsp;InputPixelType;<br>typedef &nbsp;&nbsp;unsigned char &nbsp;&nbsp;OutputPixelType;<br><br>typedef itk::Image&lt; InputPixelType, &nbsp;&nbsp;&nbsp;Dimension &gt; &nbsp;&nbsp;InputImageType;<br>typedef itk::Image&lt; OutputPixelType, &nbsp;&nbsp;Dimension &gt; &nbsp;&nbsp;OutputImageType;<br><br>void saveITKImage(InputImageType *image)<br>{<br>&nbsp;&nbsp;&nbsp;typedef &nbsp;itk::RescaleIntensityImageFilter&lt; InputImageType,<br>OutputImageType &gt; CastFilterType;<br>&nbsp;&nbsp;&nbsp;typedef &nbsp;itk::ImageFileWriter&lt; InputImageType &gt; &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;<br>WriterType;<br><br>&nbsp;&nbsp;&nbsp;WriterType::Pointer &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;writer = WriterType::New();<br>&nbsp;&nbsp;&nbsp;CastFilterType::Pointer &nbsp;caster = CastFilterType::New();<br><br>&nbsp;&nbsp;&nbsp;writer-&gt;SetFileName("/Users/usr/Desktop/test.jpg");<br>&nbsp;&nbsp;&nbsp;caster-&gt;SetOutputMinimum( &nbsp;&nbsp;0 );<br>&nbsp;&nbsp;&nbsp;caster-&gt;SetOutputMaximum( 255 );<br><br>&nbsp;&nbsp;&nbsp;// Define Pipeline<br>&nbsp;&nbsp;&nbsp;caster-&gt;SetInput( image );<br>&nbsp;&nbsp;&nbsp;writer-&gt;SetInput( caster-&gt;GetOutput() );<br>&nbsp;&nbsp;&nbsp;writer-&gt;Update();<br><br>&nbsp;&nbsp;&nbsp;return;<br>}</font><br><br>I know I'm doing something right because the following bit of code works perfectly when called.<br><br><span class="Apple-style-span" style="font-size: 11px;"><font class="Apple-style-span" color="#2d2cfa">void saveITKImage(InputImageType *image)<br>{<br>&nbsp;&nbsp;&nbsp;typedef &nbsp;itk::ImageFileWriter&lt; InputImageType &gt; WriterType;<br><br>&nbsp;&nbsp;&nbsp;WriterType::Pointer &nbsp;writer = WriterType::New();<br><br>&nbsp;&nbsp;&nbsp;writer-&gt;SetFileName("/Users/usr/Desktop/test.jpg");<br><br>&nbsp;&nbsp;&nbsp;// Define Pipeline<br>&nbsp;&nbsp;&nbsp;writer-&gt;SetInput( image);<br>&nbsp;&nbsp;&nbsp;writer-&gt;Update();<br><br>&nbsp;&nbsp;&nbsp;return;<br>}</font></span><br><br>Does anyone know what I'm doing wrong?<div><br></div><div>Thank you in advance for your help!</div></body></html>