作者singe (阿信)
看板EZsoft
标题[共享] 小图拼大图/蒙太奇(Matlab)
时间Tue Aug 15 12:18:42 2006
因为之後陆续有人写信跟我要这个程式
加上本来存放此程式的空间已经不见(前阵子毕业了)
所以我直接把程式码POST出来供大家参考
(前提还是要有Matlab程式,我用Matlab 7写的)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
[fname path] = uigetfile({'*.jpg';'*.bmp';'*.tif'},'Base Image Selector');
base = imread([path fname]);
dname = uigetdir('C:\','Select Directory of Images to Open');
tic
cell_width = 100;
cell_hight = 100;
pixels = cell_width*cell_hight;
cell_size = [30 40];
cell_pix = cell_size(1)*cell_size(2);
output = cell([cell_hight cell_width]);
base = imresize(base,[cell_hight cell_width],'bilinear');
baseR = base(:,:,1);
baseG = base(:,:,2);
baseB = base(:,:,3);
fid = dir([dname '\*.jpg']);
file_num = size(fid);
resize_pic = cell(1,file_num(1));
for i = 1:file_num(1)
I = imread([dname '\' fid(i).name],'jpg');
resize_pic{i} = imresize(I,cell_size);
end
rand_pic = randint(cell_hight,cell_width,[1 file_num(1)]);
for i = 1:pixels
I = resize_pic{rand_pic(i)};
I(:,:,1) = I(:,:,1) + (double(baseR(i)) - mean2(I(:,:,1)));
I(:,:,2) = I(:,:,2) + (double(baseG(i)) - mean2(I(:,:,2)));
I(:,:,3) = I(:,:,3) + (double(baseB(i)) - mean2(I(:,:,3)));
output{i} = I;
end
output = cell2mat(output);
toc
imwrite(output,uiputfile('*.jpg'));
figure, imshow(output)
--
你可以因为我长得帅而喜欢我...
但我长得帅并不是为了让你喜欢...
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.114.58.115
1F:推 bulin:推.. 08/15 12:52
2F:推 accordingto:push 08/15 20:11
3F:推 cmko:推 我有跟你要过 :) 08/16 02:15
4F:推 llittlefat:推学长 08/16 12:04