How to saveas multiple figure in folder using matlab ?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Karim
2022 年 6 月 17 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Printing and Saving についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!