How to saveas multiple figure in folder using matlab ?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Karim
il 17 Giu 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 Commenti
Vedere anche
Categorie
Scopri di più su Printing and Saving in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!