[3D Matlab] Save Stereo 3D image

  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'
  6. %clc;clear all;close all
  7. % [X,Y] = meshgrid(-8:.5:8);
  8. % R = sqrt(X.^2 + Y.^2) + eps;
  9. % Z = sin(R)./R;
  10. %
  11. % surf(X,Y,Z,'EdgeColor','none')
  12. % shading interp
  13. % camlight left; lighting phong
  14. % colormap jet
  15. % alpha(.4)
  16. %Make the left image
  17. axis off
  18. pos = get(gcf,'Position');
  19. [az,el] = view;
  20. pause(.5) %Take time to open
  21. I_L= getframe(gcf,[0 0 pos(3) pos(4)]);
  22. view(az-5,el)
  23. %Make the right image
  24. pos = get(gcf,'Position');
  25. pause(.5) %Take time to open
  26. I_R= getframe(gcf,[0 0 pos(3) pos(4)]);
  27. %Paste the two images together
  28. im_stereo=[I_L.cdata I_R.cdata];
  29. %And save as [.JPS] format
  30. imwrite(im_stereo,'image.jps','jpg','Quality',100)
  31. pause(.5) %Take time to write
  32. 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. ]]>

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