-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
merge.m
69 lines (62 loc) · 1.55 KB
/
merge.m
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
67
68
69
function [ newImg ] = merge( imgs, transforms, newHeight, newWidth ,f)
imgs=im2double(imgs);
height = size(imgs, 1);
width = size(imgs, 2);
nChannels = size(imgs, 3);
nImgs = size(imgs, 4);
mask = ones(height, width);
mask = warp(mask, f);
mask = imcomplement(mask);
mask = bwdist(mask, 'euclidean');
mask = mask ./ max(max(mask));
%mask(mask>1)=1;
m=ones([height,width,nChannels],'like',imgs);
for i=1:nChannels
m(:,:,i)=mask;
end
mask=m;
% image merging
max_h=0;
min_h=0;
max_w=0;
min_w=0;
for i=1:nImgs
p_prime=transforms(:,:,i)*[1;1;1];
p_prime=p_prime./p_prime(3);
base_h=floor(p_prime(1));
base_w=floor(p_prime(2));
if base_h>max_h
max_h=base_h;
end
if base_h<min_h
min_h=bash_h;
end
if base_w>max_w
max_w=base_w;
end
if base_w<min_w
min_w=base_w;
end
end
newImg = zeros([newHeight+20,newWidth+20,nChannels], 'like',imgs);
denominator = zeros([newHeight+20,newWidth+20,nChannels], 'like',imgs);
for i=1:nImgs
p_prime=transforms(:,:,i)*[min_h+10;min_w+10;1];
p_prime=p_prime./p_prime(3);
base_h=floor(p_prime(1));
base_w=floor(p_prime(2));
if base_h==0
base_h=1;
end
if base_w==0
base_w=1;
end
newImg(base_h:base_h+height-1,base_w:base_w+width-1,:)=...
newImg(base_h:base_h+height-1,base_w:base_w+width-1,:)+...
imgs(:,:,:,i).*mask;
denominator(base_h:base_h+height-1,base_w:base_w+width-1,:)=...
denominator(base_h:base_h+height-1,base_w:base_w+width-1,:)+...
mask;
end
newImg=newImg./denominator;
end