Saving an imagesc file as .png without the white borders?

43 vues (au cours des 30 derniers jours)
spider_plantt
spider_plantt le 6 Août 2020
Modifié(e) : DGM le 1 Mai 2023
I want to save a series of images that output in the format 'matlab.graphics.primitive.image' as PNGs without that white border PNGs save with. My code is below--is there any way to output these images cropped of their white border? I've already tried setting my 'iptsetpref' as 'tight', to no avail.
clc;clear all;
load('sphere.mat');
for j=80:90
I=imagesc(squeeze(sphere(:,j,:)));
set(gca,'XTick',[]);
set(gca,'YTick',[]);
filename=sprintf('sphere%d',j);
saveas(I,filename,'png');
end

Réponses (2)

Sudheer Bhimireddy
Sudheer Bhimireddy le 6 Août 2020
Try:
print(I,filename,'-dpng');
By white border if you mean the background outside the figure, then you would have to export it to epsc format
print(I,filename,'-depsc');

DGM
DGM le 3 Août 2022
Modifié(e) : DGM le 1 Mai 2023
If you have an image and want to save the image, save the image. Don't display the image and then save a screenshot of the displayed image. Don't display the image and then take a photo of the monitor with your phone. Don't describe the image as a thousand words of poetry or as an interpretive dance.
Save the image array -- not the graphics object or the parent figure. Use imwrite(). Anything else is not just self-inflicted inconvenience; it's often destructive.
For saving arbitrarily-scaled data in scaled pseudocolor (as one would expect from imagesc()), See this example:
Again, this does not rely on figure capture.

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by