<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>So the commonly suggested work around is that you can explicitly set the ImageIO to the ImageFileReader. ( Many examples exist in ITK/Examples/IO which contain calls to SetImageIO. ) If you can determine which one to use outside of ITK you can manually set it.</div><div><br></div><div>I think the the MRCImageIO also does what you are suggesting:</div><div><a href="https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/IO/MRC/src/itkMRCImageIO.cxx#L53-L96">https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/IO/MRC/src/itkMRCImageIO.cxx#L53-L96</a></div><div><br></div><div>Psudo code:</div><div><br></div><div>if known extension</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return true</div><div>else if valid header</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return true</div><div>else</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return false</div><div><br></div><div>I think that logic would produce reasonable error messages when invalid files were encounter, and automatically work for your files.</div><div><br></div><div>Brad</div><br><div><div><div>On Feb 18, 2015, at 2:48 PM, Мар'ян Климов <<a href="mailto:nekto1989@gmail.com">nekto1989@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div dir="ltr"><div><div>Hi,<br><br></div>I want ImageFileReader to read file without extension (and I don't know would it be TIFF, BMP or JPEG inside). TIFF isn't checking for extension and just checks header. BMP and JPEG are checking extension and only if extension is proper they check for proper header in CanReadFile. I don't think checking for extension is needed at all.<br><br></div>Marian<br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-02-18 21:20 GMT+02:00 Bradley Lowekamp <span dir="ltr"><<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi,<div><br></div><div>The CanRead method is used by the ImageIO Factory system to determine the correct ImageIO to use. Currently if you have a corrupt JPEG, the JPEGImageIO will be selected, then I presume it will give an error message saying that JPEGImageIO is unable to read the file.</div><div><br></div><div>If the ImageIO returns false when the header is missing then an error message saying something like[1]:</div><div><br></div><div><pre style="background-color:rgb(255,255,255)">Description: Could not create IO object for file..
Tried to create one of the following:
JPEGImageIO
GDCMImageIO
BMPImageIO
LSMImageIO
PNGImageIO
TIFFImageIO
VTKImageIO
StimulateImageIO
BioRadImageIO
MetaImageIO
NiftiImageIO
NrrdImageIO
GiplImageIO
HDF5ImageIO
PNGImageIO
JPEGImageIO
You probably failed to set a file suffix, or
set the suffix to an unsupported type.</pre><div>I think having an ImageIO specific message is better than the above generic message.</div></div><div><br></div><div>Additionally, each ImageIO is asked if it CanRead the file. It would be rather cumbersome for each ImageIO to open and read the file.</div><div><br></div><div>Specifically what is the situation cause a problem and you want to improve?</div><div><br></div><div>Brad</div><div><br></div><div><br></div><div>[1] <a href="https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/IO/ImageBase/include/itkImageFileReader.hxx#L132-L141" target="_blank">https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/IO/ImageBase/include/itkImageFileReader.hxx#L132-L141</a></div><div><div class="h5"><div><br></div><div><div><div>On Feb 18, 2015, at 1:58 PM, Matt McCormick <<a href="mailto:matt.mccormick@kitware.com" target="_blank">matt.mccormick@kitware.com</a>> wrote:</div><br><blockquote type="cite">Hi Marian,<br><br>Yes, most of the ImageIO's currently just use file extensions to check<br>if they can read a file. However, contributions that improve this by<br>examining the header would be welcome.<br><br>Thanks,<br>Matt<br><br>On Wed, Feb 18, 2015 at 1:27 PM, Мар'ян Климов <<a href="mailto:nekto1989@gmail.com" target="_blank">nekto1989@gmail.com</a>> wrote:<br><blockquote type="cite">Hi all,<br><br>I haven't looked at all IO, but JPEGImageIO and BMPImageIO are checking file<br>extensions in CanReadFile and return false without looking into header if<br>extension is wrong (or no extension is present). Is this expected behavior?<br><br>Best regards,<br>Marian<br><br>_______________________________________________<br>Community mailing list<br><a href="mailto:Community@itk.org" target="_blank">Community@itk.org</a><br><a href="http://public.kitware.com/mailman/listinfo/community" target="_blank">http://public.kitware.com/mailman/listinfo/community</a><br><br></blockquote>_______________________________________________<br>Community mailing list<br><a href="mailto:Community@itk.org" target="_blank">Community@itk.org</a><br><a href="http://public.kitware.com/mailman/listinfo/community" target="_blank">http://public.kitware.com/mailman/listinfo/community</a><br></blockquote></div><br></div></div></div></div></blockquote></div><br></div>
</blockquote></div><br></div></body></html>