-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimmerge.m
43 lines (38 loc) · 1.18 KB
/
immerge.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
function out = immerge(bg, fg, coef)
% Creates an image 'out' of same type as bg.
% 'out' has 'bg' as background, and 'fg' (transparent,
% weighted by 'coef') above 'bg'.
% Useful when one cannot use OpenGL as renderer, but still
% wants to have transparency!
% 'out', 'bg', and 'fg' are RGB images.
%
% merged = immerged(bg, fg, coef)
% - bg matrix of type double or uint8
% - fg matrix of type double or uint8
% - coef is a scalar between 0 and 1, or a matrix of
% such scalars, same size as 'fg' and 'bg' (AlphaData).
%
% Suggestions for future development:
% - allow to have 'coef' referring to the AlphaMap
% - allow 'coef' to take values between 1 and 64.
%
% Gauthier Fleutot 28-07-2004
% fleutotg@esiee.fr
intOutput = 0; % if we want the output to be of type integer
if ~isa(bg, 'double')
bg = double(bg); % because '-' isn't defined for uint8
intOutput = 1;
end
if ~isa(fg, 'double')
fg = double(fg); % because '-' isn't defined for uint8
end
dif = fg-bg;
if size(coef) == [1 1]
out = bg + coef.*dif;
else
coef = cat(3,coef,coef,coef); % extend the coef matric in the 3rd dim.
out = bg + coef .* dif;
end
if intOutput == 1
out = uint8(out);
end