Re: 【問題】請教批次讀圖/改圖後儲檔

作者: gouaj (Aj)   2014-08-29 14:17:46
※ 引述《gouaj (Aj)》之銘言:
: 請教各位,小弟是新手,目前小弟使用 target_path = uigetdir();
: 先設定了使用目錄,之後要把目錄內所有的*.jpg讀進來
: 然後進行 result_image=imcrop(temp_image,[0 0 760 600]);
: 裁切照片的大小之後,再照原檔名儲存即可。
: 請各位指導一下程式的寫法,謝謝。
@@, 我自己來回文了
%%%將原先是8000x600的影像,自動裁切成760x600
%uigetdir()跳出選擇所要處理的目錄
target_path = uigetdir();
%指定目錄下所有的jpg格式
file_path = [target_path '/*.jpg'];
file_struct = dir(file_path);
%載入目錄內所有jpg檔
for i=1:length(file_struct)
temp_image = imread([target_path '/' file_struct(i).name]);
%影像原尺寸是800x600,指定左上角(0,0)開始範圍為(760,600)裁圖
%儲存原名稱
result_image=imcrop(temp_image,[0 0 760 600]);
imwrite(result_image,[target_path '/' file_struct(i).name]);
end

Links booklink

Contact Us: admin [ a t ] ucptt.com