├── linear_test_im.png
├── real_world_im.jpg
├── DummyPipeline.m
├── DummyLens.m
├── DummyBayerSensor.m
├── DummyColorSensor.m
├── model_test.m
├── CameraModel.m
├── SensorModel.m
├── PipelineModel.m
├── LensModel.m
├── readme.md
└── gpl-3.0.txt
/linear_test_im.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imatest/simatest/HEAD/linear_test_im.png
--------------------------------------------------------------------------------
/real_world_im.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imatest/simatest/HEAD/real_world_im.jpg
--------------------------------------------------------------------------------
/DummyPipeline.m:
--------------------------------------------------------------------------------
1 | % Copyright (C) 2017 Imatest LLC
2 | %
3 | % This program is free software: you can redistribute it and/or modify
4 | % it under the terms of the GNU General Public License as published by
5 | % the Free Software Foundation, either version 3 of the License, or
6 | % (at your option) any later version.
7 | %
8 | % This program is distributed in the hope that it will be useful,
9 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | % GNU General Public License for more details.
12 | %
13 | % You should have received a copy of the GNU General Public License
14 | % along with this program. If not, see .
15 |
16 | classdef DummyPipeline < PipelineModel
17 | % A dummy Pipeline which will only convert the output to the data type of dummy.outputType
18 | % (default: uint8) and otherwise not touch the data.
19 |
20 | methods
21 |
22 | function obj = DummyPipeline()
23 | obj = obj@PipelineModel({}); % empty set of processes
24 | end
25 |
26 | end
27 |
28 |
29 | end % end classdef
--------------------------------------------------------------------------------
/DummyLens.m:
--------------------------------------------------------------------------------
1 | % Copyright (C) 2017 Imatest LLC
2 | %
3 | % This program is free software: you can redistribute it and/or modify
4 | % it under the terms of the GNU General Public License as published by
5 | % the Free Software Foundation, either version 3 of the License, or
6 | % (at your option) any later version.
7 | %
8 | % This program is distributed in the hope that it will be useful,
9 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | % GNU General Public License for more details.
12 | %
13 | % You should have received a copy of the GNU General Public License
14 | % along with this program. If not, see .
15 |
16 | classdef DummyLens < LensModel
17 | % A dummy lens which just passes through exactly the input data.
18 |
19 |
20 | methods
21 |
22 | % Override the simulate method to accomplish the bypass.
23 | function processedIm = simulate(~,scene)
24 | % processedIm = dummy.simulate(scene)
25 |
26 | processedIm = double(scene); % needs to return real values, as per superclass' contract
27 | end
28 |
29 | end
30 |
31 |
32 | end % end classdef
--------------------------------------------------------------------------------
/DummyBayerSensor.m:
--------------------------------------------------------------------------------
1 | % Copyright (C) 2017 Imatest LLC
2 | %
3 | % This program is free software: you can redistribute it and/or modify
4 | % it under the terms of the GNU General Public License as published by
5 | % the Free Software Foundation, either version 3 of the License, or
6 | % (at your option) any later version.
7 | %
8 | % This program is distributed in the hope that it will be useful,
9 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | % GNU General Public License for more details.
12 | %
13 | % You should have received a copy of the GNU General Public License
14 | % along with this program. If not, see .
15 |
16 | classdef DummyBayerSensor < SensorModel
17 | % A dummy sensor which just passes through data. It does integerize the data and mosaic it with a
18 | % given Bayer CFA orientation, though.
19 |
20 | methods
21 |
22 | function obj = DummyBayerSensor(sensorSize,varargin)
23 | if nargin==1
24 | varargin = {};
25 | end
26 | obj = obj@SensorModel(sensorSize,varargin{:});
27 |
28 | end
29 |
30 |
31 | function dn = expose(obj,radiantPower,~)
32 | % dn = dummy.expose(radiantPower)
33 | % dn = dummy.expose(radiantPower,t)
34 | %
35 | % Also accepts a second 't' argument to be consistent with other SensorModels, but simply
36 | % ignores it.
37 |
38 | dn = uint16(obj.mosaic(radiantPower));
39 | end
40 | end
41 |
42 |
43 | end % end classdef
--------------------------------------------------------------------------------
/DummyColorSensor.m:
--------------------------------------------------------------------------------
1 | % Copyright (C) 2017 Imatest LLC
2 | %
3 | % This program is free software: you can redistribute it and/or modify
4 | % it under the terms of the GNU General Public License as published by
5 | % the Free Software Foundation, either version 3 of the License, or
6 | % (at your option) any later version.
7 | %
8 | % This program is distributed in the hope that it will be useful,
9 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | % GNU General Public License for more details.
12 | %
13 | % You should have received a copy of the GNU General Public License
14 | % along with this program. If not, see .
15 |
16 | classdef DummyColorSensor < SensorModel
17 | % A dummy sensor which just passes through data (nearly) exactly. (It does integer-ize the data.)
18 | %
19 | % Unlike the standard SensorModel, this does not reduce the 3-channel input to one-channel via
20 | % re-mosaicking. (This is so that the image is *really* just passed through and doesn't require
21 | % demosaicking which could change values.) You should make sure that any PipelineModel following
22 | % this expects that sort of input (i.e., does not demosaic), or use a DummyPipeline();
23 |
24 |
25 | methods
26 |
27 | function obj = DummyColorSensor(sensorSize,varargin)
28 | if nargin==1
29 | varargin = {};
30 | end
31 | obj = obj@SensorModel(sensorSize,varargin{:});
32 |
33 | end
34 |
35 | % Override the exposre() method to accomplish the simulation bypass.
36 | function dn = expose(~,radiantPower,~)
37 | % dn = dummy.expose(radiantPower)
38 | % dn = dummy.expose(radiantPower,t)
39 | %
40 | % Also accepts a second 't' argument to be consistent with other SensorModels, but simply
41 | % ignores it.
42 |
43 | dn = uint16(radiantPower);
44 | end
45 | end
46 |
47 |
48 | end % end classdef
--------------------------------------------------------------------------------
/model_test.m:
--------------------------------------------------------------------------------
1 | %% Vary exposure around ideal for a given gain
2 |
3 | clear all,clc,close all, clear classes
4 |
5 | scene = imread('linear_test_im.png'); % Load an image to use as the 'scene'
6 | camodel = CameraModel(size(scene)); % Instantiate a virtual camera for this scene, using default settings
7 |
8 | tOpt = camodel.find_ae_time(scene,'saturation'); % Find auto-exposure suggested exposure time
9 | bracketStops = [-2 -1 0 1]; % set of exposures in stops) relative to ideal exposure we want to explore
10 |
11 | figure
12 | for i = 1:length(bracketStops)
13 | t = tOpt*2^(bracketStops(i)); % Compute exposure time for this bracketed exposure
14 | simulated = camodel.simulate_exposure(scene,t); % Simulate the exposure
15 | subplot(2,2,i)
16 | imshow(simulated)
17 | end
18 |
19 | %% Vary ISO
20 |
21 | clear all,clc,close all, clear classes
22 |
23 | scene = imread('linear_test_im.png'); % Load an image to use as the 'scene'
24 | camodel = CameraModel(size(scene)); % virtual camera with default setting of sensorModel.gain = 1
25 |
26 | gains = [0.25, 1, 4, 16]; % gain levels (DN/electrion) we want to explore
27 |
28 | figure
29 | for i = 1:length(gains)
30 | camodel.sensorModel.gain = gains(i); % Set gain to chosen level
31 | t = camodel.find_ae_time(scene,'saturation'); % Find suggested exposure time for this gain level
32 | simulated = camodel.simulate_exposure(scene,t); % Simulate the exposure
33 | subplot(2,2,i)
34 | imshow(simulated)
35 | end
36 |
37 |
38 | %% RAW data
39 | scene = imread('linear_test_im.png'); % Load an image to use as the 'scene'
40 | camodel = CameraModel(size(scene));
41 |
42 | camodel.pipelineModel = DummyPipeline(); % Use a pipeline that just passes data through
43 |
44 | % Default output of dummy pipeline is uint8, but we don't want to truncate uint16 data from the
45 | % SensorModel, so overwrite the .outputType property.
46 | camodel.pipelineModel.outputType = 'uint16';
47 |
48 | simulated = camodel.simulate_exposure(scene, camodel.find_ae_time(scene)); % uses default AE mode 'grayworld'
49 |
50 | % We must scale the output image for viewing, since the default SensorModel puts out 10-bit data in
51 | % a 16-bit format.
52 | figure
53 | imshow(simulated,[0, 2^10-1])
54 |
55 |
56 | %% Just LCA on a real image
57 | scene = imread('real_world_im.jpg'); % Load a non-simulated, sRGB image as the 'scene'
58 | camodel = CameraModel(size(scene));
59 |
60 | % Set the LensModel's LCA parameters, overwriting the default values of zero polynomials
61 | camodel.lensModel.lcaCoeffs_bg = [-0.01,0,0.02,0];
62 | camodel.lensModel.lcaCoeffs_rg = [0.03,0,-0.005,0];
63 |
64 | % Use a dummy color sensor to pass through all channels, cf dummy bayer sensor
65 | camodel.sensorModel = DummyColorSensor(size(scene));
66 | camodel.pipelineModel = DummyPipeline();
67 |
68 | % Note: exposure time argument is not actually used by a DummySensor
69 | simulated = camodel.simulate_exposure(scene,1);
70 |
71 | figure,imshow(simulated)
72 |
73 |
74 |
--------------------------------------------------------------------------------
/CameraModel.m:
--------------------------------------------------------------------------------
1 | % Copyright (C) 2017 Imatest LLC
2 | %
3 | % This program is free software: you can redistribute it and/or modify
4 | % it under the terms of the GNU General Public License as published by
5 | % the Free Software Foundation, either version 3 of the License, or
6 | % (at your option) any later version.
7 | %
8 | % This program is distributed in the hope that it will be useful,
9 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | % GNU General Public License for more details.
12 | %
13 | % You should have received a copy of the GNU General Public License
14 | % along with this program. If not, see .
15 |
16 | classdef CameraModel
17 | % CameraModel is a class which contains separate models for the lens, sensor and pipeline of the
18 | % imaging system. Its primary duty is to organize the data-flow between these components via its
19 | % .simulate_exposure() method, as well as to provide some elements of "camera control tools".
20 | %
21 | % Camera Control Tools:
22 | % .find_ae_time(scene, mode) - Basically, an auto-exposure routine which will suggest an
23 | % exposure time based on scene content.
24 |
25 |
26 | properties
27 | sensorModel
28 | lensModel
29 | pipelineModel
30 | end
31 |
32 |
33 | methods
34 |
35 | function obj = CameraModel(imSize)
36 | % camModel = CameraModel(imSize)
37 | %
38 | % A new CameraModel uses the default constructions of each of the component Models. Since a
39 | % SensorModel (even the default one) requires a [height, width] input argument for
40 | % construction, so does CameraModel require that argument for construction.
41 | %
42 | % The Default Camera is essentially:
43 | % - a perfect lens
44 | % - a 10-bit Bayer-GRBG sensor with no readout noise and gain of 1 DN/e
45 | % - a pipeline which:
46 | % - demosaics
47 | % - converts from 10-bit to 8-bit
48 | % - applies an sRGB-like gamma of 2.2
49 | % -
50 | % This essentially means a perfect lens, a 10-bit sensor with no readout noise and gain of
51 | % 1 DN/e, and a processor which demosaics, applies an sRGB-like gamma, and produces 8-bit
52 | % output.
53 |
54 | obj.sensorModel = SensorModel(imSize(1:2));
55 | obj.lensModel = LensModel();
56 | obj.pipelineModel = PipelineModel();
57 | end
58 |
59 |
60 | function processedIm = simulate_exposure(obj,scene,t)
61 |
62 | % - - Simulate optical system effects on the image - -
63 | sensorPlaneRadiance = obj.lensModel.simulate(scene); % output is type double
64 |
65 | % - - Simulate sensor response to the image - -
66 | sensorData = obj.sensorModel.expose(sensorPlaneRadiance,t); % output is type uint16
67 |
68 | % - - Simulate camera's processing on the image - -
69 | processedIm = obj.pipelineModel.process(sensorData); % output may be uint8 or uint16
70 |
71 | end
72 |
73 |
74 | function tOpt = find_ae_time(obj, scene, mode)
75 | % tOpt = camodel.find_ae_time(scene)
76 | % tOpt = camodel.find_ae_time(scene, mode)
77 | %
78 | % Use a simple given model to find the optimal exposure time to capture the given scenev
79 | % given the camera's current gain setting. (and in the future, aperture)
80 | %
81 | % - - Inputs - -
82 | % scene : currently values in units of photons per second per location
83 | % mode (optional) : a string, one of the following. Default: 'grayworld'
84 | % 'grayworld' : Exposure time will ensure the mean value of the scene equates to half
85 | % of the sensor's linear DN range
86 | % 'saturation' : Expsure time will ensure that the brightest value in the scene just
87 | % hits the saturation of the sensor's DN range (doesn't account for
88 | % finite well capacity).
89 | %
90 | %
91 | %
92 | if nargin==2
93 | mode = 'grayworld';
94 | end
95 |
96 | switch mode
97 | case 'grayworld'
98 | tOpt = obj.sensorModel.maxDN / ...
99 | (2*mean(double(scene(:)))*max(obj.sensorModel.qe)*obj.sensorModel.gain);
100 |
101 | case 'saturation'
102 | tOpt = obj.sensorModel.maxDN / ...
103 | (max(double(scene(:)))*max(obj.sensorModel.qe)*obj.sensorModel.gain);
104 | otherwise
105 | error('Invalid auto-exposure mode string.')
106 | end
107 |
108 | end
109 |
110 | end
111 |
112 | end % end classdef
113 |
--------------------------------------------------------------------------------
/SensorModel.m:
--------------------------------------------------------------------------------
1 | % Copyright (C) 2017 Imatest LLC
2 | %
3 | % This program is free software: you can redistribute it and/or modify
4 | % it under the terms of the GNU General Public License as published by
5 | % the Free Software Foundation, either version 3 of the License, or
6 | % (at your option) any later version.
7 | %
8 | % This program is distributed in the hope that it will be useful,
9 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | % GNU General Public License for more details.
12 | %
13 | % You should have received a copy of the GNU General Public License
14 | % along with this program. If not, see .
15 |
16 | classdef SensorModel
17 | % The SensorModel class represents a linear photosensor array with a realistic noise model (as
18 | % per EMVA1288 and other "linear sensor" sources). Its various instance properties represent
19 | % parameters of the noise model which can be set by the user.
20 | %
21 | % Its main function is to simulate an exposure when given an input array that represents the
22 | % radiant power density at each location of the sensor array via the .expose() method.
23 | %
24 | % The sensor is modeled as having a Bayer mosaic pattern (user's choice of orientation), but this
25 | % is currently implemented by simply re-mosaicking (i.e., throwing away most of) the 3-channel
26 | % input radiant-power array. Scaling of the different color channels by different amounts is
27 | % achieved only by different per-channel QE values, which turns that parameter effectively into
28 | % meaning "the relative sensitivity of this channel to the light of that channel after
29 | % filtering."
30 | %
31 | %
32 | % Note: output data type of this is always uint16, even if the sensor being modeled is
33 | % effectively smaller bit-depth than this. The effective bit-depth of the sensor is controlled by
34 | % setting the .maxDN property.
35 | %
36 | %
37 | % Notes about noise model elements:
38 | % - .noiseFloor_e combines any and all additive white noise sources (whether from readout noise,
39 | % amplifier noise, whatever) and expresses this in terms of effective electrons-worth of
40 | % noise at the photodetector. This can be related back to "scene referred noise" (rather,
41 | % the lambda parameter of the Poisson distribution of effective scene-referred noise) by:
42 | % lambda_scene = noiseFloor_e/(qe * t)
43 | % - Though the black level offset is typically physically implemented as a bias voltage, we only
44 | % care about its value in DN here.
45 | % - Refer to EMVA1288 for further understanding of noise model elements
46 | %
47 | %
48 | % See also: DummyBayerSensor, DummyColorSensor
49 | %
50 | % TODO: .offset could be pixel-, column-, and/or row-wise
51 |
52 | properties
53 | % These three properties need to be set at time of construction because they require knowledge
54 | % of the input 'scene' size.
55 | arraySize % i.e., MxN
56 | prnu % MxN, default all ones (set in constructor)
57 | darkCurrent % MxN, in electrons per second, default all zeros
58 |
59 | noiseFloor_e = 0; % scalar or size arraySize, units of electrons
60 | qe = [1, 1, 1]; % units of electrons/photons, order of [R, G, B]
61 | gain = 1; % linear system gain, units of DN/e
62 | offset = 0; % black-level offset, units of DN.
63 | wellCapacity = inf; % units of electrons
64 | maxDN = 2^10-1; % units of DN
65 |
66 | bayerPhase = 'grbg'
67 | end
68 |
69 |
70 |
71 | methods
72 |
73 | function obj = SensorModel(sensorSize,varargin)
74 | % model = SensorModel(sensorSize)
75 | % model = SensorModel(sensorSize, 'prnu',...,'darkCurrent',...)
76 | %
77 | % Create a SensorModel based on a given number of pixels (sensorSize).
78 | % Optional construction name/value parameters 'prnu' and 'darkCurrent' are allowed, whos
79 | % arguments must be 1-channel matrices the same size as sensorSize.
80 | %
81 | % The default SensorModel is 10-bit Bayer-GRBG, unitary gain and qe, infinite well capacity
82 | % and no data offset, and no additive noise, PRNU, or dark current.
83 |
84 | % Parse inputs
85 | parser = inputParser();
86 | default_prnu = ones(sensorSize);
87 | default_darkCurrent = zeros(sensorSize);
88 | parser.addParameter('prnu',default_prnu)
89 | parser.addParameter('darkCurrent',default_darkCurrent)
90 | parser.parse(varargin{:});
91 | params = parser.Results;
92 |
93 | obj.arraySize = sensorSize;
94 | obj.prnu = params.prnu;
95 | obj.darkCurrent = params.darkCurrent;
96 |
97 | end
98 |
99 |
100 | function dn = expose(obj,radiantPower,t)
101 | % dn = model.expose(radiantPower, t)
102 | %
103 | % Simulate an exposure of a scene on this sensor.
104 | %
105 | % - - Inputs - -
106 | % radiantPower : MxNx3 array (same M,N as model.arraySize) of real values indicating the
107 | % radiant power at the sensor plane at each pixel location units of photons
108 | % per second.
109 | % t : exposure time in seconds
110 | %
111 | % - - Output - -
112 | % dn : integer data array, as if straight out of the ADC
113 |
114 | % - - Simulate color filter array - -
115 | qe_mask = repmat(reshape(obj.qe,[1,1,size(radiantPower,3)]),size(radiantPower,1),size(radiantPower,2));
116 | filteredPower = qe_mask.*radiantPower;
117 | mosaickedPower = obj.mosaic(filteredPower);
118 |
119 | % - - Simulate the number of electrons in the well - -
120 | % Note: '*/ 10^-12' because of how imnoise() deals with doubles.
121 | poisson_base = (mosaickedPower+obj.darkCurrent)*t + obj.noiseFloor_e;
122 | e = imnoise(poisson_base*10^-12,'poisson');
123 | e = min(e*10^12, obj.wellCapacity);
124 |
125 | % - - Conversion of electrons to voltage - -
126 | v = (obj.gain * e .* obj.prnu) + obj.offset;
127 |
128 | % - - Simulate analog-digital-conversion - -
129 | dn = min(uint16(v),obj.maxDN);
130 |
131 | end
132 |
133 | end % end methods
134 |
135 |
136 | methods (Access = protected)
137 | % - - Utility function - -
138 | function cfa = mosaic(obj,fullColorIm)
139 | % cfa = sensor.mosaic(fullColorIm,phase)
140 | %
141 | % Convert an MxNx3 RGB image data array into a Bayer color-filter-array image.
142 |
143 | [M,N,~] = size(fullColorIm);
144 | rmask = zeros(M,N);
145 | bmask = zeros(M,N);
146 |
147 | switch obj.bayerPhase
148 | case 'grbg'
149 | rmask(1:2:end,2:2:end)= 1;
150 | bmask(2:2:end,1:2:end)= 1;
151 | case 'bggr'
152 | rmask(2:2:end,2:2:end)= 1;
153 | bmask(1:2:end,1:2:end)= 1;
154 | case 'rggb'
155 | rmask(1:2:end,1:2:end)= 1;
156 | bmask(2:2:end,2:2:end)= 1;
157 | case 'gbrg'
158 | rmask(2:2:end,1:2:end)= 1;
159 | bmask(1:2:end,2:2:end)= 1;
160 | otherwise
161 | error(['Incorrect mosaic phase argument. ',...
162 | 'Must be one of ''grbg'', ''bggr'', ''rggb'', or ''gbrg''.'])
163 | end
164 |
165 | gmask = double(~(rmask | bmask)); % double to use as multiplier, not index
166 |
167 | cfa = fullColorIm(:,:,1).*rmask + fullColorIm(:,:,2).*gmask + fullColorIm(:,:,3).*bmask;
168 |
169 | end % end function
170 | end % end protected methods
171 |
172 | end % end classdef
173 |
174 |
175 |
--------------------------------------------------------------------------------
/PipelineModel.m:
--------------------------------------------------------------------------------
1 | % Copyright (C) 2017 Imatest LLC
2 | %
3 | % This program is free software: you can redistribute it and/or modify
4 | % it under the terms of the GNU General Public License as published by
5 | % the Free Software Foundation, either version 3 of the License, or
6 | % (at your option) any later version.
7 | %
8 | % This program is distributed in the hope that it will be useful,
9 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | % GNU General Public License for more details.
12 | %
13 | % You should have received a copy of the GNU General Public License
14 | % along with this program. If not, see .
15 |
16 | classdef PipelineModel
17 | % The PipelineModel class is essentially a container for an ordered set of user-defined
18 | % operations to apply to the data array output of a SensorModel's .expose() method.
19 | %
20 | % An instance's .process() method does two things:
21 | % (1) Apply, in order, the operations indicated in its .processes property to the input data
22 | % (2) Convert the output of the last process to the datatype indicated in the .outputType
23 | % property. (Currently, only 'uint8' or 'uint16')
24 | %
25 | % The .process property should be a cell array of cell arrays. Each cell entry of the primary
26 | % array should itself be a cell array with form {@fcn_handle, arg1, arg2, ...}.
27 | % Each of these will be used to apply the function indicated by fcn_handle to the data, in order.
28 | % Any supplemental arguments (i.e., data-independent parameters for the processing), should fill
29 | % out the remaining elements of the sub-cell array.
30 | %
31 | % Functions used in this process should have signature: fcn(data,arg1,arg2,...)
32 | % Here, data is the data array (dimension and data type not guaranteed- it depends on the
33 | % previous processing steps) output by the previous process. The only guarantee is that the input
34 | % to the first process will be a type uint16.
35 | %
36 | % Oftentimes these processes and their supplemental parameter values will need to be specifically
37 | % set to match the SensorModel used. E.g., Removing the specific offset applied by the sensor
38 | % model, demosaicking the correct Bayer orientation of the sensor, scaling the data based on the
39 | % sensor's maxDN, etc.
40 | %
41 | % Some useful examples of processing functions are included as class static methods. These
42 | % include:
43 | % outData = demosaic(inData,bayerPhase) Apply MATLAB improc toolbox demosiacing.
44 | % outData = scale_max(inData,inMax,outMax) Re-scale the data.
45 | % outData = apply_gamma(inData,gamma,maxVal) Apply a gamma power encoding to data.
46 | %
47 | %
48 | % See also: DummyPipeline
49 |
50 |
51 | properties
52 | processes % cell array of cell arrays, each entry of form {@fcn, arg1, arg2, ...}
53 | outputType = 'uint8' % can be 'uint8' or 'uint16'
54 | end
55 |
56 |
57 |
58 | methods
59 |
60 | function obj = PipelineModel(processArray)
61 | % model = PipelineModel()
62 | % model = PipelineModel(processArray)
63 | %
64 | % Create a PipelineModel instance, optionally passing in as an argument the ordered set of
65 | % functions to apply as the pipeline (as a cell array of cell arrays).
66 | %
67 | % Default Pipeline:
68 | % (1) Demosaic
69 | % (2) Scale from default SensorModel.maxDN of 2^10-1 to 8-bit max
70 | % (3) Apply gamma of 1/2.2, to make it look like sRGB.
71 | % (4) Output as 8-bit.
72 |
73 | if nargin==0
74 | proc1 = {@PipelineModel.demosaic, 'grbg'};
75 | proc2 = {@PipelineModel.scale_max, 2^10-1, 255}; % defaults to match default SensorModel
76 | proc3 = {@PipelineModel.apply_gamma, 1/2.2, 255};
77 |
78 | processArray = {proc1, proc2, proc3};
79 | end
80 |
81 | % Check the inputs
82 | if iscell(processArray)
83 | for i = 1:length(processArray)
84 | if ~iscell(processArray{i})
85 | error('Constructor input (if supplied) must be a cell array of cell arrays.')
86 | end
87 | end
88 | obj.processes = processArray;
89 | else
90 | error('Constructor input (if supplied) must be a cell array of cell arrays.')
91 | end
92 |
93 | end
94 |
95 |
96 |
97 | function processedIm = process(obj,sensorData)
98 | % processedIm = pipeline.process(sensorData)
99 | %
100 | % - - Input - -
101 | % sensorData : MxN sensor data array
102 | %
103 | % - - Output - -
104 | % processedIm : image data array, of type indicated by .outputType property. Dimensions not
105 | % particularly guaranteed.
106 | %
107 |
108 | for i = 1:length(obj.processes)
109 | fnc = obj.processes{i}{1};
110 | args = obj.processes{i}(2:end);
111 | sensorData = feval(fnc,sensorData,args{:});
112 | end
113 |
114 | processedIm = cast(sensorData,obj.outputType);
115 | end
116 |
117 |
118 | end
119 |
120 |
121 |
122 | methods (Static)
123 |
124 |
125 | function outData = demosaic(inData,bayerPhase)
126 | % outData = demosaic(inData,bayerPhase)
127 | %
128 | % Apply the built-in (MATLAB) demosaicing function. Requires Image Processing Toolbox.
129 | % Currently, only works for values in range [0, 2^16-1]. (Conversion to integer happens
130 | % before demosaicing.)
131 | %
132 | % - - Inputs - -
133 | % inData : image data array, MxNx1. If floating point, values should NOT be normalized 0-1.
134 | % bayerPhasee : string indicating Bayer CFA phase- 'grbg', 'rggb', 'bggr', or 'gbrg'
135 | %
136 | % - - Output - -
137 | % outData : color image data, MxNx3
138 |
139 | if ~isinteger(inData)
140 | inData = uint16(inData);
141 | end
142 |
143 | outData = demosaic(inData,bayerPhase);
144 |
145 | % Return to input type as needed
146 | if ~isinteger(inData)
147 | outData = cast(outData, class(inData));
148 | end
149 |
150 | end
151 |
152 |
153 |
154 | function outData = scale_max(inData,inMax,outMax)
155 | % outData = scale_max(inData,inMax,outMax)
156 | %
157 | % Simple scaling of the data so that the input max value (e.g. a sensor's max value) maps
158 | % to another chosen one, preserving type but doing calculation on real values.
159 | %
160 | %
161 | % - - Inputs - -
162 | % inData : image data array, any type
163 | % inMax : maximum (saturation) value of input data
164 | % outMax : maximum (saturation) value of output data
165 | %
166 | % - - Output - -
167 | % outData : scaled image data array, same type as input
168 |
169 | outData = cast(double(inData)/inMax*outMax, class(inData));
170 |
171 | end
172 |
173 |
174 |
175 | function outData = apply_gamma(inData,gamma,maxVal)
176 | % outData = apply_gamma(inData,gamma,maxVal)
177 | %
178 | % Apply gamma encoding to an image. Note that the value applied should be the reciprocal of
179 | % what is often called the gamma value.
180 | %
181 | % For example, to encode an image in a sRGB-like 2.2 encoding, you actually enter the value
182 | % of 1/2.2.
183 | %
184 | % Data type is preserved in output, but calculation is done on type double conversion.
185 | %
186 | % - - Inputs - -
187 | % inData : image data array, any size or dimension
188 | % gamma : power value to raise the data to
189 | % maxVal : the value which maps to saturation in the image data
190 | %
191 | % - - Output - -
192 | % outData : gamma-encoded image data, same size as input
193 |
194 | % Normalize to 1 if not already.
195 | if maxVal ~= 1
196 | origType = class(inData);
197 | inData = double(inData)/maxVal;
198 | end
199 |
200 | outData = inData.^gamma;
201 |
202 | % Undo normalization if need be
203 | if maxVal ~= 1
204 | outData = cast(outData*maxVal,origType);
205 | end
206 | end
207 |
208 | end
209 |
210 | end % end classdef
211 |
212 |
213 |
--------------------------------------------------------------------------------
/LensModel.m:
--------------------------------------------------------------------------------
1 | % Copyright (C) 2017 Imatest LLC
2 | %
3 | % This program is free software: you can redistribute it and/or modify
4 | % it under the terms of the GNU General Public License as published by
5 | % the Free Software Foundation, either version 3 of the License, or
6 | % (at your option) any later version.
7 | %
8 | % This program is distributed in the hope that it will be useful,
9 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | % GNU General Public License for more details.
12 | %
13 | % You should have received a copy of the GNU General Public License
14 | % along with this program. If not, see .
15 |
16 | classdef LensModel
17 | % The LensModel class simulates common observable effects on image quality from lenses from
18 | % standard mathematical models of those effects. It does NOT do any simulation based on light
19 | % spectra or ray tracing, rather it simply applies the effects of distortion, LCA, etc to an
20 | % input image according to the common models used to describe those effects.
21 | %
22 | % Input data to the .simulate() method should be 3-channel RGB data. Since this class does not
23 | % deal with spectra, it is simply assumed that these tri-stimulus values are affected by the
24 | % models described below.
25 | %
26 | %
27 | % - - Geometric Distortion - -
28 | % The distortion model assumes radial distortion from the center of the image, described by a
29 | % 3rd- or 5th-order polynomial which maps from the true radial position to the distorted radial
30 | % position. This is not the same as the Local Geometric Distortion (LGD) description of radial
31 | % distortion, though it is possible to convert between the two.
32 | %
33 | %
34 | % - - Lateral Chromatic Aberration - -
35 | % The Lateral Chromatic Aberration (LCA) model assumes radial position errors of red and blue
36 | % channels relative to the green channel. Furthermore, it is assumed that this relative error is
37 | % described by a 3rd- or 5th-order polynomial which maps from relative displacement (aberration)
38 | % to radial distance.
39 | %
40 | % It is always assumed that the polynomials used are defined on the range [0, 1], with 1 being
41 | % the distance from the center of the image array (between pixels if even-sized height and width)
42 | % to the center of the pixel at the corner of the array (any corner). Thus the radial
43 | % distortion polynomials are all on normalized radial coordinates, normalized using the
44 | % half-diagonal distance.
45 | %
46 | % These polynomials are all defined in the code in the manner consistent with (and described by)
47 | % the MATLAB functions polyfit() and polyval(). Refer to those function help files for more.
48 | %
49 | % See the IEEE-1858 CPIQ specification for more description of the LCA model.
50 | %
51 | % - - Optical Center Offset - -
52 | % Both LCA and Geometric Distortion are radial in nature. The center of this distortion is the
53 | % 'optical center' of the lens, which by default is the same as the center of the array of the
54 | % scene data put in. However, you can specifyan amount, in real values in units of pixels, an
55 | % offset from the center of the image array where the optical center actually falls.
56 | %
57 | % Values are in "image coordinate" orientation, and so positive values, [dx, dy], indicate an
58 | % optical center which is towards the lower left of the image by the indicated amounts.
59 | %
60 | % - - Flare - -
61 | % The flare model assumes that some portion of the light from each pixel gets spread evenly
62 | % around the image to every other pixel. (This portion is identified in this class as the
63 | % 'flareConstant', which should be in the range [0, 1].)
64 | %
65 | % The model thus becomes that each input value is attenuated by flareConstant (i.e., scaled to
66 | % value*(1-flareConstant)), and then the total energy that has been 'sapped' from all locations
67 | % is then summed and distributed equally to all locations. Total amount of input signal is
68 | % preserved, just redistributed.
69 | %
70 | %
71 | % Flare is applied per-color channel, as a soft way of modeling that different wavelengths may
72 | % have different amounts of flare. (This is a bit of a hack.)
73 | %
74 | %
75 | % See also: DummyLens
76 |
77 | properties
78 | distortionCoeffs % polynomial coeffs for forward radial distortion
79 | lcaCoeffs_rg % polynomial coeffs for forward application of relative red-green radial aber.
80 | lcaCoeffs_bg % polynomial coeffs for forward application of relative blue-green radial aber.
81 | flareConstant = 0; % relative to the max of the scene, e.g. 1/1000
82 | opticalCenterOffset = [0,0]; % [dx,dy] offset from center of image array (real valued)
83 | end
84 |
85 |
86 | methods
87 |
88 | function obj = LensModel(varargin)
89 | % model = LensModel()
90 | % model = LensModel(name, value,...)
91 | %
92 | % Optional parameter pair-value pairs are:
93 | % 'distortionCoeffs', polynomial coefficient vector, 3rd or 5th order
94 | % 'lcaCoeffs_rg', polynomial coefficient vector, 3rd or 5th order
95 | % 'lcaCoeffs_bg', polynomial coefficient vector, 3rd or 5th order
96 | % 'opticalCenterOffset', [dx, dy] array of real values
97 | % 'flareConstant', a real value in range [0,1]
98 | %
99 | % Default LensModel (or any subset of missing optional input parameters) results in a model
100 | % which has no distortion, no LCA, and no flare.
101 |
102 | % Parse inputs
103 | default_distortionCoeffs = [0 0 1 0]; % 3rd order polynomial identity function
104 | default_lcaCoeffs_rg = [0 0 0 0]; % nuthin'
105 | default_lcaCoeffs_bg = [0 0 0 0]; % nuthin'
106 | default_offset = [0,0];
107 | default_flareConstant = 0;
108 |
109 | parser = inputParser();
110 | parser.addParameter('distortionCoeffs',default_distortionCoeffs)
111 | parser.addParameter('lcaCoeffs_rg',default_lcaCoeffs_rg)
112 | parser.addParameter('lcaCoeffs_bg',default_lcaCoeffs_bg)
113 | parser.addParameter('flareConstant',default_flareConstant)
114 | parser.addParameter('offset', default_offset)
115 | parser.parse(varargin{:});
116 | params = parser.Results;
117 |
118 | obj.distortionCoeffs = params.distortionCoeffs;
119 | obj.lcaCoeffs_bg = params.lcaCoeffs_bg;
120 | obj.lcaCoeffs_rg = params.lcaCoeffs_rg;
121 | obj.flareConstant = params.flareConstant;
122 | obj.opticalCenterOffset = params.offset;
123 | end
124 |
125 |
126 | function sensorPlaneRadiantPower = simulate(obj,sceneRadiantPower)
127 | % sensorPlaneRadiance = simulate(obj,sceneRadiantPower)
128 | %
129 | % - - Input - -
130 | % sceneRadiantPower : MxNx3 array of real values, indicating the radiant power
131 | % (photons/sec) in 3 color bands striking the front glass of the lens
132 | %
133 | % - - Output - -
134 | % sensorPlaneRadiantPower : MxNx3 array of doubles, the radiant power values after being
135 | % affected by lens and being received at the sensor plane
136 |
137 |
138 | % Unpack properties to local variables in correct form, which transforms radial distances
139 | % from distorted -> undistorted
140 | distortionInverseCoeffs = invert_poly(obj.distortionCoeffs);
141 | rgInverseCoeffs = lca2inverse_poly(obj.lcaCoeffs_rg);
142 | bgInverseCoeffs = lca2inverse_poly(obj.lcaCoeffs_bg);
143 |
144 | width = size(sceneRadiantPower, 2);
145 | height = size(sceneRadiantPower, 1);
146 |
147 | % Produce a mesh grid of the coordinates of each pixel, relative to the exact center of the image
148 | xs = (1:width) - ((width+1)/2 + obj.opticalCenterOffset(1));
149 | ys = (1:height) - ((height+1)/2 + obj.opticalCenterOffset(2));
150 | [X, Y] = meshgrid(xs,ys);
151 | normFactor = sqrt(((width+1)/2)^2 + ((height+1)/2)^2); % to normalize center-corner distance to 1
152 |
153 | % Convert cartesian coordinates of each pixel location to polar
154 | [THETA, RHO_u] = cart2pol(X, Y);
155 | scaleFactor = polyval(distortionInverseCoeffs, 1); % to keep the corners pinned to the corners
156 | RHO_u = RHO_u/normFactor*scaleFactor;
157 |
158 | % Make a new radial component for each color channel. They all share the same overall
159 | % distortion, and then the red and blue channels are aberrated relative to the green.
160 | RHO_d = zeros(size(RHO_u,1),size(RHO_u,2),3);
161 | RHO_d(:,:,2) = polyval(distortionInverseCoeffs,RHO_u);
162 | RHO_d(:,:,1) = polyval(rgInverseCoeffs,RHO_d(:,:,2));
163 | RHO_d(:,:,3) = polyval(bgInverseCoeffs,RHO_d(:,:,2));
164 |
165 | % Re-sample at the new (distorted) coordinates by color channel.
166 | sensorPlaneRadiantPower = zeros(height,width,3);
167 | for c = 1:3
168 | channelData = double(sceneRadiantPower(:,:,c));
169 | % Convert back to cartesian coordinates to get the (x,y) distorted sample points
170 | % in image space
171 | [X_d, Y_d] = pol2cart(THETA, RHO_d(:,:,c)*normFactor);
172 | sensorPlaneRadiantPower(:,:,c) = interp2(X, Y, channelData, X_d, Y_d, 'cubic', 0);
173 |
174 | % Add flare, for now a field-wide constant per color channel
175 | meanFlare = obj.flareConstant*norm(channelData(:))/sqrt(width*height);
176 | sensorPlaneRadiantPower(:,:,c) = sensorPlaneRadiantPower(:,:,c)*(1-obj.flareConstant) + meanFlare;
177 | end
178 |
179 | end
180 | end
181 |
182 | end % end classdef
183 |
184 |
185 |
186 | % - - - Utility functions - - -
187 | function inverseCoeffs = lca2inverse_poly(lcaCoeffs)
188 | % inverseCoeffs = lca2inverse_poly(lcaCoeffs)
189 | %
190 | % Converts polynomial coefficients from the form Imatest/CPIQ describes LCA in, which is based on
191 | % relative radial displacement, to polynomial coefficients which directly map from distorted
192 | % color channel radii to undistorted radii.
193 | %
194 | % Does conversion numerically, so this is really only valid for functions which can be well
195 | % appropximated by a 5th order (or lower) polynomial.
196 | %
197 | % Always returns a 5-th oder polynomial.
198 |
199 | lcaCoeffs(end-1) = lcaCoeffs(end-1)+1;
200 |
201 | rDistorted = linspace(0,1,50);
202 | rUndistorted = polyval(lcaCoeffs,rDistorted);
203 | inverseCoeffs = polyfit(rUndistorted,rDistorted,5);
204 |
205 | end
206 |
207 | function outcoeffs = invert_poly(inCoeffs)
208 | % forwardCoeffs = invert_poly(inverseCoeffs)
209 | % inverseCoeffs = invert_poly(forwardCoeffs)
210 | %
211 | % Inverts the polynomial whose coefficients are supplied.
212 | % This function is only good for distortion/aberration which is well approximated by 5th order
213 | % polynomial.
214 | %
215 | % Always puts out a 5th order inversion polynomial. Input can be 3rd or 5th order.
216 |
217 |
218 | % Inversion is done numerically by generating some undistorted points, calculating some distorted
219 | % version of them, and then fitting a polynomial.
220 |
221 | rDistorted = linspace(0,1,10); % radial distortion is <= 5th order, so 10 points is more than enough
222 | rUndistorted = polyval(inCoeffs,rDistorted);
223 | outcoeffs = polyfit(rUndistorted,rDistorted,5);
224 | end
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | Simatest is **Imatest**'s **sim**ulation suite. Simatest is designed to simulate exposures of a 'scene' made with a virtual camera whose parameters can be set by the user.
2 |
3 | Simatest is open source (GPLv3) but written in MATLAB. It requires the MATLAB Image Processing toolbox.
4 |
5 | [GNU Octave](https://www.gnu.org/software/octave/) is the open-source replacement to MATLAB, if you want to be completely open. It boasts drop-in compatibility with many MATLAB scripts, though we have not tested compatibility ourselves.
6 |
7 | Simatest makes use of the object-oriented aspects of MATLAB, which you can familiarize yourself with [here](https://www.mathworks.com/help/matlab/object-oriented-programming.html).
8 |
9 |
10 |
11 | ## What Simtest does:
12 | Simatest is a suite for producing simulated camera exposures based on an input raster image as ground truth.
13 |
14 | * It can simulate lens-originated aspects of image formation *in effect only, not in cause*. That is, we simulate things such as radial geometric distortion lateral chromatic aberration only by direct application of the very models of these effects which Imatest tests for. We do not simulate the actual optical causes of these effects.
15 |
16 | * It can simulate an exposure with a linear sensor with a very realistic noise model.
17 |
18 | * It can apply any arbitrary, user-defined image-processing pipeline to the raw (simulated) sensor output. This can include demosaicking, scaling, color correction, etc.
19 |
20 |
21 |
22 | ## What Simatest does not do:
23 | Simatest does not (currently)
24 |
25 | * slice
26 | * dice
27 | * work with vector inputs
28 | * directly model light spectra
29 | * trace rays or model geometric optics
30 | * implement a general "planar image in front of a camera" model (with perspective distortion, etc)
31 |
32 | It is likely that the last point will be implemented in the future. But besides that and possibly support for vector graphic inputs, it is generally out of the scope of this project to implement true optical simulations.
33 |
34 |
35 |
36 | ## Quick-start guide
37 | Simatest works in the following fashion:
38 |
39 | 1. Create or load an image to use as the 'scene' to simulate an exposure of.
40 | * The values of this base image will be intepreted as light power (per location and color channel) in units of photons/second, so scale it accordingly.
41 | 2. Create a `CameraModel` instance to image the scene.
42 | * This needs to be tied to the size of the scene image, and can be created as so: `camodel = CameraModel(size(scene))`
43 | * The `CameraModel` instance has models for each of three components of the system: the lens, the sensor, and the processing.
44 | 3. Create new `LensModel`, `SensorModel`, or `PipelineModel` instances with properties of your choosing and store them in the `CameraModel` as appropriate, or simply set the property values of the existing ones directly.
45 | * *e.g.*, `camodel.sensorModel.gain = 2;` sets the sensor component's electron-to-DN gain to 2.
46 | 4. Produce a simulated exposure of the scene by invoking the `CameraModel`'s `.simulate_exposure(scene,t)` method.
47 | * The second argument of this method is an exposure time, in seconds. An appropriate exposure time can be found by invoking the `t = camodel.find_ae_time(scene,mode)` method, which effectively acts as an auto-exposure function.
48 | * A composite call may look like: `exposure = camodel.simulate_exposure(scene,camodel.find_ae_time(scene,'saturation')`
49 | 5. View or save your simulated exposure! It is correctly formatted already for function like `imshow()` and `imwrite()`.
50 |
51 |
52 |
53 | ## The Scene (input data)
54 | Simatest uses an image data array as an input "scene" of the real world.
55 |
56 | Currently, Simatest is designed so that the each pixel of a scene maps to a pixel of the virtual camera sensor. The digital values at each pixel location in the scene are used to represent the *radiant power in units of photons/second*.
57 |
58 | Because of this, input data scenes should be the same resolution as the virtual camera imaging them. Note that this holds even when the lens modeling component simulate geometric distortion- it will return a distorted image of the same size (which can be read as the radiant energy falling at each pixel location on the sensor plane).
59 |
60 |
61 | #### Color Channels
62 | Since Simatest models do not deal with light spectra, they assume that different R, G, B color channels of the input scene are already intensity/power values relative to the sensitivities of the R, G, B filtered pixel locations of the Bayer sensor.
63 |
64 | These interact with the `SensorModel`'s `.qe` (quantum efficiency) property which also scales each of the input channels.
65 |
66 | This method allows us to use simulate the effects of different color *data* without having to simulate the *cause* of these data, e.g. an integral over wavelengths of a spectrum with a sensitivity curve (which is itself the combination of wavelength-dependent QE and color filter sensitivities). The user is urged to think about these interpretations and their ramifications on the simulations.
67 |
68 |
69 |
70 | #### Note on linearity
71 | Light is linear, and so the input scene data will be interpreted as linear as well. This means that if you use, *e.g.*, an sRGB-encoded image as the base for scene data the data will be interpreted as linear, which is probably incorrect and not what you intended. If you use a `CameraModel` which applies its own gamma to an exposure of this scene, it would look "double gamma'd".
72 |
73 | In short, input scene data should be 'linear', and it is up to the user to make sure that it is. If the image looks "right" using imshow() before being put into as scene data input (and you have a regular computer monitor), something is probably wrong.
74 |
75 |
76 |
77 |
78 |
79 | ## `CameraModel` class
80 | A virtual camera is represented by the `CameraModel` class. This class is essentially just a container for the models of the three sub-components-- LensModel, SensorModel, and PipelineModel-- and some control methods (such as simulating auto-exposure to determine exposure time based on a scene).
81 |
82 | The general procedure is to instantiate a `CameraModel` object, `camodel`, populate its `.sensorModel`, `.lensModel`, and `.pipelineModel` properties appropriately, create an input scene image array, and then make a virtual exposure of it using:
83 |
84 | `capture = camodel.simulate_exposure(sceneData, t)`
85 |
86 | Here `t` is the exposure time for capturing this scene, just as you would need to set with a real camera.
87 |
88 | Just as in real life, it's necessary to tie the exposure time appropriately to the scene content- you wouldn't take a 1/4000s exposure in a low-light scene because you wouldn't get any signal, and you wouldn't take a 1s exposure in daylight because it would saturate everything.
89 |
90 | `CameraModel` instances have a useful method, `camodel.find_ae_time(sceneData, mode)`, which will help you determine an appropriate exposure time based on the current gain setting and the brightness (data value magnitudes) of the scene. Basically, it's a camera auto-exposure method with two modes:
91 |
92 | * `grayworld` (default) : find the exposure time that brings the mean raw data value (after gain, before processing) of the scene to 1/2 of the maximum
93 | * `saturation` : find the exposure time that brings the maximum value of the scene just to the saturation point
94 |
95 |
96 | Invoking the `camodel.simulate_exposure()` method manages the calls to the simulation functions of the component models. Thus, this is the main interface for actually performing the simulation and you do not need to access the methods of the subsequent classes directly, only set their properties appropriately.
97 |
98 |
99 | ## `LensModel` class
100 | `LensModel` instances contain properties that define the effective radial distortion, lateral chromatic aberration, and lens flare (aka veiling glare) a lens may introduce. It is important to note that we simulate the observable effects of these degradations, *not* the causes. The models used are typically those which we can give a measurement of in Imatest.
101 |
102 |
103 | #### Radial Distortion
104 | Radial geometric disortion can be applied by a `LensModel` instance by setting the polynomial coefficients which define the distortion function in its `.distortionCoeffs` property.
105 | This polynomial can be 3rd or 5th order, and describes the function f() such that
106 |
107 | r\_d = f(r\_u)
108 |
109 | Here r\_u is the normalized, undistorted image radius (distance from center) of a point, and r\_d is the distrted version of it. Note that this function is the inverse of the one whose polynomial coefficients Imatest measures and returns- that function maps from r\_d to r\_u.
110 |
111 | #### Lateral Chromatic Aberration (LCA)
112 | LCA (sometimes known as LCD, Lateral Chromatic Displacement) is defined as different radial distances of points per each color channel. Like geometric distortion, it is modeled here as radial and with a polynomial approximation (3rd or 5th order please).
113 |
114 | Since LCA is just about relative displacement of the different color channels, it is enough to use one channel as the base and 'aberrate' the others relative to it. We use the green color channel as base, so two LCA-defining polynomials are required to describe the displacement of the other channels- red channel relative to green in the `.lcaCoeffs_rg` property and blue channel relative to green in the `.lcaCoeffs_bg` property.
115 |
116 | Each of these is used to describe functions that make the transformation:
117 |
118 | r\_red = f(r\_green)
119 | or
120 | r\_blue = f(r\_green)
121 |
122 | #### Optical Center offset
123 | Radial optical effects emanate from the optical center of the lens system. This is assumed to be the exact center of the data array of the scene data (which is a between-pixel location on even-sized dimensions) unless the user sets the `.opticalCenterOffset` property with a real 2-vector `[dx, dy]`. These values indicate the number of pixels of displacement there is between the image center and optical center, and affects things like Radial Distortion and LCA. The values are in the 'image coordinate' orientation and thus positive values will move the optical center *down* and to the *right* in the image.
124 |
125 |
126 | #### Lens Flare
127 | We model lens flare as a global effect in Simatest. That means that some fraction of the light power coming in from each location is spread around to the entire image, effectively raising the floor level from 0 and reducing contrast.
128 |
129 | The flare model assumes that some portion of the light from each pixel gets spread evenly around the image to every other pixel. This portion is identified in `LensModel` instances by the `.flareConstant`, which should be in the range [0, 1].
130 |
131 | The model thus becomes that each input value is attenuated by the flare constant (i.e., scaled to `value*(1-flareConstant)`), and then the total energy that has been 'sapped' from all locations is then summed and distributed equally to all locations. Total amount of input signal is preserved, just redistributed.
132 |
133 | ### Default `LensModel`
134 | The default instance of this class produced with an empty constructor essentially is a perfect lens- it has no flare, identity function distortion, and no LCA.
135 |
136 |
137 | ## `SensorModel` class
138 | `SensorModel` class instances represent a linear sensor with a Bayer Color Filter Array. There is a highly realistic noise model for this sensor, based on the model described in the EMVA1288 standard. The user is encouraged to refer to that (very smartly written) document [here](http://www.emva.org/standards-technology/emva-1288/), as we will not explain all of the elements in depth here. This noise model includes signal-dependent shot noise as well as a number of device-dependent additive and multiplicative sources.
139 |
140 | Creating a `SensorModel` instance requires a two element *size* array, [M, N], whose elements indicate the number of rows and columns, respectively, of the simulated sensor.
141 |
142 | Note that below we use the term 'DN' to to refer to 'digital number', the output of the analog-to-digital converter (ADC) of the sensor. This is the raw data output of the sensor. Also note that this class always produces data of type `uint16` from its simulations, regardless of what the actual range the sensor effectively has (defined by `.maxDN`). Note that this means you can't meaningfully set `.maxDN` greater than 2^16-1.
143 |
144 |
145 | ##### Noise-model related properties
146 | **Property** | **Value type** | **Meaning**
147 | -------- | ---------- | -------
148 | `.darkCurrent` | MxN double | Additive per-pixel non-uniformity during integration time, units of electrons/sec
149 | `.noiseFloor_e` | double | Additive noise after integration (due to readout, etc), units of electrons
150 | `.prnu` | MxN double | Multiplicative per-pixel non-uniformity relative to mean gain, unitless
151 |
152 |
153 | ##### Linear-sensor related properties
154 | **Property** | **Value type** | **Meaning**
155 | -------- | ---------- | -------
156 | `.gain` | double | electronic gain factor, units of DN/electron
157 | `.maxDN` | integer | Maximum digital number value, e.g. 2^10-1 for a 10-bit ADC. This need not be related to a power of 2.
158 | `.offset` | integer | Black level offset, units of DN
159 | `.qe` | 1x3 vector | Effective sensitivity of the R, G, B channel locations, respectively, to the input, units of electrons/photons.
160 | `.wellCapacity` | integer | Maximum number of electrons the photosensitive element can hold. Can be set to `inf`.
161 |
162 | (Note that a sensor can produce 'saturated' output at a pixel that either hits the well capacity in electrons or hits the maxDN in electrons\*gain, whichever comes first. Note that the former *is* saturated by all reasonable definitions, though not at max output level of the sensor.)
163 |
164 | ##### Other properties
165 | **Property** | **Value type** | **Meaning**
166 | -------- | ---------- | -------
167 | `.bayerPhase` | string | Phase (orientation) of the Bayer sensor, describing the upper left (square) block of four pixels in raster order. Either 'grbg' (default), 'rggb', 'bggr', or 'gbrg'.
168 |
169 |
170 | ### Default `SensorModel`
171 | The default instance of this class (constructed with only a sensorSize argument) is 10-bit Bayer-GRBG, unitary gain and qe, infinite well-capacity and no data offset, with no additive noise, PRNU, or dark current.
172 |
173 |
174 | ## `PipelineModel` class
175 | Instances of the `PipelineModel` class are the most flexible of the three components, because it is arbitrarily defined by the user. The user can construct a sequence of operations to apply to the raw data output of the `SensorModel`'s simulation, using any MATLAB function of their devising.
176 |
177 | The user must populate the `PipelineModel` instance's `.processes` property with a sequence of functions to apply to the data, in order. These can (and should) be functions for demosaicking, scaling, gamma compression, etc, that you might expect raw data from a sensor to be subjected to.
178 |
179 | Each function to be applied to the data should be stored in a cell array as `processCell = {myFnc_handle, arg1, arg2, ...}`. This function will then be called during execution of the instance's `.process()` method (which is managed by the containing `CameraModel` instance's `.simulate_exposure()` method) as follows:
180 |
181 | `dataOut = myFnc(dataIn, arg1, arg2, ...)`
182 |
183 | You must make sure any functions you register with the pipeline follow this signature of image data array as the first argument and supplemental arguments following.
184 |
185 | Multiple processes can be applied to the data, in order, by creating a cell array of these cell arrays, like `{processCell1, processCell2, ...}`. (Of course, you could also write one all-encompassing processing function and that takes in the raw data and produces the finished output, and register that one function with the `PipelineModel`.)
186 |
187 | The only other aspect of `PipelineModel` instances is the `.outputType` property, which is a string that can be set to either `'uint8'` or `'uint16'`. This indicates the final data type of the output image, and invokes a casting as that type after the final process defined in the set of `.processes`.
188 |
189 | #### Example processing functions
190 | Some useful examples of processing functions are included as `PipelineModel` class static methods. These include:
191 |
192 | outData = PipelineModel.demosaic(inData,bayerPhase); % Apply MATLAB Image Processing toolbox demosiacing
193 | outData = PipelineModel.scale_max(inData,inMax,outMax); % Re-scale the data
194 | outData = PipelineModel.apply_gamma(inData,gamma,maxVal); % Apply a gamma power encoding to data
195 |
196 | ### Default `PipelineModel`
197 | The default pipeline processing is tied to the default `SensorModel`, described above, in order to make simple implementations work nicely. It simply demosaics the image, scales from the 10-bit data to 8-bit data, and applies an sRGB-like gamma of 2.2, and finally outputs an 8-bit image.
198 |
199 |
200 |
201 | ## Dummy Component Models
202 | A common task is to simulate only one aspect of this entire camera-modeling process. For example, if you only want to apply geometric distortion or LCA on an image using a certain lens model but don't want to make a fake 'exposure' of it or process it in other ways.
203 |
204 | You can shortcut component models of the `CameraModel` with 'dummy instances'. These typically just have overridden simulation methods which pass the data through untouched.
205 |
206 | The available Dummy models ready for instantiation are:
207 |
208 | * `DummyLens` : Does nothing (very similar to the default `LensModel` implementation, but faster to run)
209 | * `DummyBayerSensor` : only mosaics the 3-channel data from the lens sensor and converts to `uint16`
210 | * `DummyColorsensor` : does nothing to 3-channel data from the lens simulation except convert to `uint16`. Note that any `PipelineModel` that is to follow this should be prepared for this, since it is atypical, and not assume the output is 1-channel like from most `SensorModel`s. (Note: A `DummyPipeline` meets this criterion.)
211 | * `DummyPipeline` : does nothing to the data, outputs it as `uint8`
212 |
213 |
214 |
215 | ## Example use cases
216 | These assume you have a file in your working directory called 'linear_test_im.png'. As the name implies, and as indicated above, it should be linear (*i.e.* not gamma encoded).
217 |
218 | Note that this is easy to create from a standard sRGB 8-bit image as follows:
219 |
220 | im = imread('my_favorite_image.jpg');
221 | im = (double(im)/255).^(2.2); % simple power approximation to actual sRGB encoding
222 | imwrite(im,'linear_test_im.png')
223 |
224 |
225 | #### Bracket exposure times
226 | The following will load an image to use as a scene, create a default `CameraModel` to image it, and bracket the exposure times around the auto-exposure-suggested exposure time. This changes the amount of integrated light falling on the sensor, and thus the exposure.
227 |
228 | The results are shown in a new figure window.
229 |
230 | scene = imread('linear_test_im.png'); % Load an image to use as the 'scene'
231 | camodel = CameraModel(size(scene)); % Instantiate a virtual camera for this scene, using default settings
232 |
233 | tOpt = camodel.find_ae_time(scene,'saturation'); % Find auto-exposure suggested exposure time
234 | bracketStops = [-2 -1 0 1]; % set of exposures in stops) relative to ideal exposure we want to explore
235 |
236 | figure
237 | for i = 1:length(bracketStops)
238 | t = tOpt*2^(bracketStops(i)); % Compute exposure time for this bracketed exposure
239 | simulated = camodel.simulate_exposure(scene,t); % Simulate the exposure
240 | subplot(2,2,i)
241 | imshow(simulated)
242 | end
243 |
244 |
245 |
246 | #### Bracket gain while maintaining exposure
247 | The following brackets the sensor gain (proportional to ISO speed, but defined in terms of DN/electron) while also changing the exposure time to keep the overall "exposure" level constant. Note that this has the practical effect of more effective noise in the image.
248 |
249 | scene = imread('linear_test_im.png'); % Load an image to use as the 'scene'
250 | camodel = CameraModel(size(scene)); % virtual camera with default setting of sensorModel.gain = 1
251 |
252 | gains = [0.25, 1, 4, 16]; % gain levels (DN/electrion) we want to explore
253 |
254 | figure
255 | for i = 1:length(gains)
256 | camodel.sensorModel.gain = gains(i); % Set gain to chosen level
257 | t = camodel.find_ae_time(scene,'saturation'); % Find suggested exposure time for this gain level
258 | simulated = camodel.simulate_exposure(scene,t); % Simulate the exposure
259 | subplot(2,2,i)
260 | imshow(simulated)
261 | end
262 |
263 |
264 |
265 | #### Simulate raw sensor data
266 | If we want to test measurements from raw sensor data, or a demosaicking algorithm, etc, we can just instantiate a dummy pipeline module so that we get out the raw data from the sensor as is (type `uint16`).
267 |
268 | scene = imread('linear_test_im.png'); % Load an image to use as the 'scene'
269 | camodel = CameraModel(size(scene));
270 |
271 | camodel.pipelineModel = DummyPipeline(); % Use a pipeline that just passes data through
272 |
273 | % Default output of dummy pipeline is uint8, but we don't want to truncate uint16 data from the
274 | % SensorModel, so overwrite the .outputType property.
275 | camodel.pipelineModel.outputType = 'uint16';
276 |
277 | simulated = camodel.simulate_exposure(scene, camodel.find_ae_time(scene)); % uses default AE mode 'grayworld'
278 |
279 | % We must scale the output image for viewing, since the default SensorModel puts out 10-bit data in
280 | % a 16-bit format.
281 | figure
282 | imshow(simulated,[0, 2^10-1])
283 |
284 |
285 |
286 |
287 | #### Simulating only LCA on a real image
288 | Sometimes we just want to simulate a degradation effect on a real image. For example, for studying subjective image quality loss due to LCA according to user ratings, we would want to apply controlled, known amounts of LCA to real images. This can be done by appropriately setting the parameters of the `LensModel` and using dummy components for the sensor and pipeline.
289 |
290 | scene = imread('real_world_im.jpg'); % Load a non-simulated, sRGB image as the 'scene'
291 | camodel = CameraModel(size(scene));
292 |
293 | % Set the LensModel's LCA parameters, overwriting the default values of zero polynomials
294 | camodel.lensModel.lcaCoeffs_bg = [-0.01,0,0.02,0];
295 | camodel.lensModel.lcaCoeffs_rg = [0.03,0,-0.005,0];
296 |
297 | % Use a dummy color sensor to pass through all channels, cf dummy bayer sensor
298 | camodel.sensorModel = DummyColorSensor(size(scene));
299 | camodel.pipelineModel = DummyPipeline();
300 |
301 | % Note: exposure time argument is not actually used by a DummySensor
302 | simulated = camodel.simulate_exposure(scene,1);
303 |
304 | figure,imshow(simulated)
305 |
306 |
307 |
308 |
309 |
310 |
311 |
--------------------------------------------------------------------------------
/gpl-3.0.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------