git-svn-id: http://moon:8086/svn/matlab/trunk@140 801c6759-fa7c-4059-a304-17956f83a07c
85 lines
2.0 KiB
Objective-C
85 lines
2.0 KiB
Objective-C
## 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
|
|
## <https://www.gnu.org/licenses/>.
|
|
|
|
## -*- texinfo -*-
|
|
## @deftypefn {} {@var{retval} =} bluescreen (@var{input1}, @var{input2})
|
|
##
|
|
## @seealso{}
|
|
## @end deftypefn
|
|
|
|
## Author: Jens <jens@orion>
|
|
## 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);
|
|
se = strel('square',3)
|
|
|
|
ref_rgb = toRef([0.0 0.5 0.95], size(im_rgb));
|
|
|
|
close all;
|
|
|
|
figure;
|
|
imshow(ref_rgb);
|
|
|
|
figure;
|
|
despilled_rgb_matte = max(0, im_rgb - k_sb*ref_rgb);
|
|
imshow(despilled_rgb_matte);
|
|
|
|
figure;
|
|
despilled_rgb = max(0, im_rgb - k_ds*ref_rgb);
|
|
imshow(despilled_rgb);
|
|
|
|
figure;
|
|
matte = min(1, k_cw*similarity(despilled_rgb_matte, ref_rgb));
|
|
imshow(matte);
|
|
|
|
figure;
|
|
final = despilled_rgb.*matte;
|
|
imshow(final);
|
|
|
|
figure;
|
|
edges = coloredges(despilled_rgb_matte, ref_rgb);
|
|
imshow(edges);
|
|
|
|
figure;
|
|
final = max(0, despilled_rgb.*matte - edges.*ref_rgb);
|
|
imshow(final);
|
|
|
|
imwrite(final, 'final.png','png','alpha', matte);
|
|
imwrite(matte, 'alpha.png','png');
|
|
|
|
retval = 0;
|
|
|
|
function r = toRef(ref, d)
|
|
r = repmat(reshape(ref,1, 1, 3), d(1), d(2));
|
|
endfunction
|
|
|
|
function s = similarity(im, ref)
|
|
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
|