Unable to open file "binaryeye.jpg" for writing. You may not have write permission.

121 vues (au cours des 30 derniers jours)
Hi, i am trying to run this program but i keep getting this error "Unable to open file "binaryeye.jpg" for writing. You may not have write permission. "
The code which i am trying is:
im=imread('2.jpg');
imgray=rgb2gray(im);
imgray=double(imgray);
[imgx,imgy]=gradient(imgray);
imggra=sqrt(imgx.^2+imgy.^2);
imedge=uint8(imggra);
imedge=imadjust(imedge);
imedge=im2bw(imedge);
imwrite(imedge,'binaryeye.jpg');
[imr,imc]=size(imgray);
maxvalue=eps;
maxr=0;
maxx=1;
maxy=1;
for radius=9:13
for i=radius+1:imr-radius
for j=radius+1:imc-radius
maxcount=0;
for theta=0:pi/60:2*pi
y=floor(radius*sin(theta))+i;
x=floor(radius*cos(theta))+j;
if imedge(y,x)==true
maxcount=maxcount+1;
end
% y=floor((radius-1)*sin(theta))+i;
% x=floor((radius-1)*cos(theta))+j;
% if imedge(y,x)==true
% maxcount=maxcount+1;
% end
if maxcount>maxvalue
maxvalue=maxcount;
maxr=radius;
maxx=j;
maxy=i;
end
end
end
end
end
maxr,maxx,maxy
imgray=uint8(imgray);
figure,imshow(imgray)
hold on;
for theta=0:pi/50:2*pi
x=floor(maxr*cos(theta))+maxx;
y=floor(maxr*sin(theta))+maxy;
plot(x,y,'b*-');
end
However i keep getting this error
Error using imwrite (line 455)
Unable to open file "binaryeye.jpg" for writing. You may not have write
permission.
what can i do to solve it? i already change the setting of the folder containing binaryeye.jpg to be written.
Thanks.
  3 commentaires
Walter Roberson
Walter Roberson le 7 Mai 2018
That was the complete code.
RAVI KIRAN DASARI
RAVI KIRAN DASARI le 8 Mai 2018
I'm also having same issue with that "imwrite" function. Can anyone please help us.

Connectez-vous pour commenter.

Réponse acceptée

Geoff Hayes
Geoff Hayes le 17 Nov 2014
Jia - are you sure that you have given the write permission to the correct folder where the image should be written to? Perhaps you should explicitly define the path to the folder as
folder = '/Users/jia/someFolder';
imwrite(imedge,fullfile(folder,'binaryeye.jpg'));
If that doesn't work, then check to see if the file already exists in this folder. Perhaps you don't have permission to overwrite it.
  2 commentaires
sameerah talafha
sameerah talafha le 7 Nov 2017
thank you so much, your answer help me haha in somehow thanks
yeny ortiz
yeny ortiz le 22 Oct 2020
ejecutando como administrador y ya

Connectez-vous pour commenter.

Plus de réponses (2)

Mridul Pandey
Mridul Pandey le 18 Nov 2017
change present working directory to the desired directory where you want to save the file either change in on the command window or script. like.. cd c:\folder\folder\... and then use imsave(...) function.
  3 commentaires
Image Analyst
Image Analyst le 13 Déc 2018
No way! NOT a bug in MATLAB.
How can you say that bad programming practice by a novice user is a bug in MATLAB???
Geoff gave the proper way - using fullfile(). Just because you can do it by using cd() (like a novice) and not using fullfile() (like an expert would) does not mean that that is a bug in MATLAB.
It's not a bug - it's a feature.bmp
Walter Roberson
Walter Roberson le 13 Déc 2018
Mathworks recommends not using cd unless necessary. Every time you cd, Mathworks has to recheck the path resolution for functions, just in case you happened to cd to a directory that had a function whose name was the same as a function already being called.

Connectez-vous pour commenter.


Tushant Verma
Tushant Verma le 21 Oct 2021
Well, I also faced the same issue, so what i did was I just changed the directory to which i am writing my file to,and then the code worked as desired. I would recommend you to write in some folder of drive other then the one where MATLAB is installed.
Hope this will help.

Catégories

En savoir plus sur Search Path dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by