|
本帖最后由 indeedzcr 于 2016-12-23 23:10 编辑
每年年底,照例福州GDG都将发布一个重大的社区帖。2015年是全年社区工作总结,2016年底发布的是虚拟现实的产业研究。
原谅我们比较懒,文字加图片一段一段粘贴比较浪费时间,因此全文粘贴,欢迎拍砖!
另外,出于程序员的本能,重复超过三次的工作,一定要交给程序完成。
为了拼接上面的这些图片,在matlab2015环境下,用m语言编写了图片拼接程序。
这个程序可以将任意尺寸的图片集合,按照每batch_size张图片分成子集,并将子集中的图片自动放大缩小到对齐,然后把这些子集的对齐的图片拼接成纵向大图,然后按照编号区间排列好,输出保存。
可以用在微信公众号发长图或者类似这种传图有限制的论坛编辑维护上。
% ===========清除内存工作空间==============================
clear;clc;close all
% ==========所有的输入变量===============================
col_set = 1024;%全部图片都缩放到这个像素的宽度
% 纵向拼接,因此行的数量由拼接图片数量决定不可设定,列的数量可以随意配置。
start_index = 1900;%1901-1051
image_total = 51;% 一共51张图片
batch_size = 4; %每组4张图片
filename_prefix = ['word2jpg-'];
filename_filetype= ['.jpg'];
% ===========根据输入变量预计算==============================
no_batch = floor(51/4);% =12 前12组刚刚好
image_remain = image_total - batch_size * no_batch; %=3 剩下3张
% ==========开始函数体===============================
w1_vec = zeros(image_total,1);
for i = 1:image_total
no = start_index + i ;
filename = [filename_prefix num2str(no) filename_filetype];
x=imread(filename);%
[w1,w2,w3] = size(x); % 图片w1行,w2列,w3的颜色维度
clear x;
scale = col_set/w2;%缩放因子
row_cal = floor(w1*scale);
w1_vec(i) = row_cal;
disp(['done! reading image ' num2str(i) ]);
end
for i = 1:no_batch
for j = 1:batch_size
no_image = (i-1)*batch_size + j;
if j ==1
w1_selected_vec = w1_vec(no_image:1no_image+batch_size-1));
w1_out = sum (w1_selected_vec);
image_out = zeros(w1_out,col_set,w3);
image_out = uint8(image_out);
pointer = 1;
end
no = start_index+ no_image;
filename = [filename_prefix num2str(no) filename_filetype];
x = imread(filename);%
x = imresize(x, [w1_selected_vec(j) , col_set]);%指定尺寸缩放
pointer_stop = pointer+w1_selected_vec(j) - 1;
image_out( pointer:pointer_stop , :, = x;
pointer = pointer_stop+1;
clear x;
end
filename_save = [num2str(no-batch_size+1) '-' num2str(no)];
filetype_save = ['.png'];
imwrite(image_out,[filename_save filetype_save]);
disp(['done! writing image ' filename_save ]);
end
if image_remain >0
for j=1:image_remain
no_image = no_batch*batch_size + j;
if j ==1
w1_selected_vec = w1_vec(no_image:1no_image+image_remain-1));
w1_out = sum (w1_selected_vec);
image_out = zeros(w1_out,col_set,w3);
image_out = uint8(image_out);
pointer = 1;
end
no = start_index+ no_image;
filename = [filename_prefix num2str(no) filename_filetype];
x = imread(filename);%
x = imresize(x, [w1_selected_vec(j) , col_set]);%指定尺寸缩放
pointer_stop = pointer+w1_selected_vec(j) - 1;
image_out( pointer:pointer_stop , :, = x;
pointer = pointer_stop+1;
clear x;
end
filename_save = [num2str(no-image_remain+1) '-' num2str(no)];
filetype_save = ['.png'];
imwrite(image_out,[filename_save filetype_save]);
disp(['done! writing image ' filename_save ]);
end
|
|