## 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} =} prj_load (@var{input1}, @var{input2}) ## ## @seealso{} ## @end deftypefn ## Author: Jens ## Created: 2020-10-04 function [im_rgb, ref_rgb] = prj_load(prj_name) extensions = {'.png'}; name_im = '' for i=1:length(extensions), ext = extensions{i} name_cand = strcat(prj_name, ext) if isfile(name_cand) name_im = name_cand; break; end; end; if isempty(name_im) error("File Not found") end [im, m, a] = imread(name_im); if length(a) == 0 error("Alpha channel not found") end # Get image dimensions [w, h, nc] = size(im) # Get RGBA data im_rgb = im2double(im); im_a = im2double(a); # Find background sample area in alpha channel # And create reference data ref_sample_indices = find(im_a < 0.5); zzz = reshape(im_rgb, w*h, nc); ref = mean(zzz(ref_sample_indices, :)) ref_rgb = toRef(ref, size(im_rgb)); function r = toRef(ref, d) r = repmat(reshape(ref,1, 1, 3), d(1), d(2)); endfunction endfunction