- added matlab scripts
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
## Copyright (C) 2020 Jens
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify it
|
||||
## under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful, but
|
||||
## WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with this program. If not, see
|
||||
## <https://www.gnu.org/licenses/>.
|
||||
|
||||
## -*- texinfo -*-
|
||||
## @deftypefn {} {@var{retval} =} alpha_gen (@var{input1}, @var{input2})
|
||||
##
|
||||
## @seealso{}
|
||||
## @end deftypefn
|
||||
|
||||
## Author: Jens <jens@orion>
|
||||
## Created: 2020-10-07
|
||||
|
||||
function a = alpha_gen(N, slope)
|
||||
s = (0:N-1)/(N-1);
|
||||
a = to_param(s, 0, 1, 2, -slope, 0.5, 0.5);
|
||||
|
||||
color_bg = [0.1 0.3 0.9];
|
||||
color_fg = [0.9 0.9 0.0];
|
||||
|
||||
mean_fg = mean(color_fg)
|
||||
norm_fg = norm(color_fg)
|
||||
mean_bg = mean(color_bg)
|
||||
norm_bg = norm(color_bg)
|
||||
|
||||
w = N;
|
||||
h = 8;
|
||||
|
||||
im_a = repmat(a, h, 1);
|
||||
|
||||
|
||||
im_comp = to_im (color_fg, a, h) + to_im (color_bg, 1-a, h);
|
||||
im_fg = to_ref(color_fg, size(im_comp));
|
||||
im_bg = to_ref(color_bg, size(im_comp));
|
||||
|
||||
im_ac = (im_comp - im_bg)./(im_fg - im_bg);
|
||||
|
||||
close all;
|
||||
figure;
|
||||
imshow(im_a); title ("im_a")
|
||||
|
||||
figure;
|
||||
imshow(im_ac); title ("im_ac")
|
||||
|
||||
figure;
|
||||
imshow(im_comp); title ("im_comp")
|
||||
|
||||
figure;
|
||||
im_filtered = im_comp - to_ref(color_bg, size(im_comp));
|
||||
imshow(im_filtered); title ("im_filtered")
|
||||
|
||||
strip = im_filtered(1,:,:);
|
||||
strip_clamped = max(0, strip);
|
||||
strip_clamped_norm = strip_clamped;
|
||||
n = vecnorm(strip, 2, 3)/norm_fg;
|
||||
figure;
|
||||
plot (s, a, s, n); grid; legend("Ground truth", "Calculated")
|
||||
|
||||
endfunction
|
||||
|
||||
function im = to_im(color, a, h)
|
||||
w = length(a);
|
||||
im = reshape([color(1)*ones(h,1)*a color(2)*ones(h,1)*a color(3)*ones(h,1)*a], h, w, 3);
|
||||
|
||||
endfunction
|
||||
|
||||
function r = to_ref(ref, d)
|
||||
r = repmat(reshape(ref,1, 1, 3), d(1), d(2));
|
||||
endfunction
|
||||
@@ -0,0 +1,75 @@
|
||||
## Copyright (C) 2020 Jens
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify it
|
||||
## under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful, but
|
||||
## WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with this program. If not, see
|
||||
## <https://www.gnu.org/licenses/>.
|
||||
|
||||
## -*- texinfo -*-
|
||||
## @deftypefn {} {@var{retval} =} bluescreen (@var{input1}, @var{input2})
|
||||
##
|
||||
## @seealso{}
|
||||
## @end deftypefn
|
||||
|
||||
## Author: Jens <jens@orion>
|
||||
## Created: 2020-10-03
|
||||
|
||||
# chromakey('adventure_rose', 20, 10)
|
||||
# chromakey('cineon_before', 200, 100)
|
||||
|
||||
function eval_matte (prj_name, k_e_matte)
|
||||
|
||||
clip_white_thresh = 0.80;
|
||||
clip_white_amp = 3;
|
||||
|
||||
clip_black_thresh = 0.20;
|
||||
clip_black_amp = 3;
|
||||
|
||||
[im_rgb, ref_rgb] = prj_load(prj_name);
|
||||
|
||||
close all;
|
||||
|
||||
pre_filtered = im_rgb - ref_rgb;
|
||||
pre_filtered_p = max(0,pre_filtered);
|
||||
pre_filtered_n = -min(0,pre_filtered);
|
||||
|
||||
figure;
|
||||
imshow(abs(pre_filtered)); title("pre_filtered")
|
||||
|
||||
figure;
|
||||
filtered_var = var(pre_filtered, 0, 3);
|
||||
|
||||
kn = 1/max(max(filtered_var(:)))
|
||||
var_n = k_e_matte*kn*filtered_var;
|
||||
matte = min(1, var_n);
|
||||
imshow(matte); title("var")
|
||||
|
||||
figure;
|
||||
filtered_norm = vecnorm(pre_filtered, 2, 3);
|
||||
imshow(filtered_norm); title("norm")
|
||||
|
||||
figure;
|
||||
intermediate = im_rgb.*matte;
|
||||
imshow(intermediate); title("intermediate")
|
||||
|
||||
figure;
|
||||
edges = exp(-1.7*k_e_matte*var(intermediate - ref_rgb, 0, 3));
|
||||
imshow(edges); title("edges")
|
||||
|
||||
figure;
|
||||
final = intermediate - edges.*ref_rgb;
|
||||
imshow(final); title("final")
|
||||
|
||||
imwrite(intermediate, sprintf('%s.intermediate.png',prj_name),'png','alpha', matte);
|
||||
imwrite(edges, sprintf('%s.edges.png',prj_name),'png');
|
||||
imwrite(final, sprintf('%s.final.png',prj_name),'png','alpha', matte);
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
## Copyright (C) 2020 Jens
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify it
|
||||
## under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful, but
|
||||
## WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with this program. If not, see
|
||||
## <https://www.gnu.org/licenses/>.
|
||||
|
||||
## -*- texinfo -*-
|
||||
## @deftypefn {} {@var{retval} =} to_param (@var{input1}, @var{input2})
|
||||
##
|
||||
## @seealso{}
|
||||
## @end deftypefn
|
||||
|
||||
## Author: Jens <jens@orion>
|
||||
## Created: 2020-10-07
|
||||
|
||||
function p = to_param(x, pmin, pmax, B, k, pcenter, scenter)
|
||||
|
||||
if (pmin == pmax)
|
||||
pmax += 1E-9;
|
||||
end
|
||||
|
||||
if (k == 0)
|
||||
k = 1E-9;
|
||||
end
|
||||
|
||||
if ((pcenter < pmin) || (pcenter > pmax))
|
||||
pcenter = pmax*scenter + pmin*(1-scenter);
|
||||
end
|
||||
|
||||
x = min(1, max(0, x));
|
||||
kc = 1/(B^k-1);
|
||||
p = [];
|
||||
for n=1:length(x);
|
||||
s = x(n);
|
||||
if (s < scenter)
|
||||
s = (scenter-s)/scenter;
|
||||
ks = -(pcenter-pmin);
|
||||
else
|
||||
s = (-scenter+s)/(1-scenter);
|
||||
ks = (pmax-pcenter);
|
||||
end
|
||||
if (B == 1)
|
||||
p = [p pcenter + ks*kc*s];
|
||||
else
|
||||
p = [p pcenter + ks*kc*(B.^(k*s)-1)];
|
||||
end
|
||||
end
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user