diff --git a/chromakey/alpha.png b/chromakey/alpha.png index cc321f5..14f2c05 100644 Binary files a/chromakey/alpha.png and b/chromakey/alpha.png differ diff --git a/chromakey/chromakey.m b/chromakey/chromakey.m index 44248da..21bd38a 100644 --- a/chromakey/chromakey.m +++ b/chromakey/chromakey.m @@ -28,77 +28,41 @@ im = im2double(imread(img_name)); im_rgb = imresize(im, 1); se = strel('square',3) -ref = [0.3 0.4 0.65]; # cineon_before -#ref = 0.2 0.6 0.95]; # adventure_rose - -ref_c = 1 - ref +#ref = [0.3 0.4 0.65]; # cineon_before +ref = [0.2 0.6 0.95]; # adventure_rose ref_rgb = toRef(ref, size(im_rgb)); -ref_rgb_c = toRef(ref_c, size(im_rgb)); -k_ds = 0.2; -k_e_matte = 5.0 -k_e_edge = 3.0 +k_ds_matte = 1.0; +k_e_matte = 20.0 +k_e_edge = 10.0 close all; figure; -imshow(ref_rgb); - -figure; -matte_p = imnorm(im_rgb, ref_rgb); -imshow(matte_p); title("matte_p") - -figure; -matte_n = imnorm(im_rgb, ref_rgb_c); -imshow(matte_n); title("matte_n") - -figure; -matte = exp(-k_e_matte*(matte_n - matte_p)); +matte = supermatte(im_rgb, ref_rgb, k_e_matte); imshow(matte); title("matte") figure; -final = max(0, im_rgb - k_ds*matte.*ref_rgb).*matte; -imshow(final); title("final") +intermediate = im_rgb.*matte; +imshow(intermediate); title("intermediate") figure; -edges = coloredges(final, ref_rgb, k_e_edge); +edges = 1-supermatte(intermediate, ref_rgb, k_e_edge); imshow(edges); title("edges") figure; -final_cc = im_rgb - edges.*ref_rgb; -imshow(final_cc); title("final_cc") +final = max(0, intermediate - k_ds_matte.*edges.*ref_rgb); +imshow(final); title("final") +imwrite(intermediate, 'intermediate.png','png','alpha', matte); 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 hsv = toHsv(in, gain_hsv) - hsv = rgb2hsv(in) .* toRef(gain_hsv, size(in)); -endfunction - -function s = imnorm(im, ref) - s = vecnorm (im - ref, 2, 3); -endfunction - -function s = similarity(im, ref, k) - s = 1-exp(-k*vecnorm (im - ref, 2, 3)); -endfunction - -function s = similarity_hsv(im_rgb, ref_rgb, k, weigth) - im = toHsv(im_rgb, weigth); - ref = toHsv(ref_rgb, weigth); - 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; diff --git a/chromakey/final.png b/chromakey/final.png index 25b976a..2d922b3 100644 Binary files a/chromakey/final.png and b/chromakey/final.png differ diff --git a/chromakey/final_cc.png b/chromakey/final_cc.png index 07b4a4c..2c22dff 100644 Binary files a/chromakey/final_cc.png and b/chromakey/final_cc.png differ diff --git a/chromakey/intermediate.png b/chromakey/intermediate.png new file mode 100644 index 0000000..2c22dff Binary files /dev/null and b/chromakey/intermediate.png differ diff --git a/chromakey/supermatte.m b/chromakey/supermatte.m new file mode 100644 index 0000000..7a8d52e --- /dev/null +++ b/chromakey/supermatte.m @@ -0,0 +1,32 @@ +## 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} =} supermatte (@var{input1}, @var{input2}) +## +## @seealso{} +## @end deftypefn + +## Author: Jens +## Created: 2020-10-04 + +function matte = supermatte (im_rgb, ref_rgb, k_e) + +im_minus_ref = im_rgb - ref_rgb; +var_im_minus_ref = var(im_minus_ref, 0, 3); +matte = 1-exp(-k_e*var_im_minus_ref); + +endfunction