File: MonitorGamma.m

package info (click to toggle)
psychtoolbox-3 3.0.9%2Bsvn2579.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 63,408 kB
  • sloc: ansic: 73,310; cpp: 11,139; objc: 3,129; sh: 1,669; python: 382; php: 272; makefile: 172; java: 113
file content (24 lines) | stat: -rwxr-xr-x 860 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
function y=MonitorGamma(x,x0,g)
% y=MonitorGamma(x,x0,gamma)
%
% This function is commonly used to describe the "gamma" function of a video
% monitor. x represents input voltage and y represents luminance. There are two
% parameters: threshold x0, and the exponent gamma. In my applications, x and y
% have been normalized so that the gamma curve always goes through (0,0) and (1,1),
% so I've built that constraint into the function:
%    if x<=x0 then y=0
%    if x>x0 then y=((x-x0)/(1-x0))^gamma
% The arguments can be scalars or matrices; MonitorGamma will do the right thing.
% Note that it is unreasonable for x0 to be outside the unit interval, or for g to
% be negative, but these constraints are not enforced here.
%
% See MonitorGammaError.
%
% Denis Pelli 5/28/96

x=(x-x0)./(1-x0);
y=zeros(size(x));
i=find(x>0);
if ~isempty(i)
	y(i)=x(i).^g;
end