Unable to read image.JPG file
4 Comments
Accepted Answer
More Answers (2)
0 votes
1 Comment
Hello, I am getting the same error. However, when I check with the recommended 'exist', the output is 2. Which, according to the documentation, means: "2 — name is a file with extension .m, .mlx, or .mlapp, or name is the name of a file with a non-registered file extension (.mat, .fig, .txt)." How can I move forward?
I am confused imread is in a loop, and all the files are .jpg files. However, when I loop, some of the images result in the error. Here is the relevant portion of my code. Thank you.
display ('top'); %Get list of all files in the folder with the desired file name pattern filePattern = fullfile(myFolder, '*.jpg'); %find files that are .jpg jpegFiles = dir(filePattern); %dir = list all files that match .jpg (from filePattern)
if ~isdir(myFolder) errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder); uiwait(warndlg(errorMessage)); return; end
display ('before loop'); for k = 1:length(jpegFiles) %loop through all .jpg files display ('inside loop'); baseFileName = jpegFiles(k).name; %name of .jpgs (indexed individually (k)); Ex: SDC10705_RS.jpg fullFileName = fullfile(myFolder, baseFileName); %fullfile builds filename from parts = myfolder\baseFileName (full path of ^) fprintf(1, 'Now reading %s\n', fullFileName); imageArray = imread(fullFileName); %read specific FULLfilename from store of .jpg files %this should be the full
%Rotate
display ('rotation');
%raw= jpegFiles(k).name;
I = imread(jpegFiles(k).name); %must have imread for next step to work (rotation of I)
R = imrotate(I, 355, 'bicubic'); %put angle and type of rotation here. 'bicubic' works best/ least distortion
imshow(R); %display image
%drawnow; %force display to update immediately %Break up fileparts to allow saving with '_rotate' extension when looping through files
[tmp_path, tmp_name, tmp_ext] = fileparts(fullFileName); %separating fullFileName, into path, name, and ext (.jpg) (pretty much opposite of fullfile)
%need to do this so .jpg is at the end
fullFileName_rotate = [tmp_path, filesep, tmp_name, '_rotate',tmp_ext]; imwrite(R, fullFileName_rotate); %new rotated image
%saved as filename_rotate1 Comment
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!