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 comentarios

Walter Roberson
Walter Roberson el 19 de Mzo. de 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.
Muhammad Bariq Azmi
Muhammad Bariq Azmi el 19 de Mzo. de 2018
Yeah, I don't realized about the path before also changed. Thanks for help!!!

Iniciar sesión para comentar.

 Respuesta aceptada

Steven Lord
Steven Lord el 2 de Mzo. de 2018

1 voto

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 comentarios

Stephen23
Stephen23 el 2 de Mzo. de 2018
Or indeed do not use anywhere under C:\Program Files at all. The best location to use for storing files is your user directory.
Muhammad Bariq Azmi
Muhammad Bariq Azmi el 4 de Mzo. de 2018
Editada: Muhammad Bariq Azmi el 4 de Mzo. de 2018
Sorry sir, I still have error of write permission. This time, the error point to C:\FYP\work\FYP\crop\crop_037_F_10.jpg. The folder that i keep input picture are also different from error (C:\FYP\work\FYP\PolyU)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Scripts en Centro de ayuda y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by