[ITK] CanReadFile checks extension
Bradley Lowekamp
blowekamp at mail.nih.gov
Wed Feb 18 15:29:34 EST 2015
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.
I think the the MRCImageIO also does what you are suggesting:
https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/IO/MRC/src/itkMRCImageIO.cxx#L53-L96
Psudo code:
if known extension
return true
else if valid header
return true
else
return false
I think that logic would produce reasonable error messages when invalid files were encounter, and automatically work for your files.
Brad
On Feb 18, 2015, at 2:48 PM, Мар'ян Климов <nekto1989 at gmail.com> wrote:
> Hi,
>
> 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.
>
> Marian
>
> 2015-02-18 21:20 GMT+02:00 Bradley Lowekamp <blowekamp at mail.nih.gov>:
> Hi,
>
> 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.
>
> If the ImageIO returns false when the header is missing then an error message saying something like[1]:
>
> 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.
> I think having an ImageIO specific message is better than the above generic message.
>
> Additionally, each ImageIO is asked if it CanRead the file. It would be rather cumbersome for each ImageIO to open and read the file.
>
> Specifically what is the situation cause a problem and you want to improve?
>
> Brad
>
>
> [1] https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/IO/ImageBase/include/itkImageFileReader.hxx#L132-L141
>
> On Feb 18, 2015, at 1:58 PM, Matt McCormick <matt.mccormick at kitware.com> wrote:
>
>> Hi Marian,
>>
>> Yes, most of the ImageIO's currently just use file extensions to check
>> if they can read a file. However, contributions that improve this by
>> examining the header would be welcome.
>>
>> Thanks,
>> Matt
>>
>> On Wed, Feb 18, 2015 at 1:27 PM, Мар'ян Климов <nekto1989 at gmail.com> wrote:
>>> Hi all,
>>>
>>> I haven't looked at all IO, but JPEGImageIO and BMPImageIO are checking file
>>> extensions in CanReadFile and return false without looking into header if
>>> extension is wrong (or no extension is present). Is this expected behavior?
>>>
>>> Best regards,
>>> Marian
>>>
>>> _______________________________________________
>>> Community mailing list
>>> Community at itk.org
>>> http://public.kitware.com/mailman/listinfo/community
>>>
>> _______________________________________________
>> Community mailing list
>> Community at itk.org
>> http://public.kitware.com/mailman/listinfo/community
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20150218/bf641544/attachment.html>
More information about the Community
mailing list