Tuesday, February 27, 2018

Matlab: 批量等比例调整图片尺寸

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
% Created by LI Xu
% Version 1.0
% February 28, 2018

% Description:
% Resize Images

% If you have any question about this code,
% please do not hesitate to contact me via E-mail: 
% jeremy456@163.com

% Blog:
% http://blog.sciencenet.cn/u/lixujeremy
% http://lixuworld.blogspot.com/

clear;
clc;

timebegin=tic;
cur_data=date;
cur_time=fix(clock);
str1=sprintf('%s %.2d:%.2d:%.2d', cur_data, cur_time(4), cur_time(5), cur_time(6)); 
fprintf('Time Begin: ');
fprintf(str1);
fprintf('\n');

% Source Directory
SouDir='input';
% Destination Directory
DesDir='output';

% Resize Scale
ReScale=0.1;

% All Images
files=dir(SouDir);
files=files(3:end);


% Loop
parfor ii=1:length(files)
    filepath=fullfile(SouDir, files(ii).name);
    image=imread(filepath);
    otimage=imresize(image, ReScale);
    
    otpath=fullfile(DesDir, files(ii).name);
    imwrite(otimage, otpath);
    
    
    str4dp=[num2str(ii), '.', files(ii).name, ' done!'];
    disp(str4dp);
end

fprintf('Time Begin: ');
fprintf(str1);
fprintf('\n');

cur_data=date;
cur_time=fix(clock);
str2=sprintf('%s %.2d:%.2d:%.2d', cur_data, cur_time(4), cur_time(5), cur_time(6)); 
fprintf('Time End: ');
disp(str2);
timespan=toc(timebegin);
fprintf('Time Span: %.4f s\n', timespan);

disp('*************************************');

No comments:

Post a Comment