IMREAD error: Unable to determine the file format

164 views (last 30 days)
Michael Martin
Michael Martin on 5 Jan 2013
I am having trouble getting a code to finish without error. The error message is with IMREAD.
Here's an overview of my code & problem:
I have 41 images in 9 different folders. My code iterates through each folder, and thus each image. During the iteration IMREAD reads an image, alters it, then IMWRITE writes the altered file in the same directory under a different file name such that the original images and new written images are now in that directory.
The image directories look like this:
In each directory are 41 images. All .tiff files. Each set of images also have the same naming scheme: 0.tiff : 40.tiff
The code successfully iterates through /.../Test2/3
At /.../Test3/1 images 0:9 are ran through the code, then this error message comes up:
Error using imread (line 381)
Unable to determine the file format.
Error in pathwayVersion02 (line 36)
Here is my code:
R = {'3' '3' '3'};
r = length(R);
folderbase = {'Test1','Test2','Test3'};
filepath = '/Users/imgcompute/Desktop/Mock2/';
m = length(folderbase);
B = rdir('/Users/imgcompute/Desktop/Mock2/Test2/Half_Frames/');
lengthB = length(B);
for j = 1:m
Half_Frames = 'Half_Frames/';
filename1 = strcat(filename1, Half_Frames);
for rr = 1:r
rr = num2str(rr);
C = char(strcat(filename1,rr,'/'))
file_names = rdir(C);
for s = 1:length(file_names)
if file_names(s).bytes >=10000;
file_count = num2str(file_count);
a=['This is pic num',num2str(file_count)];
% code

Answers (2)

Walter Roberson
Walter Roberson on 5 Jan 2013
dbstop if error
at the command line, and re-run. When the program stops, determine the file name that is giving the problem. Try to imread() that file at the command line. Copy the filename, and close MATLAB and restart, and then try to imread() that same file. If both times the read fails, you can be sure that it is something in the file rather than a difficulty with running out of some kind of resource because of the loop.
There is a possibility that you might find an unexpected file in that directory that is not an image file.
If it does look like a real image file, does Windows Explorer have problems opening it?
Try using imfinfo() on the file. Try it including 'tiff' as the format, and try it with 'jpg' as well, in case the file is a real image but not a tiff image.
Image Analyst
Image Analyst on 7 Jan 2013
I still don't know why you don't just set up the file pattern so that you get only files with the proper extension like I suggested.

Sign in to comment.

Image Analyst
Image Analyst on 5 Jan 2013
Replace this line:
file_names = rdir(C);
with this:
file_names = dir('*.tif');
and try again. And then this line - not sure what problems that might cause with the null prepended - maybe none, but try this more robust way.
folder = filename1;
fullFileName = fullfile(folder, file_names(s).name);
oldimage=imread(fullFileName );
Also, you might want to look at genpath() to generate all subfolders automatically.
  1 Comment
Walter Roberson
Walter Roberson on 5 Jan 2013
['',string] is the same as string, provided that string is char data type -- even if string is a strangely-sized empty string such as ones(1,1,0)

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by