Problem of imwrite permission
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Muhammad Bariq Azmi
le 2 Mar 2018
Commenté : Muhammad Bariq Azmi
le 19 Mar 2018
Hi!, recently I have been troubled with getting cropped picture for given input. What I expected are from input PolyU_0034_F.bmp will become crop_0034_F.jpg for example the code are:
file = dir('C:\Program Files\MATLAB\R2017a\bin\FYP\PolyU\*.bmp');
input = {file.name}';
c = input;
for i = 1:length(file)
fname = strcat('C:\Program Files\MATLAB\R2017a\bin\FYP\PolyU\',file(i).name);
a = imread(fname);
b = imcrop(a,[140,65,150,150]);
c{i} = strrep(fname, 'PolyU', 'crop');
d = c{i};
imwrite(b,strrep(d, '.bmp', '.jpg'));
imshow(b);
end
However, The error given out are
Error using imwrite (line 454)
Unable to open file "C:\Program Files\MATLAB\R2017a\bin\FYP\crop\crop_037_F_10.jpg" for writing. You might not have write
permission.
Error in corp1 (line 24)
imwrite(b,strrep(d, '.bmp', '.jpg'));
This is weird for 2 reasons. First, the file direction on error is different folder (crop) even though I use folder of (PolyU). Second, This code was done on different folder(FYP) and execute very well. Are same code in different folder need to readjust so that it could work again?
Thanks for your time!
2 commentaires
Walter Roberson
le 19 Mar 2018
"First, the file direction on error is different folder (crop) even though I use folder of (PolyU)."
No you do not. You strrep(fname, 'PolyU, 'crop') to replace PolyU with crop, and then you use that as the destination for imwrite, so it is expected that you write to the crop directory.
Réponse acceptée
Steven Lord
le 2 Mar 2018
In general trying to write files in a directory under the MATLAB root directory is probably not a good idea, and in this case the error indicates you don't have write permissions to that directory and/or that file.
I strongly recommend moving your FYP subdirectory somewhere else that is NOT under "C:\Program Files\MATLAB\R2017a".
3 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!