forked from ndwork/dworkLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindColorChannelWeights.m
More file actions
40 lines (34 loc) · 980 Bytes
/
findColorChannelWeights.m
File metadata and controls
40 lines (34 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function w = findColorChannelWeights( M, C, varargin )
% w = findColorChannelWeights( M, C [, 'objective', objective ] )
%
% Find w such that M = sum w(i) * C(:,:,i)
%
% Inputs:
% M - monochrome image
% C - color image
%
% Optional Inputs:
% objective - either 'L2' or 'L1'
%
% Written by Nicholas Dwork, Copyright 2019
%
% https://github.com/ndwork/dworkLib.git
%
% This software is offered under the GNU General Public License 3.0. It
% is offered without any warranty expressed or implied, including the
% implied warranties of merchantability or fitness for a particular
% purpose.
p = inputParser;
p.addParameter( 'objective', 'L2', @(x) true );
p.parse( varargin{:} );
objective = p.Results.objective;
sC = size(C);
A = reshape( C, [ sC(1)*sC(2) sC(3) ] );
b = M(:);
w = A \ b;
f = @(w) norm( A*w - b, 1 );
if strcmp( objective, 'L1' )
wLB = w*0;
w = fmincon( f, w, A, b, [], [], wLB, [] );
end
end