Skip to content

Commit

Permalink
Tuned up display calibration instructions & tweaked openScreen so that
Browse files Browse the repository at this point in the history
.display.gamma could be manually overridden without messing with rigPrefs directly
- for some reason, merely setting .display.gamma = [] wasn't actually overriding
existing .display.gamma.power values
- updated precidence in openScreen and instructions in calibDisplay_...m to explain
how & why those must be overridden during calibration
  • Loading branch information
czuba committed Mar 12, 2021
1 parent c454bbf commit d652ce7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
37 changes: 24 additions & 13 deletions @pldaps/openScreen.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,14 @@

%% Color correction
% Must be initialized before PTB screen opened, correction parameters are loaded/applied below
if isfield(p.trial.display, 'gamma') && isfield(p.trial.display.gamma, 'power')
PsychImaging('AddTask', 'FinalFormatting', 'DisplayColorCorrection', 'SimpleGamma');
else
PsychImaging('AddTask', 'FinalFormatting', 'DisplayColorCorrection', 'LookupTable');
if isfield(p.trial.display, 'gamma')
if isfield(p.trial.display.gamma, 'power') && ~isempty(p.trial.display.gamma.power)
PsychImaging('AddTask', 'FinalFormatting', 'DisplayColorCorrection', 'SimpleGamma');
elseif isfield(p.trial.display.gamma, 'table') && ~isempty(p.trial.display.gamma.table)
PsychImaging('AddTask', 'FinalFormatting', 'DisplayColorCorrection', 'LookupTable');
end
% else
% PsychImaging('AddTask', 'FinalFormatting', 'DisplayColorCorrection', 'LookupTable');
end

% Functional modifications to PsychImaging prior to PTB screen creation
Expand Down Expand Up @@ -466,15 +470,12 @@


%% Apply display calibration (e.g. gamma encoding or lookup table)
if isfield(p.trial.display, 'gamma')
if isfield(p.trial.display, 'gamma')
% disp('****************************************************************')
fprintLineBreak
fprintf('Applying display color correction ');
if isfield(p.trial.display.gamma, 'table')
fprintf('via lookup table\n');
PsychColorCorrection('SetLookupTable', p.trial.display.ptr, p.trial.display.gamma.table, 'FinalFormatting');
elseif isfield(p.trial.display.gamma, 'power')
fprintf('via gamma power %3.3f\n', p.trial.display.gamma.power);
if isfield(p.trial.display.gamma, 'power') && ~isempty(p.trial.display.gamma.power)
% allow .power correction to take precident
fprintf('Applying display color correction via gamma power %3.3f\n', p.trial.display.gamma.power);
PsychColorCorrection('SetEncodingGamma', p.trial.display.ptr, p.trial.display.gamma.power, 'FinalFormatting');
% Extended gamma parameters
if all( isfield(p.trial.display.gamma, {'bias', 'minL', 'maxL', 'gain'}) )
Expand All @@ -484,10 +485,20 @@
gain=p.trial.display.gamma.gain;
PsychColorCorrection('SetExtendedGammaParameters', p.trial.display.ptr, minL, maxL, gain, bias);
end

elseif isfield(p.trial.display.gamma, 'table') && ~isempty(p.trial.display.gamma.table)
% [old] direct lookup table approach
fprintf('Applying display color correction via lookup table\n');
PsychColorCorrection('SetLookupTable', p.trial.display.ptr, p.trial.display.gamma.table, 'FinalFormatting');

else
fprintf('No luminance/color linearization to apply\n');
end
else
%set a linear gamma
PsychColorCorrection('SetLookupTable', ptr, linspace(0,1,p.trial.display.info.realBitDepth)'*[1, 1, 1], 'FinalFormatting');
% do nothing, direct pass through to device while allowing PTB to 'ClampOnly' by default
fprintf('No luminance/color linearization to apply\n');
% %set a linear gamma
% PsychColorCorrection('SetLookupTable', ptr, linspace(0,1,p.trial.display.info.realBitDepth)'*[1, 1, 1], 'FinalFormatting');
end

% % This seems redundant. Is it necessary?
Expand Down
15 changes: 14 additions & 1 deletion SupportFunctions/Utils/calibDisplay_pldaps.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,25 @@
% Must be run after pausing a running PLDAPS session.
% - This is a feature, not a bug, because it ensures that measurements are made under
% the exact same setup conditions as your experiment.
% - This is not the stereo-specific version of the calibration code
% This is not the stereo-specific version of the calibration code
% - its *not* INcompatible with stereo displays, but it doesn't make/fit
% separate monocular calibrations, or do any binocular crosstalk measurements
%
% When making initial calibration measurements, its important to be sure that
% all other/prior calibrations are disabled when the new measurements are made.
% - e.g. linearization via gamma table or power, or binocular crosstalk corrections
% - Otherwise the result will be confounded by [unknown] prior display corrections
% - Easiest way to do this is to make sure the .display.gamma.power field is empty
% before your code executes p.run
% - In the modularDemo, you would want to set: pss.display.gamma.power = [];
%
% Save the returned greyscale [simpleGamma] value in your rigPrefs as:
% .display.gamma.power
%
% AFTER you've run your calibration & added the results to your rigPrefs,
% run this calibration function again to validate. This will help ensure that your
% validation is performed in EXACTLY the same state as your experiment.
%
%
% EXAMPLE:
% ---
Expand All @@ -43,6 +55,7 @@
% % [ follow command window instructions to apply & save new rigPrefs values ]
%
% % Done! Future experiments on this rig will apply this gamma correction automatically
% % Rerun the calibration measurements with the new settings applied to validate your results
% ---
%
%
Expand Down
13 changes: 13 additions & 0 deletions SupportFunctions/Utils/calibDisplay_pldapsRb3d.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,21 @@
% & binocular crosstalk correction
% - ...still needs [more] commenting & explanation on how to properly use/implement (TBC 2021)
%
% When making initial calibration measurements, its important to be sure that
% all other/prior calibrations are disabled when the new measurements are made.
% - e.g. linearization via gamma table or power, or binocular crosstalk corrections
% - Otherwise the result will be confounded by [unknown] prior display corrections
% - Easiest way to do this is to make sure the .display.gamma.power field is empty
% before your code executes p.run
% - In the modularDemo, you would want to set: pss.display.gamma.power = [];
%
% Save the returned greyscale [simpleGamma] value in your rigPrefs as:
% .display.gamma.power
%
% AFTER you've run your calibration & added the results to your rigPrefs,
% run this calibration function again to validate. This will help ensure that your
% validation is performed in EXACTLY the same state as your experiment.
%
%
% EXAMPLE:
% p = yourPldapsExperiment;
Expand All @@ -43,6 +55,7 @@
% % [ follow command window instructions to apply & save new rigPrefs values ]
%
% % Done! Future experiments on this rig will apply this gamma correction automatically
% % Rerun the calibration measurements with the new settings applied to validate your results
% ---
%
%
Expand Down
2 changes: 1 addition & 1 deletion tutorial/+modularDemo/doRfPos_gabGrid.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
% pss.display.screenSize = [];
% pss.display.scrnNum = 0;

pss.display.stereoMode = 4; % 0==mono 2D; 3-or-4==freeFuse 3D; See Screen('OpenWindow?')
pss.display.stereoMode = 0; % 0==mono 2D; 3-or-4==freeFuse 3D; See Screen('OpenWindow?')

pss.display.useGL = 1;
pss.display.multisample = 2;
Expand Down

0 comments on commit d652ce7

Please sign in to comment.