How to save image as pixel by pixel size and without white background

7 次查看(过去 30 天)
Hello, I would like to seek help for the image save as bmp.file with pixel by pixel size and without white background.
clear all; close all; clc
X = [-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150];
Y = [-150,-150,-150,-150,-150,-150,-150,-150,-150,-150,-150,-150,-150;-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125;-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100;-75,-75,-75,-75,-75,-75,-75,-75,-75,-75,-75,-75,-75;-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50;-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25;0,0,0,0,0,0,0,0,0,0,0,0,0;25,25,25,25,25,25,25,25,25,25,25,25,25;50,50,50,50,50,50,50,50,50,50,50,50,50;75,75,75,75,75,75,75,75,75,75,75,75,75;100,100,100,100,100,100,100,100,100,100,100,100,100;125,125,125,125,125,125,125,125,125,125,125,125,125;150,150,150,150,150,150,150,150,150,150,150,150,150];
r_M = [27,19,12,8,3,3,1,0,0,3,9,15,23;30,20,14,9,5,3,1,0,0,3,7,12,21;33,23,15,11,6,3,2,1,2,4,7,13,20;33,23,15,12,7,4,2,2,2,4,7,12,19;30,20,16,13,8,5,3,3,4,5,7,12,20;27,20,16,14,9,6,4,4,5,5,7,12,21;27,20,16,14,8,5,3,3,4,4,6,11,20;27,19,15,13,7,5,3,2,3,4,6,12,21;25,18,14,12,6,4,2,2,3,4,6,11,21;28,19,15,13,7,4,2,2,3,4,7,13,23;29,19,15,13,8,5,3,2,2,4,7,15,25;33,22,17,14,8,5,3,2,2,3,5,12,23;37,25,19,15,8,6,4,2,1,2,2,10,19];
figure(3)
contourf(X,Y,r_M,2560,'LineColor','none')
shading interp
axis square
% colorbar
% caxis([0 4])
colormap(flipud(gray(256)));
set(gca,'xtick',[])
set(gca,'ytick',[])
% %-------save compensation hologram-------
name = 'hologram';
fpath = 'C:\Users\Admin\Desktop';
saveas(gca, fullfile(fpath, name), 'bmp');

采纳的回答

DGM
DGM 2021-4-7
编辑:DGM 2021-4-7
Getting figures saved in a particular way is always a challenge, and the methods vary with versions. Personally, I just use export_fig()
set(gca,'units','pixels')
origpos=get(gca,'position');
origpos(3)=399; % 400-1
set(gca,'position',origpos)
outpict=export_fig('-a2','-m1');
This gives me a 400x400 close-cropped image, and should work so long as the figure window is big enough. You can just save the image as needed.
imwrite(outpict,'finallyworks.png')
  4 个评论
DGM
DGM 2021-4-7
编辑:DGM 2021-4-7
How did you unpack the zip file? I imagine one of two things happened. Either you didn't unpack all the files, or when you added them to the path, you didn't add all of them. It's usually more convenient to have them all together in a dedicated directory and then add that whole directory to the path.
You can check by:
which export_fig
which hyperlink
which isolate_axes
etc

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by