visboundaries/linewidth not rendering sharply when exporting figures

5 次查看(过去 30 天)
Hi everyone,
I am working with MATLAB to generate images that include segmentation lines (using visboundaries and viscircles) drawn over images. However, when I export these images (using saveas or print), the lines are not rendered sharply. Instead, they are much thicker. If I change the LineWidth to something like 0.5 a “halo”/outline effect appears around them. Interestingly, when I zoom into the figure manually within MATLAB and then export, the lines are much sharper.
I already tried a different export format, different dpi (max 1000) and changing the figure position to a higher zoom level.
Any idea on how to improve the export quality?
left: manually zoomed and exported; right: saved through script
figure;
imshow(dicomData, [], 'InitialMagnification', 'fit');
title(sprintf('segmentation %s', fileTitle), 'Interpreter', 'none');
hold on;
visboundaries(signalRoiMask, 'Color', 'g', 'LineWidth', 1);
visboundaries(lesionMask, 'Color', 'm', 'LineWidth', 1);
visboundaries(surroundingTissueMask, 'Color', 'r', 'LineWidth', 1);
visboundaries(phantomRoiMask, 'Color', 'b', 'LineWidth', 1);
viscircles(phantomCenter, phantomRadius, 'EdgeColor', 'c');
segmentationFile = fullfile(imageFolder, sprintf('segmentation_%s.png', fileTitle));
print('-dpng', segmentationFile, '-r600');

回答(1 个)

Ayush
Ayush 2024-9-14
Hi Yannick
Although I do not have access to your code but you can try out these steps to improve the quality of your exported images:
  • Use Vector Graphics: If possible, export your figure as a vector graphic (such as PDF or EPS) instead of a raster image like PNG.
print('-depsc', segmentationFile); % Use EPS for vector output
  • Adjust Figure Size: Before exporting, adjust the figure size to be larger. This can be done by setting the Position property of the figure:
set(gcf, 'Position', [100, 100, 1000, 800]); % Adjust the size as needed
exportgraphics(gcf, segmentationFile, 'Resolution', 600);
I hope this helps.
  1 个评论
Yannick Schröder
Yannick Schröder 2024-9-14
编辑:Yannick Schröder 2024-9-14
Thank you for your response!
That helped a lot.
Although I thought I tested it adjusting the figure size helps a little. And combined with exportgraphics works well so the lines look much better now. But the white edges are still there so the export quality doesnt seem to be the problem for that. Do you have any tips on how to remove/reduce those?
I tried eps but it didnt help. Also changing LineWidth did not improve the edges.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by