[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!

  1. function makesbs
  2. %[Creative Commons]
  3. %Tim Zaman 2012 [http://www.timzaman.com/]
  4. %If you have a 3D figure open in a Matlab window,
  5. % just run this file and it will save the 3D image as 'image.jps'
  7. %clc;clear all;close all
  8. % [X,Y] = meshgrid(-8:.5:8);
  9. % R = sqrt(X.^2 + Y.^2) + eps;
  10. % Z = sin(R)./R;
  11. %
  12. % surf(X,Y,Z,'EdgeColor','none')
  13. % shading interp
  14. % camlight left; lighting phong
  15. % colormap jet
  16. % alpha(.4)
  18. %Make the left image
  19. axis off
  20. pos = get(gcf,'Position');
  21. [az,el] = view;
  22. pause(.5) %Take time to open
  23. I_L= getframe(gcf,[0 0 pos(3) pos(4)]);
  24. view(az-5,el)
  26. %Make the right image
  27. pos = get(gcf,'Position');
  28. pause(.5) %Take time to open
  29. I_R= getframe(gcf,[0 0 pos(3) pos(4)]);
  30. %Paste the two images together
  31. im_stereo=[I_L.cdata I_R.cdata];
  32. %And save as [.JPS] format
  33. imwrite(im_stereo,'image.jps','jpg','Quality',100)
  34. pause(.5) %Take time to write
  35. 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.

Tim Zaman

MSc Biorobotics. Specialization in computer vision and deep learning. Works at NVIDIA.

You may also like...

2 Responses

  1. June 19, 2015

    […] 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/ […]

  2. October 26, 2016

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