Converting complex figure to a variable on a system without display
조회 수: 1 (최근 30일)
이전 댓글 표시
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);
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Printing and Saving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!