{"id":149,"date":"2007-06-29T08:49:15","date_gmt":"2007-06-29T12:49:15","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/2007\/06\/29\/imfinfo-imread-auto-detection\/"},"modified":"2019-10-23T13:38:59","modified_gmt":"2019-10-23T17:38:59","slug":"imfinfo-imread-auto-detection","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2007\/06\/29\/imfinfo-imread-auto-detection\/","title":{"rendered":"imfinfo, imread can automatically detect the image format"},"content":{"rendered":"<p>\r\nDidja know? Functions <tt>imfinfo<\/tt> and <tt>imread<\/tt> 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 <tt>imfinfo<\/tt>:\r\n<\/p>\r\n\r\n<pre>\r\n>> imfinfo SEMparticles\r\n\r\nans = \r\n\r\n                  Filename: 'SEMparticles'\r\n               FileModDate: '29-Jun-2007 09:12:35'\r\n                  FileSize: 277598\r\n                    Format: 'png'\r\n             FormatVersion: []\r\n                     Width: 603\r\n                    Height: 390\r\n                  BitDepth: 24\r\n                 ColorType: 'truecolor'\r\n           FormatSignature: [137 80 78 71 13 10 26 10]\r\n                    ...\r\n<\/pre>\r\n\r\n<p>\r\nThe automatic format detection works by opening the file, reading the first few bytes, and looking for distinguishing byte patterns.  (See the <tt>FormatSignature<\/tt> field in the output shown above.)\r\n<\/p>\r\n\r\n<p>\r\nIf the filename does have a recognized image format extension, then <tt>imfinfo<\/tt> and <tt>imread<\/tt> check the file against that format first.\r\n<\/p>\r\n\r\n<p>\r\nIf 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.\r\n<\/p>","protected":false},"excerpt":{"rendered":"<p>\r\nDidja 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... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2007\/06\/29\/imfinfo-imread-auto-detection\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[332,76],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/149"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/comments?post=149"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/149\/revisions"}],"predecessor-version":[{"id":3544,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/149\/revisions\/3544"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}