function anaglyph()
%---------------------------------------
% 
% Author: Iari-Gabriel Marino, Ph.D., nonlinear optics
% University of Parma, Dept. of Physics, ITALY
% email address: iarigabriel.marino@fis.unipr.it
% Website: http://www.fis.unipr.it/raman/index2.htm
% Personal: http://www.fis.unipr.it/home/marino/
% November 2006; Last revision: 6-Nov-2006
% 
%------------- BEGIN CODE --------------

dpi    = 300;
uhel   = 1;

set(gcf, 'Color', [255, 255, 255]./255, 'InvertHardcopy', 'off');

[az, el] = view;

view(az - uhel, el);  
print(gcf, '-dpng', ['-r', num2str(dpi)], '-zbuffer', 'tmp_anaglyph1.png');
view(az + uhel, el);
print(gcf, '-dpng', ['-r', num2str(dpi)], '-zbuffer', 'tmp_anaglyph2.png');

view(az, el);

dx = imread('tmp_anaglyph1', 'png');
sx = imread('tmp_anaglyph2', 'png');

figH = figure(1234);
set(figH, 'Visible', 'off');
set(figH, 'userdata', 0);

origCVA = get(gca, 'CameraViewAngle');
set(gca, 'CameraViewAngle', origCVA - 1);

plotAnaglyph(dx, sx);

print(figH, '-dpng', ['-r', num2str(dpi)], '-zbuffer', 'anaglyph.png');

% -------------------------------------------------------
 
function plotAnaglyph(A, B);

r  = zeros(size(A));
gb = zeros(size(B));

r(:, :, 1)      = double(A(:, :, 1));
gb(:, :, 2 : 3) = double(B(:, :, 2 : 3));

image(uint8(r+gb));
axis equal
set(gca, 'YTickLabel', [])
set(gca, 'XTickLabel', [])
set(gca, 'XTick', [])
set(gca, 'YTick', [])
set(gca, 'Color', [0 0 0])
set(gcf, 'Color', [0 0 0])

%------------- END OF CODE --------------
