diff --git a/chromakey/alpha.png b/chromakey/alpha.png index 14f2c05..1bf0d44 100644 Binary files a/chromakey/alpha.png and b/chromakey/alpha.png differ diff --git a/chromakey/chromakey.m b/chromakey/chromakey.m index 58132fd..1184ceb 100644 --- a/chromakey/chromakey.m +++ b/chromakey/chromakey.m @@ -23,25 +23,23 @@ ## Author: Jens ## Created: 2020-10-03 -function chromakey (img_name) -im = im2double(imread(img_name)); -im_rgb = imresize(im, 1); -se = strel('square',3) +# chromakey('adventure_rose', 20, 10) +# chromakey('cineon_before', 200, 100) -#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)); +function chromakey (prj_name, k_e_matte, k_e_edge) k_ds_matte = 1.0; -k_e_matte = 20.0 -k_e_edge = 10.0 + +[im_rgb, ref_rgb] = prj_load(prj_name); close all; - figure; -matte = supermatte(im_rgb, ref_rgb, k_e_matte); +[matte, dev, conf] = supermatte(im_rgb, ref_rgb, k_e_matte); imshow(matte); title("matte") +figure; +imshow(dev); title("dev") +figure; +imshow(conf); title("conf") figure; intermediate = im_rgb.*matte; @@ -60,10 +58,6 @@ imwrite(edges, 'edges.png','png'); imwrite(final, 'final.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 mask = mask_clip_above(mask_in, thresh) k = mask_in < thresh; mask = k .* mask_in + kn; diff --git a/chromakey/edges.png b/chromakey/edges.png index 3e16feb..a251780 100644 Binary files a/chromakey/edges.png and b/chromakey/edges.png differ diff --git a/chromakey/final.png b/chromakey/final.png index 2d922b3..412e8d2 100644 Binary files a/chromakey/final.png and b/chromakey/final.png differ diff --git a/chromakey/intermediate.png b/chromakey/intermediate.png index 2c22dff..32eae74 100644 Binary files a/chromakey/intermediate.png and b/chromakey/intermediate.png differ diff --git a/chromakey/supermatte.m b/chromakey/supermatte.m index 7a8d52e..5d63c89 100644 --- a/chromakey/supermatte.m +++ b/chromakey/supermatte.m @@ -23,10 +23,17 @@ ## Author: Jens ## Created: 2020-10-04 -function matte = supermatte (im_rgb, ref_rgb, k_e) +function [matte, dev, conf] = supermatte (im_rgb, ref_rgb, k_e) im_minus_ref = im_rgb - ref_rgb; var_im_minus_ref = var(im_minus_ref, 0, 3); + +# The base matte matte = 1-exp(-k_e*var_im_minus_ref); +# Deviation from reference color +dev = vecnorm(im_minus_ref, 2, 3); + +# Deviation from gray +conf = mean(abs(im_minus_ref), 3); endfunction