diff --git a/chromakey/alpha.png b/chromakey/alpha.png index 3c2bf66..0237a3e 100644 Binary files a/chromakey/alpha.png and b/chromakey/alpha.png differ diff --git a/chromakey/bluescreen.m b/chromakey/bluescreen.m index d0827c1..eae3ec6 100644 --- a/chromakey/bluescreen.m +++ b/chromakey/bluescreen.m @@ -23,6 +23,7 @@ ## Author: Jens ## Created: 2020-10-03 +# bluescreen('adventure_rose.jpg', 0.4, 0.4, 4) function retval = bluescreen (img_name, k_sb, k_ds, k_cw) im = im2double(imread(img_name)); im_rgb = imresize(im, 1); diff --git a/chromakey/chromakey.m b/chromakey/chromakey.m new file mode 100644 index 0000000..8d1b82a --- /dev/null +++ b/chromakey/chromakey.m @@ -0,0 +1,90 @@ +## 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 +## . + +## -*- texinfo -*- +## @deftypefn {} {@var{retval} =} bluescreen (@var{input1}, @var{input2}) +## +## @seealso{} +## @end deftypefn + +## Author: Jens +## Created: 2020-10-03 + +function chromakey (img_name) +im = im2double(imread(img_name)); +im_rgb = imresize(im, 1); +se = strel('square',3) + +#ref_rgb = toRef([0.3 0.4 0.65], size(im_rgb)); +ref_rgb = toRef([0.2 0.6 0.95], size(im_rgb)); + +k_ds = 0.2; +k_c_matte = 1.0 +k_e_matte = 3 + +k_c_edge = 3.0 +k_e_edge = 3.0 + +close all; + +figure; +imshow(ref_rgb); + +figure; +matte = min(1, k_c_matte*similarity_rgb(im_rgb, ref_rgb, k_e_matte)); +#matte = mask_clip_below(matte, 0.5); +imshow(matte); title("matte") + +figure; +final = max(0, im_rgb - k_ds*matte.*ref_rgb).*matte; +imshow(final); title("final") + +figure; +edges = k_c_edge*coloredges(final, ref_rgb, k_e_edge); +#edges = mask_clip_below(edges, 0.25); +imshow(edges); title("edges") + +figure; +final_cc = im_rgb - edges.*ref_rgb; +imshow(final_cc); title("final_cc") + +imwrite(final, 'final.png','png','alpha', matte); +imwrite(final_cc, 'final_cc.png','png','alpha', matte); +imwrite(matte, 'alpha.png','png'); + +function r = toRef(ref, d) + r = repmat(reshape(ref,1, 1, 3), d(1), d(2)); +endfunction + +function s = similarity_rgb(im, ref, k) + s = 1-exp(-k*vecnorm (im - ref, 2, 3)); +endfunction + +function s = coloredges(im, ref, k) + s = exp(-k*vecnorm (im - ref, 2, 3)); +endfunction + +function mask = mask_clip_above(mask_in, thresh) + k = mask_in < thresh; + mask = k .* mask_in + kn; +endfunction + +function mask = mask_clip_below(mask_in, thresh) + k = mask_in > thresh; + mask = k .* mask_in + 0; +endfunction + +endfunction diff --git a/chromakey/final.png b/chromakey/final.png index 1aab552..e31638d 100644 Binary files a/chromakey/final.png and b/chromakey/final.png differ