Help with imwrite() transparency values

9 views (last 30 days)
David
David on 13 Nov 2013
Hello,
Thank you for the help. Im sure this might be an easy fix for someone more advanced with Matlab.
Heres the jist:
I'm saving png files during each iteration of a loop (later I will make the images into a movie). The tricky part is that I'm running this on the cluster at the university, so I can't actually render the figures, which limits my options. As a work around I'm using this code to save the image
fig=figure('visible','off');
[code that makes the figure]
filename = sprintf('/img%d.png', frame) ;
whereto = [directory filename];
cdata = zbuffer_cdata(fig)
imwrite(cdata,whereto);
with
function cdata = zbuffer_cdata(hfig)
% Need to have PaperPositionMode be auto
orig_mode = get(hfig, 'PaperPositionMode');
set(hfig, 'PaperPositionMode', 'auto');
cdata = hardcopy(hfig, '-dopengl', '-r96');
% Restore figure to original state
set(hfig, 'PaperPositionMode', orig_mode);
end
This does almost everything I need it to. It saves the figure as a png and names the files correctly.
The problem is that the figures are a plot of numerous spheres and each sphere has different FaceAlpha and EdgeAlpha values (i'm basically using the sphere() function). When I plot it (locally, where I can actually render the figure) It looks fine and the transparency is correct. However, when I save it like this ALL of the spheres are opaque and have the same transparency.
I think that I'm losing some of the data from the colormap or something, but I'm not sure how to fix it. I can't find this in a forum anywhere either.
Thanks for the help if you can provide it!
David

Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!