Skip to content
Snippets Groups Projects
Commit 50859f3a authored by Henryk Krzysztof Blasinski's avatar Henryk Krzysztof Blasinski
Browse files

Merge branch 'cloud' of https://github.com/RenderToolbox/RenderToolbox4 into cloud

parents 94200b8b 7a25df60
No related branches found
No related tags found
No related merge requests found
......@@ -73,7 +73,7 @@ if isempty(outPath)
'hints', hints);
end
SRGBMontage = [];
% SRGBMontage = [];
XYZMontage = [];
%% Pick the montage dimensions.
......
function outputXYZCalFormat = BasicToneMapCalFormat(inputXYZCalFormat, maxLum)
% outputXYZCalFormat = BasicToneMapCalFormat(inputXYZCalFormat, maxLum)
%
% Simple tone mapping. Leaves any pixel with luminance below maxLum alone.
% For pixels whose luminance exceeds maxLum, scale XYZ down multiplicatively so
% that luminance is maxLum.
%
% 10/1/09 bjh, dhb Created it.
% 10/4/09 dhb Debug and make it work right.
% Find offending pixels
index = find(inputXYZCalFormat(2,:) > maxLum);
% If any pixel exceeds maxLum, scale it by 1/Y. Uses
% MATLAB's indexing trick of repeating an index to replicate
% values.
outputXYZCalFormat = inputXYZCalFormat;
if (~isempty(index))
outputXYZCalFormat(:, index) = maxLum*(inputXYZCalFormat(:, index)./inputXYZCalFormat([2 2 2]', index));
end
end
function image = CalFormatToImage(calFormat,nX,nY)
% image = CalFormatToImage(calFormat,nX,nY)
%
% Convert a calibration format image back to a real
% image.
%
% Note that the order nX,nY makes sense for thinking about images
% in terms of x and y coordinates, but that the order is backwards
% from the MATLAB convention of row dim then column dim.
%
% See also ImageToCalFormat
%
% 8/04/04 dhb Wrote it.
% 9/1/09 dhb Update help.
% 10/2/09 dhb Try again on making help clear.
k = size(calFormat,1);
image = reshape(calFormat',nY,nX,k);
function [calFormat,nX,nY] = ImageToCalFormat(image)
% [calFormat,nX,nY] = ImageToCalFormat(image)
%
% Take an nX (col dimension) by nY (row dimension) by k image
% and convert it to a format that may be used to Psychtoolbox
% calibration routines.
%
% Note that the order nX,nY makes sense for thinking about images
% in terms of x and y coordinates, but that the order is backwards
% from the MATLAB convention of row dim then column dim.
%
% See also CalFormatToImage
%
% 8/04/04 dhb Wrote it.
% 7/16/07 dhb Update help line.
% 10/2/09 dhb Try again on making help clear.
[nY,nX,k] = size(image);
if nY*nX == 1
calFormat = squeeze(reshape(image,nY*nX,1,k));
else
calFormat = squeeze(reshape(image,nY*nX,1,k))';
end
function RGB = SRGBGammaCorrect(rgb,SCALE)
% RGB = SRGBGammaCorrect(rgb,[SCALE])
%
% Gamma correct according to sRGB standard.
%
% SCALE = 0: No scaling applied to input rgb. Input values > 1 truncated to 1.
% SCALE = 1: Input data scaled to max of 1. (Default).
%
% Input values less than 0 are truncated to zero.
%
% The gamma correction stage of the SRGB standard converts inputs in the
% range [0,1] into gamma corrected output in the same range.
%
% This routine then multiplies the [0,1] output by 255 and quantizes
% to integer values. None-the-less, it still returns the output as
% a double (rather than uint8) matrix. I (DHB) am not sure this was
% a good design decision, but am for now (6/15/11) leaving it as is
% to avoid breaking code that relies on the current implementation.
% [Smarter, I think would have been to return values in the [0,1] range
% and leave the quantization to the caller, or else to convert to uint8
% after scaling into [0,255].]
%
% See XYZToSRGBPrimary for comment on evolution of the standard
% and of this implementation.
%
% 5/1/04 dhb Wrote it.
% 7/8/10 dhb Updated to match standard I can now find on the web.
% 6/15/11 dhb, ms Clarify input output range issues in comment.
% Set SCALE if not passed.
if (nargin < 2 || isempty(SCALE))
SCALE = 1;
end
% Scale into range, or truncate to 1.
if (SCALE)
rgb = rgb/max(rgb(:));
else
index = find(rgb > 1);
if (~isempty(index))
rgb(index) = 1;
end
end
% Truncate negative values to 0.
index = find(rgb < 0);
if (~isempty(index))
rgb(index) = 0;
end
% Cutoff value
% Value in old routines was 0.0031308, which I actually think
% was wrong even for the old standard. It should have been
% 0.00405 for the old standard.
cutoff = 0.00304;
% Apply sRGB gamma correction according to formulae
rgbprime = rgb;
index = find(rgb < cutoff);
if (~isempty(index))
rgbprime(index) = 12.92*rgb(index);
end
index = find(rgb >= cutoff);
if (~isempty(index))
rgbprime(index) = 1.055*(rgb(index).^(1/2.4))-0.055;
end
clear rgb;
% Quantize to 8 bits.
RGB = round(255*rgbprime);
File added
function [rgb,M] = XYZToSRGBPrimary(XYZ)
% [rgb,M] = XYZToSRGBPrimary(XYZ)
%
% Convert between CIE XYZ to sRGB primary
% coordinates. These are linear device
% coordinates for the primaries of the sRGB
% standard. If your input is scaled in the
% gamut of the monitor, the numbers will come
% out in the range 0-1. You may want to scale
% the result into the range 0-1 before applying
% sRGB gamma correction.
%
% Originally implemented from conversion matrix as specified at:
% http://www.srgb.com/basicsofsrgb.htm
% It turns out this was the draft standard. The site above is gone
% You can still find the draft standard at:
% http://www.colour.org/tc8-05/Docs/colorspace/61966-2-1.pdf
%
% I can't find the official technical standard on the web, but
% there is pretty good agreement across web sources. Wikipedia
% seems fine, as does.
% http://www.w3.org/Graphics/Color/sRGB
%
% 5/1/04 dhb Wrote it.
% 7/8/10 dhb Updated to match standard I can now find on the web.
% Define the transformation matrix. Now matching what's at w3.org. The
% old matrix is commented out in the second line.
M = [3.2410 -1.5374 -0.4986 ; -0.9692 1.8760 0.0416 ; 0.0556 -0.2040 1.0570];
%M = [3.2406 -1.5372 -0.4986 ; -0.9689 1.8758 0.0415 ; 0.0557 -0.2040 1.0570];
% Do the transform
if (~isempty(XYZ))
rgb = M*XYZ;
else
rgb = [];
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment