diff --git a/chromakey/alpha.png b/chromakey/alpha.png index 0237a3e..cc321f5 100644 Binary files a/chromakey/alpha.png and b/chromakey/alpha.png differ diff --git a/chromakey/chromakey.m b/chromakey/chromakey.m index 8d1b82a..44248da 100644 --- a/chromakey/chromakey.m +++ b/chromakey/chromakey.m @@ -28,14 +28,16 @@ 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)); +ref = [0.3 0.4 0.65]; # cineon_before +#ref = 0.2 0.6 0.95]; # adventure_rose + +ref_c = 1 - ref + +ref_rgb = toRef(ref, size(im_rgb)); +ref_rgb_c = toRef(ref_c, size(im_rgb)); k_ds = 0.2; -k_c_matte = 1.0 -k_e_matte = 3 - -k_c_edge = 3.0 +k_e_matte = 5.0 k_e_edge = 3.0 close all; @@ -44,8 +46,15 @@ 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); +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)); imshow(matte); title("matte") figure; @@ -53,8 +62,7 @@ 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); +edges = coloredges(final, ref_rgb, k_e_edge); imshow(edges); title("edges") figure; @@ -69,7 +77,21 @@ function r = toRef(ref, d) r = repmat(reshape(ref,1, 1, 3), d(1), d(2)); endfunction -function s = similarity_rgb(im, ref, k) +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 diff --git a/chromakey/final.png b/chromakey/final.png index e31638d..25b976a 100644 Binary files a/chromakey/final.png and b/chromakey/final.png differ