standalone executable to run on virtual Windows server and save figure plot to .png file
Mostrar comentarios más antiguos
I have written a m file which processes and displays an image to a figure window and then saves the figure to a png file.
I compiled it to a standalone excutable and it runs fine on my PC where I devloped it.
When I run this on run on virtual Windows server (the deployment target) it does not run, it just hangs
The function doing this part is (and it all works fine on server if I don't call this):
function displayROIs(I,iminfo)
% cfig=figure('visible','off')
imshow(I);
hold on;
axis on;
% drawnow;
[filepath,filename,ext] = fileparts(iminfo.Filename);
expFilename=strcat(filepath,'\',filename,' CNR.','png');
%exportgraphics(cfig,expFilename)
saveas(cfig,expFilename)
end
thanks for any help offered.
4 comentarios
Walter Roberson
el 30 de Sept. de 2025
I suggest experrimenting with
function displayROIs(I,iminfo)
cfig = figure('visible','off')
ax = gca(cfig);
imshow(ax, I);
hold(ax, 'on');
axis(ax, 'on');
% drawnow;
[filepath,filename,ext] = fileparts(iminfo.Filename);
expFilename=strcat(filepath,'\',filename,' CNR.','png');
%exportgraphics(cfig,expFilename)
saveas(cfig,expFilename)
end
Nick Gibson
el 1 de Oct. de 2025
Spoorthy Kannur
el 11 de Nov. de 2025
Hi Nick,
It appears that the executable hangs because graphics commands like “figure”, “imshow”, and “gca” require a graphical display, which might not be available on your virtual Windows Server. In headless environments, such calls can hang or fail silently.
You can try the following workarounds:
- Avoid creating a visible figure. Instead, render directly to an offscreen image using “imwrite” or “exportgraphics” on a “uifigure” created with 'Visible','off'.
- Alternatively, use the “figure('Visible','off')” approach but ensure the MCR has access to an OpenGL software renderer (you can set “opengl('save','software'”) before compiling). (https://www.mathworks.com/matlabcentral/answers/43326-create-figure-without-displaying-it.html)
- If the server runs without GUI support, try using “getframe” or “imwrite” to save the processed image instead of relying on “imshow + saveas”. Something like this:
- If this still hangs, it likely confirms the environment lacks GUI capabilities. In that case, consider running MATLAB or the executable on a machine with graphical support or through a remote desktop session that provides a display context (https://www.mathworks.com/matlabcentral/answers/44860-save-figure-on-a-server-machine-with-no-display.html)
If this does resolve the issue, kindly reach out to MathWorks Technical Support for more help (https://www.mathworks.com/support/contact_us.html)
Nick Gibson
el 11 de Nov. de 2025
Respuestas (0)
Categorías
Más información sobre MATLAB Compiler en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!