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

Walter Roberson
Walter Roberson 2018년 3월 19일
"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 2018년 3월 19일
Yeah, I don't realized about the path before also changed. Thanks for help!!!

댓글을 달려면 로그인하십시오.

 채택된 답변

Steven Lord
Steven Lord 2018년 3월 2일

1 개 추천

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

Stephen23
Stephen23 2018년 3월 2일
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 2018년 3월 4일
편집: Muhammad Bariq Azmi 2018년 3월 4일
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)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Scripts에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by