diff --git a/chromakey/alpha.png b/chromakey/alpha.png index 96b4049..7408e26 100644 Binary files a/chromakey/alpha.png and b/chromakey/alpha.png differ diff --git a/chromakey/bluescreen.m b/chromakey/bluescreen.m index 30c27d7..f50c82d 100644 --- a/chromakey/bluescreen.m +++ b/chromakey/bluescreen.m @@ -23,9 +23,9 @@ ## Author: Jens ## Created: 2020-10-03 -function retval = bluescreen (img_name, k_ds, k_gain) +function retval = bluescreen (img_name, k_sb, k_ds, k_cw) im = im2double(imread(img_name)); -im_rgb = imresize(im, 2); +im_rgb = imresize(im, 1); se = strel('square',3) ref_rgb = toRef([0 0.5 1], size(im_rgb)); @@ -35,20 +35,28 @@ close all; figure; imshow(ref_rgb); +figure; +despilled_rgb_matte = im_rgb - k_sb*ref_rgb; +imshow(despilled_rgb_matte); + figure; despilled_rgb = im_rgb - k_ds*ref_rgb; imshow(despilled_rgb); figure; -mask = min(1, k_gain*similarity(rgb2hsv(despilled_rgb), rgb2hsv(ref_rgb))); -imshow(mask); +matte = min(1, k_cw*similarity(despilled_rgb_matte, ref_rgb)); +imshow(matte); figure; -final = despilled_rgb.*mask; +final = despilled_rgb.*matte; imshow(final); -imwrite(final, 'final.png','png','alpha', mask); -imwrite(mask, 'alpha.png','png'); +figure; +edges = coloredges(despilled_rgb_matte, ref_rgb); +imshow(edges); + +imwrite(final, 'final.png','png','alpha', matte); +imwrite(matte, 'alpha.png','png'); retval = 0; @@ -57,7 +65,15 @@ function r = toRef(ref, d) endfunction function s = similarity(im, ref) - s = abs(im(:,:,1) - ref(:,:,1)); + im = rgb2hsv(im); + ref = rgb2hsv(ref); + s = (im(:,:,1) - ref(:,:,1)).^2; +endfunction + +function s = coloredges(im, ref) + im = rgb2hsv(im); + ref = rgb2hsv(ref); + s = max(0, im(:,:,1) - ref(:,:,1)); endfunction endfunction diff --git a/chromakey/final.png b/chromakey/final.png index 412bdc1..8b1cc89 100644 Binary files a/chromakey/final.png and b/chromakey/final.png differ