<br>Hi Jihan,<br><br>Please do the following:<br><br>
<br>
A)  Remove the lines<br>
<br>
<br>
  itk::PNGImageIO::Pointer io;<br>
  io = itk::PNGImageIO::New();<br>
<br>
  PNGwriter-&gt;SetImageIO(io);<br>
<br>
  PNGreader-&gt;SetImageIO(io);<br>
<br>
<br>
They are confusing the ImageIO factory,<br>
since you are telling it to read a JPEG<br>
image, but you are forcing to use a<br>
PNG reader. (and of course, the PNG reader<br>doesn&#39;t know how to read a JPEG image).<br>
<br><br>
The ITK image IO factory will figure<br>
out automatically what file format to<br>
use. You don&#39;t need to (and in general<br>
should not) specify what ImageIO to use.<br>
<br>
<br>
<br><br><br>B) Replace:<br><br>  PNGreader-&gt;Update();
<div><br>with:<br><br>  try<br>     {<br>     PNGreader-&gt;Update();
<br>     }<br>   catch ( itk::ExceptionObject &amp; excp )<br>     {<br>     std::cerr &lt;&lt; excp &lt;&lt; std::endl;<br>     return 1;<br>     }<br><br><br>This will give you an informative error message,<br>if something goes wrong.<br>
<br><br>C)  Replace:<br>
<br>
  PNGwriter-&gt;Update();
<div><br>
with:<br>
  <br>
  try<br>
     {<br>
     PNGwriter-&gt;Update();
  <br>
     }<br>
   catch ( itk::ExceptionObject &amp; excp )<br>
     {<br>
     std::cerr &lt;&lt; excp &lt;&lt; std::endl;<br>
     return 1;<br>
     }<br>
  <br>
</div><br>
This will give you an informative error message,<br>
if something goes wrong.</div><br><br>----<br><br>So, the final code should be:<br><br><br><div>  itk::ImageFileReader&lt;RGBImageType&gt;::Pointer PNGreader;<br>  PNGreader = itk::ImageFileReader&lt;RGBImageType&gt;::New();<br>
<br>  PNGreader-&gt;SetFileName( &quot;demoMeanFilter.jpg&quot; );<br><br>
</div>
<div>  itk::ImageFileWriter&lt;OutputImageType&gt;::Pointer PNGwriter;<br>  PNGwriter = itk::ImageFileWriter&lt;OutputImageType&gt;::New();<br><br>  PNGwriter-&gt;SetInput( PNGreader-&gt;GetOutput() );<br>  PNGwriter-&gt;SetFileName(&quot;demoMeanFilter.png&quot; );<br>
</div>
<br>  try<br>
     {<br>
     PNGwriter-&gt;Update();
  <br>
     }<br>
   catch ( itk::ExceptionObject &amp; excp )<br>
     {<br>
     std::cerr &lt;&lt; excp &lt;&lt; std::endl;<br>
     return 1;<br>
     }<br>
  <br><br><br>Note that we have removed the PNGreader-&gt;Update(),<br>since that call will be triggered anyways by the call to<br>Update() in the writer.<br><br><br><br>     Regards,<br><br><br>            Luis<br><br><br>
-----------------------------------------------------------------------------------------<br><div class="gmail_quote">On Fri, Oct 29, 2010 at 3:50 AM, 汪济航 <span dir="ltr">&lt;<a href="mailto:wangjihang88@gmail.com">wangjihang88@gmail.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>Hi,</div>
<div> </div>
<div>I meet a run-time problem when I try to read the jpg format file and save it as png. I just simulate the coding in itkPNGImageIOTest.cxx. </div>
<div>The problem may happen in the coding below</div>
<div> </div>
<div>// Read in the image<br>  itk::PNGImageIO::Pointer io;<br>  io = itk::PNGImageIO::New();</div>
<div>  itk::ImageFileReader&lt;RGBImageType&gt;::Pointer PNGreader;<br>  PNGreader = itk::ImageFileReader&lt;RGBImageType&gt;::New();<br>  PNGreader-&gt;SetFileName( &quot;demoMeanFilter.jpg&quot; );<br>  PNGreader-&gt;SetImageIO(io);<br>

  PNGreader-&gt;Update();</div>
<div>  itk::ImageFileWriter&lt;OutputImageType&gt;::Pointer PNGwriter;<br>  PNGwriter = itk::ImageFileWriter&lt;OutputImageType&gt;::New();<br>  PNGwriter-&gt;SetInput(PNGreader-&gt;GetOutput());<br>  PNGwriter-&gt;SetFileName(&quot;demoMeanFilter.png&quot; );<br>

  PNGwriter-&gt;SetImageIO(io);<br>  PNGwriter-&gt;Write();</div>
<div> </div>
<div>Thanks,</div>
<div> </div>
<div>Jihang</div>
<br>_____________________________________<br></blockquote></div>