How to saveas multiple figure in folder using matlab ?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to save the figure in .jpeg format in a new folder. i get an error in this code. please help me to solve this problem. I would be very grateful.
image_folder ='E:\Resize 200'
filenames = dir (fullfile(image_folder,'*.jpeg'))
total_images = numel(filenames);
for n= 1:total_images;
f= fullfile(image_folder, filenames(n).name);
ambang = 40; % ambang mulai dianggap bagian badan
citra = imread(f);
[tinggi, lebar] = size(citra); % ukuran citra
%figure; imshow(citra);
baris_tengah = citra(floor(tinggi / 2), :); % baris tengah citra
kiri = 1; % nilai awal batas kiri
kanan = lebar; % nilai awal batas kanan
for i = 25:lebar % cari dari kiri
if baris_tengah(i) > ambang % kalau sudah tercapai,
kiri = i; % simpan letaknya
break; % berhenti cari
end;
end;
for i = (lebar - 25):-1:1 % cari dari kanan
if baris_tengah(i) > ambang % ,
kanan = i; %
break; %
end;
end;
%figure; hold on;
%plot(baris_tengah);
%plot([kiri kiri], [0 255], 'r'); % batas kiri
%plot([kanan kanan], [0 255], 'r'); % batas kanan
%hold off;
%hasil pangkas
pangkas = imcrop(citra, [kiri 0 (kanan - kiri) tinggi]);
figure;
imshow(pangkas);
saveas (figure, 'baru',f(i));
end
0 commentaires
Réponses (1)
Karim
le 17 Juin 2022
Hello,
Witouth the figures or the error message it's not really clear which error you obtain. But at first glance the saveas command doesn't seem correct. The variable f holds the full filename of the original picture, and you ask the i'th element from that.
Can you try to change the command into something like:
currFig = figure;
imshow(pangkas);
saveas(currFig, fullfile(image_folder, ['baru ' filenames(n).name]));
By doing so you basically append the original filename with "baru". Note that this will save it in the orginal folder, but with a different name.
0 commentaires
Voir également
Catégories
En savoir plus sur Printing and Saving 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!