<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->SetImageIO(io);<br>
<br>
PNGreader->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'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'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->Update();
<div><br>with:<br><br> try<br> {<br> PNGreader->Update();
<br> }<br> catch ( itk::ExceptionObject & excp )<br> {<br> std::cerr << excp << 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->Update();
<div><br>
with:<br>
<br>
try<br>
{<br>
PNGwriter->Update();
<br>
}<br>
catch ( itk::ExceptionObject & excp )<br>
{<br>
std::cerr << excp << 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<RGBImageType>::Pointer PNGreader;<br> PNGreader = itk::ImageFileReader<RGBImageType>::New();<br>
<br> PNGreader->SetFileName( "demoMeanFilter.jpg" );<br><br>
</div>
<div> itk::ImageFileWriter<OutputImageType>::Pointer PNGwriter;<br> PNGwriter = itk::ImageFileWriter<OutputImageType>::New();<br><br> PNGwriter->SetInput( PNGreader->GetOutput() );<br> PNGwriter->SetFileName("demoMeanFilter.png" );<br>
</div>
<br> try<br>
{<br>
PNGwriter->Update();
<br>
}<br>
catch ( itk::ExceptionObject & excp )<br>
{<br>
std::cerr << excp << std::endl;<br>
return 1;<br>
}<br>
<br><br><br>Note that we have removed the PNGreader->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"><<a href="mailto:wangjihang88@gmail.com">wangjihang88@gmail.com</a>></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<RGBImageType>::Pointer PNGreader;<br> PNGreader = itk::ImageFileReader<RGBImageType>::New();<br> PNGreader->SetFileName( "demoMeanFilter.jpg" );<br> PNGreader->SetImageIO(io);<br>
PNGreader->Update();</div>
<div> itk::ImageFileWriter<OutputImageType>::Pointer PNGwriter;<br> PNGwriter = itk::ImageFileWriter<OutputImageType>::New();<br> PNGwriter->SetInput(PNGreader->GetOutput());<br> PNGwriter->SetFileName("demoMeanFilter.png" );<br>
PNGwriter->SetImageIO(io);<br> PNGwriter->Write();</div>
<div> </div>
<div>Thanks,</div>
<div> </div>
<div>Jihang</div>
<br>_____________________________________<br></blockquote></div>