visboundaries/linewidth not rendering sharply when exporting figures
Show older comments
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?

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');
Answers (1)
Ayush
on 14 Sep 2024
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
- Use exportgraphics: If you're using a newer version of MATLAB (R2020a), consider using exportgraphics. Refer to this documentation link: https://www.mathworks.com/help/matlab/ref/exportgraphics.html
exportgraphics(gcf, segmentationFile, 'Resolution', 600);
I hope this helps.
1 Comment
Categories
Find more on Object Analysis 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!
