## 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} =} alpha_gen (@var{input1}, @var{input2}) ## ## @seealso{} ## @end deftypefn ## Author: Jens ## Created: 2020-10-07 function a = alpha_gen(N, slope) s = (0:N-1)/(N-1); a = to_param(s, 0, 1, 2, -slope, 0.5, 0.5); color_bg = [0.1 0.3 0.9]; color_fg = [0.9 0.9 0.0]; mean_fg = mean(color_fg) norm_fg = norm(color_fg) mean_bg = mean(color_bg) norm_bg = norm(color_bg) w = N; h = 8; im_a = repmat(a, h, 1); im_comp = to_im (color_fg, a, h) + to_im (color_bg, 1-a, h); im_fg = to_ref(color_fg, size(im_comp)); im_bg = to_ref(color_bg, size(im_comp)); im_ac = (im_comp - im_bg)./(im_fg - im_bg); close all; figure; imshow(im_a); title ("im_a") figure; imshow(im_ac); title ("im_ac") figure; imshow(im_comp); title ("im_comp") figure; im_filtered = im_comp - to_ref(color_bg, size(im_comp)); imshow(im_filtered); title ("im_filtered") strip = im_filtered(1,:,:); strip_clamped = max(0, strip); strip_clamped_norm = strip_clamped; n = vecnorm(strip, 2, 3)/norm_fg; figure; plot (s, a, s, n); grid; legend("Ground truth", "Calculated") endfunction function im = to_im(color, a, h) w = length(a); im = reshape([color(1)*ones(h,1)*a color(2)*ones(h,1)*a color(3)*ones(h,1)*a], h, w, 3); endfunction function r = to_ref(ref, d) r = repmat(reshape(ref,1, 1, 3), d(1), d(2)); endfunction