Saving image with Colorbar in high quality

23 次查看(过去 30 天)
Hi,
I want to save images with a colormap and a colorbar and use the following code below. The code saves a file, but the saved file has a large white frame and contains less pixels than if I display the images via imshow. Below is a comparison of the result of imshow vs. the saved image from the code. How can I save the image(s) in the same quality as seen via imshow?
imshow image:
saved image:
for n=1:length(out(1,1,:))
imshow(out(:,:,n)) %out is a stack containing all images, which are supposed to be saved
colormap parula
colorbar
caxis([0 color_scale]) %color_scale is some integer value, which was calculated previously
temp=getframe(gcf)
img=filename(5*n-4); %this line and the next 2 are for proper naming of the file
img2=split(img,'result of ');
img3=replace(img2,'.tif','.png');
fullfilename=fullfile(folder2,img3{2});
imwrite(temp.cdata,fullfilename)
clear temp
end
  3 个评论
Adam Danz
Adam Danz 2022-9-16
Have you tried expanding your axes to the size of your figure by setting the position property of your axes?
Malte Römer-Stumm
Malte Römer-Stumm 2022-9-19
I am not sure how to use figure in combination with imshow and getframe. In the examples, which I found, figure was used with some plot command. However if I use f=figure first and then load the imagedata in f, then f isn't a figure anymore and if I load the data first and then declare f as a figure the data is gone. Am I missing something?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Import, Export, and Conversion 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by