Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First commit from code online.

  • Loading branch information...
commit 389cac255be367f02a19ccc4539a5ef8076905ef 0 parents
Jean-Francois Lalonde authored
17 LICENSE.txt
@@ -0,0 +1,17 @@
+License for Non-Commercial Use
+
+If this software is redistributed, this license must be included. The term
+software includes any source files, documentation, executables, models,
+and data.
+
+This software is available for general use by academic or non-profit, or
+government-sponsored researchers. It may also be used for evaluation
+purposes elsewhere. This license does not grant the right to use this
+software or any derivation of it in a for-profit enterprise. For commercial
+use, please contact the Tech Transfer Office at Carnegie Mellon University.
+
+This software comes with no warranty or guarantee of any kind. By using
+this software, the user accepts full liability.
+
+This license is written by Jean-Francois Lalonde, Copyright 2010.
+
33 README.txt
@@ -0,0 +1,33 @@
+This is a high-level overview of the files available within this package. It is based on the Perez sky model [Perez et al., 1993]. For more information, please follow our IJCV 2009 paper available here:
+
+http://graphics.cs.cmu.edu/projects/sky/
+
+=== TEST FILE ===
+
+Use the file 'synthesizeSky.m' as a starting point.
+
+=== SKY MODEL ===
+
+These files synthesize the sky model based on camera parameters as inputs:
+- exactSkyModel.m: Synthesizes the full sky model;
+- exactGradientModel.m: Synthesizes only the "gradient" part of the sky model;
+- exactSunModel.m: Synthesizes only the "sun" part of the sky model.
+
+These files synthesize the sky model based on angles as inputs (Perez sky model):
+- perezSkyModel.m: Synthesizes the full sky model;
+- perezGradientModel.m: Synthesizes only the "gradient" part of the sky model;
+- perezSunModel.m: Synthesizes only the "sun" part of the sky model.
+
+Useful files that convert from pixel coordinates to angles:
+- pixelAzimuthAngle.m: Converts from pixels to azimuth angle;
+- pixelZenithAngle.m: Converts from pixels to zenith angle.
+
+=== TURBIDITY ===
+
+These files deal with converting the turbidity to the Perez weather coefficients (in 3 channels in xyY color space, as in [Preetham et al., 1999]):
+- convertTurbidityToSkyParams.m: Converts turbidity to the weather coefficients;
+- getTurbidityMapping.m: Returns the turbidity mapping between the weather coefficients in each channel.
+
+=== CHANGELOG ===
+
+09/21/11: Added missing file 'exactGradientModelRatio.m'. Thanks to A. Ravichandran for pointing this out!
31 convertTurbidityToSkyParams.m
@@ -0,0 +1,31 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% function skyParams = convertTurbidityToSkyParams(turbidity, k)
+% Converts turbidity to sky parameters. Also appends
+% the scale factors at the end, if given.
+%
+% Input parameters:
+% - turbidity
+% - [k]: scale factors for each channels
+%
+% Output parameters:
+% - skyParams: parameters (a,b,c,d,e), 6x3 (if k specified), 5x3 otherwise
+%
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function skyParams = convertTurbidityToSkyParams(turbidity, k)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Copyright 2006-2009 Jean-Francois Lalonde
+% Carnegie Mellon University
+% Do not distribute
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+if nargin > 1, nbParams = 6; else nbParams = 5; end
+
+skyParams = zeros(nbParams, 3);
+for ch=1:3
+ skyParams(1:5,ch) = getTurbidityMapping(ch)*[turbidity 1]';
+end
+
+if nargin > 1
+ skyParams(6,:) = k(:)';
+end
30 exactGradientModel.m
@@ -0,0 +1,30 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% function lum = exactGradientModel(a, b, f, up, vp, vh)
+% Synthesizes the sky gradient part only.
+%
+% Input parameters:
+% - a, b: Perez sky model parameters
+% - f: camera focal length (in pixels)
+% - up: x-coordinates of pixels in image
+% - vp: y-coordinates of pixels in image
+% - vh: horizon line (0 = center of image)
+%
+% Output parameters:
+% - lum: luminance map in image coordinates (same dimensions as up and vp)
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function lum = exactGradientModel(a, b, f, up, vp, vh)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Copyright 2006-2009 Jean-Francois Lalonde
+% Carnegie Mellon University
+% Do not distribute
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% convert to camera parameters
+thetac = pi/2+atan2(vh, f);
+fc = f;
+thetap = pixelZenithAngle(thetac, fc, up, vp);
+
+% plug in Perez sky model
+lum = perezGradientModel(a, b, thetap);
+
24 exactGradientModelRatio.m
@@ -0,0 +1,24 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% function lum = exactGradientModel(a, b, f, up, vp, vh)
+% Compute the ratio of luminance with respect to an arbitrary elevation
+%
+% Input parameters:
+% - a, b: Perez sky model parameters
+% - f: camera focal length (in pixels)
+% - up: x-coordinates of pixels in image
+% - vp: y-coordinates of pixels in image
+% - vh: horizon line (0 = center of image)
+%
+% Output parameters:
+% - lum: luminance map in image coordinates (same dimensions as up and vp)
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function ratio = exactGradientModelRatio(a, b, f, up, vp, vh, lz)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Copyright 2006-2009 Jean-Francois Lalonde
+% Carnegie Mellon University
+% Do not distribute
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+ratio = lz .* exactGradientModel(a, b, f, up, vp, vh) ./ perezGradientModel(a, b, 0);
28 exactSkyModel.m
@@ -0,0 +1,28 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% function lum = exactSkyModel(a, b, c, d, e, f, up, vp, vh, phi, phiSun, thetaSun)
+% Synthesizes the full sky model.
+%
+% Input parameters:
+% - a, b, c, d, e: Perez sky model parameters
+% - f: camera focal length (in pixels)
+% - up: x-coordinates of pixels in image
+% - vp: y-coordinates of pixels in image
+% - vh: horizon line (0 = center of image)
+% - phi: camera azimuth angle (in radians)
+% - phiSun: sun azimuth angle (in radians)
+% - thetaSun: sun zenith angle (in radians)
+%
+% Output parameters:
+% - lum: luminance map in image coordinates (same dimensions as up and up)
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function lum = exactSkyModel(a, b, c, d, e, f, up, vp, vh, phi, phiSun, thetaSun)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Copyright 2006-2009 Jean-Francois Lalonde
+% Carnegie Mellon University
+% Do not distribute
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% produce of sun and gradient luminance
+lum = exactGradientModel(a, b, f, up, vp, vh) .* exactSunModel(c, d, e, f, up, vp, vh, phi, phiSun, thetaSun);
+
28 exactSkyModelRatio.m
@@ -0,0 +1,28 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% function ratio = exactSkyModelRatio(a, b, c, d, e, f, up, vp, vh, lz, phi, phiSun, thetaSun)
+% Synthesizes the full sky model, based on ratios of luminances
+%
+% Input parameters:
+% - a, b, c, d, e: Perez sky model parameters
+% - f: camera focal length (in pixels)
+% - up: x-coordinates of pixels in image
+% - vp: y-coordinates of pixels in image
+% - vh: horizon line (0 = center of image)
+% - lz: zenith luminance
+% - phi: camera azimuth angle (in radians)
+% - phiSun: sun azimuth angle (in radians)
+% - thetaSun: sun zenith angle (in radians)
+%
+% Output parameters:
+% - ratio: ratio of luminances (with respect to zenith)
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function ratio = exactSkyModelRatio(a, b, c, d, e, f, up, vp, vh, lz, phi, phiSun, thetaSun)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Copyright 2006-2009 Jean-Francois Lalonde
+% Carnegie Mellon University
+% Do not distribute
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+ratio = lz .* exactSkyModel(a, b, c, d, e, f, up, vp, vh, phi, phiSun, thetaSun) ./ perezSkyModel(a, b, c, d, e, 0, thetaSun);
33 exactSunModel.m
@@ -0,0 +1,33 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% function lum = exactSunModel(c, d, e, f, up, vp, vh, phi, phiSun, thetaSun)
+% Synthesizes the sun contribution to the sky model
+%
+% Input parameters:
+% - c, d, e: Perez sky model parameters
+% - f: camera focal length (in pixels)
+% - up: x-coordinates of pixels in image
+% - vp: y-coordinates of pixels in image
+% - vh: horizon line (0 = center of image)
+% - phi: camera azimuth angle (in radians)
+% - phiSun: sun azimuth angle (in radians)
+% - thetaSun: sun zenith angle (in radians)
+%
+% Output parameters:
+% - lum: luminance map in image coordinates (same dimensions as up and up)
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function lum = exactSunModel(c, d, e, f, up, vp, vh, phi, phiSun, thetaSun)
+
+phic = phi;
+thetac = pi/2+atan2(vh, f);
+
+fc = f;
+thetap = pixelZenithAngle(thetac, fc, up, vp);
+phip = pixelAzimuthAngle(thetac, phic, fc, up, vp);
+
+deltaPhi = abs(phiSun - phip);
+gamma = acos(cos(thetaSun) .* cos(thetap) + sin(thetaSun) .* sin(thetap) .* cos(deltaPhi));
+
+% plug in Perez sky model
+lum = perezSunModel(c, d, e, gamma);
+
32 getTurbidityMapping.m
@@ -0,0 +1,32 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% function M = getTurbidityMapping(channelId)
+% Returns the turbidity mapping between turbidity and the constants
+% (a,b,c,d,e) from the Perez sky model. Taken from [Preetham et al., SISGGRAPH '99].
+%
+% Input parameters:
+% - channelId: [1,3] channel in the xyY space
+%
+% Output parameters:
+% - M: turbidity mapping. [a b c d e] = M*[T 1]'
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function M = getTurbidityMapping(channelId)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Copyright 2006-2009 Jean-Francois Lalonde
+% Carnegie Mellon University
+% Do not distribute
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+switch channelId
+ case 1 % x
+ M = [-0.0193 -0.2592; -0.0665 0.0008; -0.0004 0.2125; -0.0641 -0.8989; -0.0033 0.0452];
+
+ case 2 % y
+ M = [-0.0167 -0.2608; -0.0950 0.0092; -0.0079 0.2102; -0.0441 -1.6537; -0.0109 0.0529];
+
+ case 3 % Y
+ M = [0.1787 -1.4630; -0.3554 0.4275; -0.0227 5.3251; 0.1206 -2.5771; -0.0670 0.3703];
+
+ otherwise
+ error('input channelID must be between 1 and 3!');
+end
21 perezGradientModel.m
@@ -0,0 +1,21 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% function lum = perezGradientModel(a, b, theta)
+% Synthesizes the sky according to the Perez sky model, the
+% gradient-dependent part only.
+%
+% Input parameters:
+% - a, b: the 2 gradient-related weather coefficients
+% - theta: zenith angle of sky element
+%
+% Output parameters:
+% - lum: luminance map (same dimensions as theta)
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function lum = perezGradientModel(a, b, theta)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Copyright 2006-2009 Jean-Francois Lalonde
+% Carnegie Mellon University
+% Do not distribute
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+lum = 1 + a.*exp(b./cos(theta));
21 perezSkyModel.m
@@ -0,0 +1,21 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% function lum = perezSkyModel(a, b, c, d, e, theta, gamma)
+% Synthesizes the sky according to the Perez sky model.
+%
+% Input parameters:
+% - a, b, c, d, e: the 5 weather coefficients
+% - theta: zenith angle of sky element
+% - gamma: angular difference between sky element and sun
+%
+% Output parameters:
+% - lum: luminance map (same dimensions as theta, gamma)
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function lum = perezSkyModel(a, b, c, d, e, theta, gamma)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Copyright 2006-2009 Jean-Francois Lalonde
+% Carnegie Mellon University
+% Do not distribute
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+lum = perezGradientModel(a, b, theta) .* perezSunModel(c, d, e, gamma);
21 perezSunModel.m
@@ -0,0 +1,21 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% function lum = perezSunModel(c, d, e, theta, gamma)
+% Synthesizes the sun contribution to the sky model
+%
+% Input parameters:
+% - c, d, e: the 3 sun-related weather coefficients
+% - theta: zenith angle of sky element
+% - gamma: angular difference between sky element and sun
+%
+% Output parameters:
+% - lum: luminance map (same dimensions as theta, gamma)
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function lum = perezSunModel(c, d, e, gamma)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Copyright 2006-2009 Jean-Francois Lalonde
+% Carnegie Mellon University
+% Do not distribute
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+lum = 1 + c.*exp(d.*gamma) + e.*cos(gamma).^2;
23 pixelAzimuthAngle.m
@@ -0,0 +1,23 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% function phip = pixelAzimuthAngle(thetac, phic, fc, up, vp)
+% Converts pixel coordinates to azimuth angles.
+%
+% Input parameters:
+% - thetac: camera zenith angle (in radians)
+% - phic: camera azimuth angle (in radians)
+% - fc: camera focal length
+% - up: x-coordinates of pixels in image
+% - vp: y-coordinates of pixels in image
+%
+% Output parameters:
+% - phip: pixel azimuth angle
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function phip = pixelAzimuthAngle(thetac, phic, fc, up, vp)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Copyright 2006-2009 Jean-Francois Lalonde
+% Carnegie Mellon University
+% Do not distribute
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+phip = atan2((sin(phic).*sin(thetac).*fc-cos(phic).*up-sin(phic).*cos(thetac).*vp),(cos(phic).*sin(thetac).*fc+sin(phic).*up-cos(phic).*cos(thetac).*vp));
22 pixelZenithAngle.m
@@ -0,0 +1,22 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% function thetap = pixelZenithAngle(thetac, fc, up, vp)
+% Converts pixel coordinates to zenith angles.
+%
+% Input parameters:
+% - thetac: camera zenith angle (in radians)
+% - fc: camera focal length
+% - up: x-coordinates of pixels in image
+% - vp: y-coordinates of pixels in image
+%
+% Output parameters:
+% - thetap: pixel zenith angle
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function thetap = pixelZenithAngle(thetac, fc, up, vp)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Copyright 2006-2009 Jean-Francois Lalonde
+% Carnegie Mellon University
+% Do not distribute
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+thetap = acos((sin(thetac).*vp+cos(thetac).*fc)./(fc.^2+up.^2+vp.^2).^(1/2));
44 reconstructSkyFromFullModel.m
@@ -0,0 +1,44 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% function reconstructedImg = reconstructSkyFromFullModel(imgDims, params, vh, f, phiCam, thetaSun, phiSun)
+% Synthesizes the sky according to the input parameters.
+%
+% Input parameters:
+% - imgDims: dimensions of the output image [height width nbChannels]
+% - params: the weather coefficients (6xnbChannels, rows = a,b,c,d,e,k)
+% - vh: horizon line (where 0 = center of the image, pointing up)
+% - f: focal length of the camera
+% - phiCam: camera azimuth angle
+% - thetaSun: sun zenith angle
+% - phiSun: sun azimuth angle
+%
+% Output parameters:
+% - reconstructedImg: rendered sky (in the xyY color space)
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function reconstructedImg = reconstructSkyFromFullModel(imgDims, params, vh, f, phiCam, thetaSun, phiSun)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Copyright 2006-2009 Jean-Francois Lalonde
+% Carnegie Mellon University
+% Do not distribute
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+imgHeight = imgDims(1);
+imgWidth = imgDims(2);
+nbChannels = imgDims(3);
+
+[uRange, vRange] = meshgrid(1:imgWidth, 1:imgHeight);
+upVec = (uRange - imgWidth/2) - 0.5;
+vpVec = (imgHeight/2 - vRange) + 0.5;
+
+vhImg = floor(imgHeight/2 - vh + 0.5);
+
+% synthesize each channel
+reconstructedImg = zeros(imgHeight, imgWidth, nbChannels);
+for ch = 1:nbChannels
+ reconstructedImg(:,:,ch) = exactSkyModelRatio(params(1,ch), params(2,ch), params(3,ch), params(4,ch), params(5,ch), ...
+ f, upVec, vpVec, vh, params(6,ch), phiCam, phiSun, thetaSun);
+end
+
+% black out what's below the horizon
+reconstructedImg(vhImg:end,:,:) = 0;
+
182 setPath.m
@@ -0,0 +1,182 @@
+%% Path setup for the webcam sequence project
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Copyright 2007 Jean-Francois Lalonde
+% Carnegie Mellon University
+% Do not distribute
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+clear global;
+global logFileRoot;
+
+% host-dependent paths
+[a, host] = system('hostname');
+
+if (isdeployed || ~isempty(strfind(lower(host), 'cmu')) || ~isempty(strfind(lower(host), 'compute'))) && isempty(strfind(lower(host), 'jf-mac'))
+ % at CMU
+ codeBasePath = '/nfs/hn01/jlalonde/code';
+ basePath = '/nfs/hn25/jlalonde/results/webcamSequence';
+ dataBasePath = '/nfs/hn01/jlalonde/data';
+ logFileRoot = '/nfs/hn01/jlalonde/status/logs';
+else
+ % on my laptop
+ codeBasePath = '/Users/jflalonde/Documents/phd/code';
+ basePath = '/Users/jflalonde/Documents/phd/results/webcamSequence';
+ dataBasePath = '/Users/jflalonde/Documents/phd/data';
+ logFileRoot = '/Users/jflalonde/Documents/phd/data/logs';
+end
+
+statusBasePath = '/nfs/hn01/jlalonde/status/siggraphAsia09';
+
+path3rdParty = fullfile(codeBasePath, 'matlab/trunk/3rd_party');
+pathMyCode = fullfile(codeBasePath, 'matlab/trunk/mycode/');
+rootPath = fullfile(pathMyCode, 'webcamSequence');
+
+%% Turn off some annoying warnings
+warning off Images:initSize:adjustingMag;
+
+%% Initialize the random number generator (otherwise initialized to the same value each time!)
+randSeed = sum(100*clock) + sum(host);
+if ~isempty(strfind(version, '7.7'))
+ RandStream.setDefaultStream(RandStream('mt19937ar','seed', randSeed))
+else
+ rand('twister', randSeed);
+end
+
+if isdeployed
+ return;
+end
+
+% Restore to initial state
+restoredefaultpath;
+
+%% Setup mycode paths
+addpath(fullfile(pathMyCode, 'database'));
+addpath(fullfile(pathMyCode, 'database', 'commonProcessing'));
+addpath(fullfile(pathMyCode, 'histogram'));
+addpath(fullfile(pathMyCode, 'xml'));
+addpath(fullfile(pathMyCode, 'xml', 'load_xml'));
+addpath(fullfile(pathMyCode, 'html'));
+
+%% Setup util paths
+utilPath = fullfile(pathMyCode, 'util');
+addpath(utilPath);
+addpath(fullfile(utilPath, 'rendering'));
+addpath(fullfile(utilPath, 'labelme'));
+addpath(fullfile(utilPath, 'webcams'));
+
+%% Setup project paths
+addpath(rootPath);
+addpath(fullfile(rootPath, 'datasetCreation'));
+addpath(fullfile(rootPath, 'datasetSummary'));
+addpath(fullfile(rootPath, 'datasetProcessing'));
+addpath(fullfile(rootPath, 'datasetManagement'));
+addpath(fullfile(rootPath, 'visualization'));
+addpath(fullfile(rootPath, 'visualization', 'cameraParameters'));
+addpath(fullfile(rootPath, 'pca'));
+addpath(fullfile(rootPath, 'pca', 'canonicalDay'));
+addpath(fullfile(rootPath, 'illuminationContext'));
+addpath(fullfile(rootPath, 'learning'));
+addpath(fullfile(rootPath, 'sequenceAlignment'));
+addpath(fullfile(rootPath, 'skyLabeling'));
+addpath(fullfile(rootPath, 'skyModeling'));
+addpath(fullfile(rootPath, 'skyModeling', 'fitting'));
+addpath(fullfile(rootPath, 'skyModeling', 'fitting', 'luminance'));
+addpath(fullfile(rootPath, 'skyModeling', 'fitting', 'turbidity'));
+addpath(fullfile(rootPath, 'skyModeling', 'matching'));
+addpath(fullfile(rootPath, 'skyModeling', 'matchingTimeOfDay'));
+addpath(fullfile(rootPath, 'skyModeling', 'globalModel'));
+addpath(fullfile(rootPath, 'skyModeling', 'fullModel'));
+addpath(fullfile(rootPath, 'skyModeling', 'fullModel', 'fitting'));
+addpath(fullfile(rootPath, 'skyModeling', 'fullModel', 'matching'));
+addpath(fullfile(rootPath, 'skyModeling', 'fullModel', 'syntheticValidation'));
+addpath(fullfile(rootPath, 'skyModeling', 'fullModel', 'visualization'));
+addpath(fullfile(rootPath, 'skyModeling', 'skyModel'));
+addpath(fullfile(rootPath, 'radiometricCalibration'));
+addpath(fullfile(rootPath, 'radiometricCalibration', 'wildValidation'));
+addpath(fullfile(rootPath, 'cameraParameters'));
+addpath(fullfile(rootPath, 'cameraParameters', 'allParams'));
+addpath(fullfile(rootPath, 'skyCalibration'));
+addpath(fullfile(rootPath, 'groundTruth'));
+addpath(fullfile(rootPath, 'transformations'));
+addpath(fullfile(rootPath, 'transformations', 'singleImage'));
+addpath(fullfile(rootPath, 'util'));
+addpath(fullfile(rootPath, 'webcamClipart'));
+addpath(fullfile(rootPath, 'webcamRelighting'));
+addpath(fullfile(rootPath, 'siggraphScripts', 'danielle'));
+addpath(fullfile(rootPath, 'gpsCoordinates'));
+
+
+%% Setup 3rd party paths
+% vgg
+addpath(fullfile(path3rdParty, 'vgg_matlab'));
+addpath(fullfile(path3rdParty, 'vgg_matlab', 'vgg_numerics'));
+addpath(fullfile(path3rdParty, 'vgg_matlab', 'vgg_general'));
+addpath(fullfile(path3rdParty, 'vgg_matlab', 'vgg_image'));
+% Arguments parsing
+addpath(fullfile(path3rdParty, 'parseArgs'));
+% Color conversion
+addpath(fullfile(path3rdParty, 'color'));
+% Lightspeed
+addpath(fullfile(path3rdParty, 'lightspeed'));
+% Useful stuff
+addpath(fullfile(path3rdParty, 'util'));
+% SIFT
+addpath(fullfile(path3rdParty, 'sift'));
+% Isomap
+addpath(fullfile(path3rdParty, 'isomap'));
+% Click 3-D points
+addpath(fullfile(path3rdParty, 'click3DPoint'));
+% Better dijkstra (with paths)
+addpath(fullfile(path3rdParty, 'dijkstra'));
+% Sun position
+addpath(fullfile(path3rdParty, 'sunPosition'));
+% Intrinsic images
+addpath(fullfile(path3rdParty, 'intrinsicSequence'));
+% Poisson solver
+addpath(fullfile(path3rdParty, 'poisson'));
+% Berkeley code
+addpath(fullfile(path3rdParty, 'segmentationBerkeley', 'lib', 'matlab'));
+% Texture synthesis
+addpath(fullfile(path3rdParty, 'quilt'));
+% for GMM
+addpath(fullfile(path3rdParty, 'netlab'));
+% for simulated annealing
+addpath(fullfile(path3rdParty, 'anneal'));
+% emd
+addpath(fullfile(path3rdParty, 'emd'));
+% mapping
+addpath(fullfile(path3rdParty, 'mmap'));
+% progress bar
+addpath(fullfile(path3rdParty, 'progressbar'));
+% Peter Kovesi's functions
+addpath(fullfile(path3rdParty, 'pkovesi'));
+addpath(fullfile(path3rdParty, 'pkovesi', 'Robust'));
+addpath(fullfile(path3rdParty, 'pkovesi', 'Projective'));
+% Anat Levin's matting
+addpath(fullfile(path3rdParty, 'matting'));
+% O. Chapelle's svm code
+addpath(fullfile(path3rdParty, 'primal_svm'));
+% Anti-aliasing
+addpath(fullfile(path3rdParty, 'myaa'));
+% Laplacian pyramid code
+addpath(fullfile(path3rdParty, 'pyramidMatching'));
+addpath(fullfile(path3rdParty, 'pyramidMatching', 'MEX'));
+% incremental SVD
+addpath(fullfile(path3rdParty, 'svdUpdate'));
+% sunrise/sunset
+addpath(fullfile(path3rdParty, 'sunrise'));
+
+
+
+%% Setup geometric context paths
+appPath = fullfile(path3rdParty, 'geometricContext');
+addpath(appPath);
+addpath(fullfile(appPath, 'boosting'));
+addpath(fullfile(appPath, 'crf'));
+addpath(fullfile(appPath, 'geom'));
+addpath(fullfile(appPath, 'ijcv06'));
+addpath(fullfile(appPath, 'mcmc'));
+addpath(fullfile(appPath, 'textons'));
+addpath(fullfile(appPath, 'tools', 'drawing'));
+addpath(fullfile(appPath, 'tools', 'misc'));
+addpath(fullfile(appPath, 'tools', 'weightedstats'));
29 synthesizeSky.m
@@ -0,0 +1,29 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Example code which demonstrates the use of the sky model.
+%
+% Copyright 2006-2009 Jean-Francois Lalonde
+% Carnegie Mellon University
+% Do not distribute
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+imgDims = [480 640 3]; % 640x480 color image
+k = [0.2 0.2 0.05];
+skyParams = convertTurbidityToSkyParams(2.2, k); % t=2.2, clear sky
+vh = -100; % looking up
+f = 800; % focal length in pixels
+phiCam = 0; % facing north
+
+thetaSun = pi/2-(10*pi/180); % 10 degrees to horizon
+
+% synthesize the sky with the sun behind the camera
+phiSun = pi;
+skySunBehind = reconstructSkyFromFullModel(imgDims, skyParams, vh, f, phiCam, thetaSun, phiSun);
+
+% synthesize the sky with the sun in front of the camera
+phiSun = 0;
+skySunFront = reconstructSkyFromFullModel(imgDims, skyParams, vh, f, phiCam, thetaSun, phiSun);
+
+% display results
+figure;
+subplot(1,2,1), imshow(xyY2rgb(skySunBehind)), title('Sun behind');
+subplot(1,2,2), imshow(xyY2rgb(skySunFront)), title('Sun in front');
70 xyY2rgb.m
@@ -0,0 +1,70 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% function rgb = xyY2rgb(xyY, doClamp)
+% Converts an image in xyY format to the RGB format, as described in
+% http://en.wikipedia.org/wiki/CIE_1931_Color_Space
+%
+% Input parameters:
+% - xyY: input image (3 channels) in the xyY color space
+% - doClamp: 0 or [1], clamps the output in the [0,1] range. If not,
+% linearly extrapolates the values of rgb
+%
+% Output parameters:
+%
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function rgb = xyY2rgb(xyY, doClamp)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Copyright 2006-2009 Jean-Francois Lalonde
+% Carnegie Mellon University
+% Do not distribute
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% default value: clamp to the [0,1] interval
+if nargin == 1
+ doClamp = 1;
+end
+
+% first convert to XYZ
+x = xyY(:,:,1);
+y = xyY(:,:,2);
+Y = xyY(:,:,3);
+
+X = x.* Y./y;
+Z = Y./y - X - Y;
+
+% special case: completely black!
+indZero = (y == 0);
+X(indZero) = 0;
+Y(indZero) = 0;
+Z(indZero) = 0;
+
+xyz = cat(3, X, Y, Z);
+
+% then convert to rgb
+cTrans = makecform('xyz2srgb');
+
+if ~doClamp
+ mat = [cTrans.cdata.MatTRC.RedColorant;
+ cTrans.cdata.MatTRC.GreenColorant;
+ cTrans.cdata.MatTRC.BlueColorant];
+ rgb = reshape(xyz, size(x,1)*size(x,2), 3) * inv(mat);
+
+ % remove negative values
+ rgb = max(rgb, 0);
+
+ % "hallucinate" HDR by linearly extrapolating outside the [0,1] range
+ TRC = cell(1, 3);
+ TRC{1} = double(cTrans.cdata.MatTRC.RedTRC);
+ TRC{2} = double(cTrans.cdata.MatTRC.GreenTRC);
+ TRC{3} = double(cTrans.cdata.MatTRC.BlueTRC);
+ out = zeros(size(rgb));
+ for i = 1 : 3
+ out(:,i) = interp1(TRC{i}./max(TRC{i}), linspace(0,1,length(TRC{i})), rgb(:,i), 'linear', 'extrap');
+ end
+ rgb = reshape(out, size(x,1), size(x,2), 3);
+
+else
+ % applycform clamps in [0,1] interval and applies non-linearity from XYZ to RGB
+ rgb = applycform(xyz, cTrans);
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.