How to saveas multiple figure in folder using matlab ?
조회 수: 5 (최근 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!