imfinfo, imread can automatically detect the image format
Didja know? Functions imfinfo and imread do not depend exclusively on the filename extension (for example, .jpg, .png, .tif, etc.) to determine the image file format. I thought about this because a user sent us an image file yesterday with no extension. The user didn't mention what type of file it was, so I just handed the file to imfinfo:
>> imfinfo SEMparticles ans = Filename: 'SEMparticles' FileModDate: '29-Jun-2007 09:12:35' FileSize: 277598 Format: 'png' FormatVersion:  Width: 603 Height: 390 BitDepth: 24 ColorType: 'truecolor' FormatSignature: [137 80 78 71 13 10 26 10] ...
The automatic format detection works by opening the file, reading the first few bytes, and looking for distinguishing byte patterns. (See the FormatSignature field in the output shown above.)
If the filename does have a recognized image format extension, then imfinfo and imread check the file against that format first.
If you're bored and looking for something amusing to do for the next two minutes, save a JPEG file with a .tif extension and see if you can get MATLAB to read it.
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.