I am having Permission/format Issue with imwrite and imread while using matlab in linux. How can I resolve the issue?

Hello,
I am working on a program to manipulate images from a folder and transfer it into another folder. The code works prety well on a windows system but when I try to run it on linux I get errors:
Code:
% File handling
inputPath = '/home/user/projectfolder/toBeProcessed/';
outputFull = '/home/user/projectfolder/full/';
ext = '.jpg';
for q=1:totalNoOfImg
%Load image
filename = strcat(inputPath,loc(q+2).name);
inputI = imread(filename);
%Save full
saveFull = saveFull + 1;
imageNo = int2str(saveFull);
filename = strcat(outputFull,imageNo,ext);
% mkdir(outputFull); %%%%this was added after browing for solutions
imwrite(full,filename);
Firstly, I used to get the following error. before adding the lines having many "%" symbol.
____________
Error using imwrite (line 459)
Can't open file "/home/ranga/version2/full/1001.jpg" for writing.
You may not have write permission.
___________
Then I changed the code according to the information I found from other questions and answers. It suggested that I add mkdir the line represented with many "%" symbols.
And now I get this error. And another point is the folder created by mkdir becomes highly secure and I cannot access it by any other means not even by the code that follows.
___________
Error using imread (line 382)
Unable to determine the file format.
_____________
I tried using dbstop if error to find the problem and it points to the following in the first case
if (fid == -1)
error(message('MATLAB:imagesci:imwrite:fileOpen', filename));
else
and to the following in the second case
if (isempty(format))
error(message('MATLAB:imagesci:imread:fileFormat'));
end
I am newbie to matlab and I recently took this code written and executed in windows by my friend to use in a different case in linux environment. Could some one suggest me a solution to this problem. Please remember that the program runs perfectly in windows and I am currently trying it on linux, to be presise in Ubuntu.

Answers (1)

You failed to put the file extension on when you created the file name.
Also, use fullfile() instead of constructing the filename yourself.
Question: is there a reason you are using
loc = dir('/home/user/projectfolder/toBeProcessed');
instead of
loc = dir(inputPath);
??

3 Comments

Oh i neva saw that it can be replaced no issue with that
and about the extension thing does that make a difference when running on windows and on linux?? Because there was not a single error when the program was run in windows
I might have read too quickly with regards to the file extension.
However, your code assumes that you should skip the first two entries of the directory and that all the rest are images. That is an incorrect assumption even on MS Windows: '.' and '..' are not guaranteed to be the first two entries even on MS Windows, and are not at all guaranteed to be the first two entries on OS-X or Linux. You should eliminate the directories from the results returned by dir() by checking the isdir field:
loc = dir('/home/user/projectfolder/toBeProcessed');
loc([loc.isdir]) = []; %remove directories
totalNoOfImg = length(loc);
And for each 'name' you examine you should be checking to see if it is a potential image file, such as by checking its extension.
Ok ill give it a try and get back on it as soon as I can

Sign in to comment.

Categories

Products

Asked:

Sri
on 27 Aug 2013

Community Treasure Hunt

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

Start Hunting!