How can I save a 3D rendering as a .fig?

28 views (last 30 days)
Amanda Lee
Amanda Lee on 28 Apr 2020
Edited: Ameer Hamza on 29 Apr 2020
Created a 3D rendering of z-stacked images using volshow (Image Processing Toolbox). Can save it as a .png but would like to save it in a way that would allow me to rotate it (as a 3D surface plot would), ideally a .fig. However saving as a .fig produces an empty file. I have tried using print, saveas, and savefig. All save an empty figure.
figure(1)
f = volshow(FullImage,'ScaleFactors', [2 2 30],'BackgroundColor',[0.4 0.65 0.83]); %works
fileName = 'myImg.fig';
savefig(gcf, fileName); %saves when extension is .png instead. for .fig, saves and produces an empty figure (all grey)

Answers (1)

Ameer Hamza
Ameer Hamza on 29 Apr 2020
Edited: Ameer Hamza on 29 Apr 2020
I tried a bit to save the volshow() object, but it appears that the savefig doesn't save it. In fact, the 3D volume matrix is not even stored in the volshow handle ('f' in your code). It seems that the simplest method is to save the 3D volume matrix 'FullImage' and create a new volshow object every time by loading the FullImage matrix.
However, If you still want that loading the variable automatically create the figure, Then you can do so by creating your own handle class with a transient property as shown here: https://www.mathworks.com/help/matlab/matlab_oop/regenerate-transient-objects.html. I have also modified it for the specific case of volshow.
First, create a file name myVolShow.m and save this code.
classdef myVolShow < handle
properties
volData
props
end
properties(Transient)
volShow
end
properties(Access = private)
volShowData
end
methods
function obj = myVolShow(data, varargin)
obj.volData = data;
obj.props = varargin;
setup(obj,data, varargin{:});
end
function set.volShowData(obj,V)
setup(obj, V, 'load');
end
function V = get.volShowData(obj)
V = obj.volData;
end
end
methods(Access = private)
function setup(obj, data, varargin)
if strcmp(varargin{1}, 'load')
obj.volShow = volshow(data, obj.props{:});
else
obj.volShow = volshow(data, varargin{:});
end
end
end
end
Then run following lines
f = myVolShow(FullImage,'ScaleFactors', [2 2 30],'BackgroundColor',[0.4 0.65 0.83]);
It will create a volshow figure. You can save it in a .mat file like this
save('myFileName', 'f');
and then load it load it with
load('myFileName', 'f');
or double clicking the file.

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!