Skip to Main Content Skip to Search
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Steve on Image Processing

June 29th, 2007

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.

7 Responses to “imfinfo, imread can automatically detect the image format”

  1. srikanth replied on :

    hi steve,

    I tried changing the extension of a jpeg to tiff. MATLAB did read that as jpeg. however,i was wondering what could be the reason for the “Format signature” to not show anything. All i get is “”.

    thanks

  2. Steve replied on :

    Srikanth—That’s normal with JPEG files.

  3. Kaushik replied on :

    Hi Steve,
    Is there any method to read/access individual file information like the image width or height using ‘imfinfo’ or any other matlab functions. In the sense, I am able to view it in the browser - the file information but I need to load the image width and height into another variable.
    Any method to do this …. ?

    Thank you,
    Regards,
    Kaushik

  4. Steve replied on :

    Kaushik—Why can’t you just use imfinfo?

  5. Damodar replied on :

    Hi Steve;
    i want to convert 417×315(height x width) binary image in to 512×512(height x width) and then compress to (256×256), is there any matlab functions to pad and compress the binary images?

  6. Steve replied on :

    Damodar—imresize, padarray, or ordinary matrix indexing, depending on exactly what effects you are trying to achieve.

  7. Kaushik replied on :

    Thanks Steve,
    I played around with ‘imfinfo’ and found the solution.

    rgds,
    Kaushik

Leave a Reply


Steve Eddins manages the Image & Geospatial development team at The MathWorks and coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.

  • ismail: i love chess keep posting :) can we make a web cam identify a chess set ? so we have a roboarm plays for real...
  • Navan: While black is going to win with a smothered mate, it is hard to see what moves would have led to this...
  • Doug: Forced ’smothermate&# 8217; is about to happen, with the added insult of threatening the queen on the...
  • Viton: Let’s give it a try: - RxQ : White Rook takes black Queen (White King was checked, can’t take...
  • Omar: Hi Steve, when using tformfwd to find corresponding points in the new space, the resulting co-ordinates from...
  • Steve: Cris—You’ ;re right, I should have caught the plot scaling issue. I wasn’t actually trying...
  • Cris Luengo: Not to spoil your upcoming bog entry too much, but if you scale the first graph (times vs Q) by setting...
  • Steve: Jim—Thanks for adding your comment showing how the syntax works for matrices.
  • Jim: for i = A …statements 230; end; Description: The …statements 230; are executed (as MATLAB...
  • Steve: Omar—Nice work.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.

Related Topics