# [3D Matlab] Save Stereo 3D image

So if you happen to have a stereo-vision enabled computer, you’d like to look at some 3D stuff. Particularly interesting is of course your own data. Matlab is easy for data processing and making some fast and pretty plots.

So i have a 120Hz screen and the NVIDIA 3D vision glasses as in the picture above.

So lets say you run Matlab, and you have your 3D figure open. Then just run the below function and it saves a .JPS file automatically. JPS is just a stereo jpeg file, so now you can view your Matlab renders with your 3D glasses!

`function makesbs`

`%[Creative Commons]`

`%Tim Zaman 2012 [http://www.timzaman.com/]`

`%If you have a 3D figure open in a Matlab window,`

`% just run this file and it will save the 3D image as 'image.jps'`

`%clc;clear all;close all`

`% [X,Y] = meshgrid(-8:.5:8);`

`% R = sqrt(X.^2 + Y.^2) + eps;`

`% Z = sin(R)./R;`

`%`

`% surf(X,Y,Z,'EdgeColor','none')`

`% shading interp`

`% camlight left; lighting phong`

`% colormap jet`

`% alpha(.4)`

`%Make the left image`

`axis off`

pos = get(gcf,'Position');

[az,el] = view;

pause(.5) %Take time to open

I_L= getframe(gcf,[0 0 pos(3) pos(4)]);

view(az-5,el)

`%Make the right image`

pos = get(gcf,'Position');

pause(.5) %Take time to open

I_R= getframe(gcf,[0 0 pos(3) pos(4)]);

`%Paste the two images together`

im_stereo=[I_L.cdata I_R.cdata];

`%And save as [.JPS] format`

imwrite(im_stereo,'image.jps','jpg','Quality',100)

pause(.5) %Take time to write

disp('Done and written as image.jps')

It’s as simple as that! You can obviously tune some stuff in the function, but i particularly liked these settings like this. If you’re smart you can even make a nice stereo-3D video in the same fashion for multiple frames.

## 2 Responses

[…] I recently came across some Matlab code to output a 3D graph as a stereoscopic left/right .JPS file, viewable e.g. with 3D Media Viewer, Stereoscopic Player or using any 3D television or beamer: http://www.timzaman.com/2012/03/3d-matlab-save-stereo-3d-image/ […]

[…] [3D Matlab] Save Stereo 3D image […]