matlab自動保存圖像

在使用imwrite函數對圖片進行保存時需要指定圖像位置及圖像名稱,不同的圖像結果進行保存不免有些麻煩,所以在此寫下自動保存圖像方法。

clear all;clc;close all;
Img_path = '../origin-imgs/Dawn Sky.jpg';
path = '../result';
origin_Img = imread(Img_path);
[dir, file, ext] = fileparts(Img_path);
filename = [file, '_another',ext];
newPath = fullfile(path,filename);
newPath = strrep(newPath,'\','/');
imwrite(origin_Img, newPath);
fileparts:

獲取文件名的組成部分。
** 用法:**
** [filepath, name, ext] = fileparts(filename)**
返回文件的路徑名稱、文件名、擴展名。

fullfile:

創建合成完整的地址字符串。
例:

file = fullfile('C:','A','one','example.m')
file =

    'C:\A\one\example.m'

這得到的是絕對路徑,如果使用相對路徑時需要使用strrep函數將’/'替換成 '/'

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章