How to save multiple crop picture with output picture name is same as input picture name?

14 vues (au cours des 30 derniers jours)
Hi, I am really new in this Matlab coding. My problem is I try to create a coding with will read a multiple numbers of picture inside a folder and crop it into multiple small picture and save it on other folder. However, I am stuck on creating a save crop picture which is the retain some name from input picture.
For example: Input : PolyU_002_S_02 PolyU_003_S_03 PolyU_002_S_04
After the cropping and save, Output: crop_002_S_02 crop_002_S_02 crop_002_S_02
Here is my latest coding which still have some error
if true
file = dir('C:\Program Files\MATLAB\R2017a\bin\FYP\*.bmp');
out = 'C:\Program Files\MATLAB\R2017a\bin\FYP\corp';
src = 'C:\Program Files\MATLAB\R2017a\bin\FYP\';
folder = dir([src '*.bmp']);
input = {folder.name}';
c = input;
for i = 1:length(folder)
fname = strcat('C:\Program Files\MATLAB\R2017a\bin\FYP\',file(i).name);
a = imread(fname);
b = imcrop(a,[140,65,150,150]);
c{i} = strrep(file(i).name, 'PolyU', 'crop');
imwrite(b,[out c{i}],'.bmp');
end end
Thanks for the help!

Réponse acceptée

Rik
Rik le 21 Nov 2017
There are multiple things you could improve in this code, but replacing the next two lines with the subsequent two should solve your issue.
%replace this:
c{i} = strrep(file(i).name, 'PolyU', 'crop');
imwrite(b,[out c{i}],'.bmp');
%with this:
c{i} = strrep(fname, 'PolyU', 'crop');
imwrite(b,c{i});
  1 commentaire
Muhammad Bariq Azmi
Muhammad Bariq Azmi le 22 Nov 2017
Modifié(e) : Muhammad Bariq Azmi le 22 Nov 2017
It works! thanks! Mind to tell me on how I could improve this coding beside on how save the crop picture on different folder, sir?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Feature Detection and Extraction 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