首页 > 学院 > 开发设计 > 正文

matlab 图像的保存

2019-11-06 08:27:31
字体:
来源:转载
供稿:网友
gcf:获取当前显示图像的句柄;默认 plot 的 position 是 [232 246 560 420]

1. imwrite、saveas、PRint

I = imread('./name.bmp');% process the image matrix I% ...imwrite(I, './new_name.bmp');

imwrite函数有两点需要注意的是:

保存的内容必须是uint8类型的,

无法很好地保存gcf对象 例如,我们需要对当前图像显示(imshow(I, []))添加一些文本信息(使用text(x, y, 'string')),或者一些特殊形状标识(使用rectangle('Position', [x, y, w, h], 'FaceColor', 'k')),imwrite是无法保存这些添加到figure之上的信息的,这时就需要使用saveas()方法,或者print()方法

saveas(gcf, './fig.tif');print(gcf, '-dtiff', '-r200', 'fig');% '-dtiff':表示文件格式% '-r200':分辨率% 'fig':文件名,

这种方法保存的图像文件,容易失真,当然也有一些属性的设置,具体的参考matlab 文档。

关于 print还存在一个简易的操作,直接对当前 figure,进行保存:

print -djpeg weights.jpg

2. subplots

保存某一个具体的 sub 子图;H = subplot(1,2,1);saveas(H,[pathname,filename],'jpg');

3. 去除白边

matlab保存figure中的图片去掉白边

imshow(I, 'border', 'tight', 'initialmagnification', 'fit');set (gcf, 'Position', [0,0,500,500]);axis normal;saveas(gca,'meanshape.bmp','bmp');

一个更为精简的形式为:

imshow(I, 'border', 'tight');axis normal;saveas(gca,'meanshape.bmp','bmp');
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表