Converting complex figure to a variable on a system without display

1 visualizzazione (ultimi 30 giorni)
Hi,
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');
colorbar('East','Color','white');
MyBox = uicontrol('style','text','FontSize',16);
set(MyBox,'String','Hello World!');
xpos = 0.05; ypos = 0; xsize = 0.3; ysize = 0.15;
set(MyBox,'Units','normalized','Position',xpos,ypos,xsize,ysize]);
set(h,'InvertHardcopy','off');
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
dicomwrite(f.cdata,filename);
%% OR saveas(h, filename, extention) % Adds borders and changes resolution.
f.cdata = imread(filename);
dicomwrite(f.cdata,filename);

Risposte (0)

Categorie

Scopri di più su Printing and Saving in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by