File: SensorToSettingsAcc.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (70 lines) | stat: -rw-r--r-- 2,704 bytes parent folder | download | duplicates (7)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function [finalSettings,badIndex,quantized,perError,settings] = SensorToSettingsAcc(cal,sensor)
% [finalSettings,badIndex,quantized,perError,settings] = SensorToSettingsAcc(cal,sensor)
%
% Convert from sensor color space coordinates to device
% setting coordinates.  This routine makes use of the
% full basis function information to compensate for spectral
% shifts in the device primaries with input settings.
%
% This depends on the standard calibration globals.
%
% 11/12/93   dhb      Wrote it.
% 3/30/94	 dhb, jms Fixed logic bug in error computation.
%					  Return finalSettings as best during iteration
% 8/4/96     dhb      Update for stuff bag routines.
% 8/21/97    dhb      Update for structures.
% 3/10/98	 dhb      Change nBasesOut to nPrimaryBases.
% 4/5/02     dhb, ly  New calling interface.
% 1/26/04    ly, dhb  Get rid of unused variable called "error".
% 11/22/09   dhb      Check basis dimension and do the simple fast thing if it is 1.
%                     This will speed things up when there is no point in trying the
%                     iterative algorithm.

% Algorithm parameters
nIterations = 10;
dampingFactor = 1.0;

% Determine sizes
[nLinear,nTargets] = size(sensor);
if (nTargets ~= 1)
	error('Only handles one sensor target at a time');
end
settings = zeros(nLinear,nIterations);
quantized = zeros(nLinear,nIterations);

% Get basis information
nPrimaryBases = cal.nPrimaryBases;
if (isempty(nPrimaryBases))
	error('No nPrimaryBases field present in calibration structure');
end

if (nPrimaryBases == 1)
    [finalSettings,badIndex] = SensorToSettings(cal,sensor);
    quantized = [];
    perError = [];
    settings = [];
else
    % THINK ABOUT OUT OF GAMUT ISSUE.  THIS COMMENTED
    % OUT CODE WAS AN INITIAL STAB AT IT.
    %primary = SensorToPrimary(cal,sensor);
    %[nDevice,null] = size(primary);
    %gamut = PrimaryToGamut(cal,primary);
    %target = PrimaryToSensor(cal,gamut);
    target = sensor;
    aimfor = target;
    for i = 1:nIterations
        primary = SensorToPrimary(cal,aimfor);
        [gamut,badIndex] = PrimaryToGamut(cal,primary);
        settings(:,i) = GamutToSettings(cal,gamut);
        [tmpQuantized,primaryE] = SettingsToSensorAcc(cal,settings(:,i));
        quantized(:,i) = tmpQuantized;
        calError(:,i) = quantized(:,i) - aimfor;
        perError(:,i) = quantized(:,i) - target;
        aimfor = target - dampingFactor*calError(:,i);
    end
    
    % Find minimum error that was encountered and return those settings
    summaryError = diag(perError'*perError);
    [null,minIndex] = min(summaryError);
    finalSettings = settings(:,minIndex);
end