Converting complex figure to a variable on a system without display

1 view (last 30 days)
I need to convert a figure which has images, colorbars, and text "as is" to a variable (to then save it as a dicom secondary capture). The code is intended for a system without display capabilities. I have found partial answers but none seem to get me all the way there. Even if visibility is set to off, the getframe function displays the figure. The saveas function saves out a border, although if I display the figure, the borders are correctly tight. Saveas also changes resolution. Can someone give a suggestion?
P.S.: As a separate point, colorbar colors have no effect in Matlab 2013b on linux, so my tick labels fade in with the black background. Many thanks, Bogdan
h = figure('Visible','off');
MyBox = uicontrol('style','text','FontSize',16);
set(MyBox,'String','Hello World!');
xpos = 0.05; ypos = 0; xsize = 0.3; ysize = 0.15;
set(gca,'position',[0 0 1 1],'units','normalized')
% OR -> iptsetpref('ImshowBorder','tight');
% OR -> set(gca,'LooseInset',get(gca,'TightInset'));
f.cdata = getframe(h); % Does display figure before getting frame. Not working on the system without display
%% OR saveas(h, filename, extention) % Adds borders and changes resolution.
f.cdata = imread(filename);

Answers (0)


Find more on Printing and Saving 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!