作者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