zoukankan      html  css  js  c++  java
  • matlab 图像的保存

    • gcf:获取当前显示图像的句柄;
    • 默认 plot 的 position 是 [232 246 560 420]

    0. save

    >> A = randn(3, 4);
    >> B = 'hello world';
    
    >> save 'data.mat' A B               % 将多个对象保存进 data.mat 文件中
    >> save data A B                     % 两个保存语句是等价的;

    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');
  • 相关阅读:
    关于 No buffer space available (maximum connections reached?): connect 的处理
    Cron 表达式
    Hudson 打包部署到Was上特别慢
    JAVA jar 参数
    CentOS 6 UNEXPECTED INCONSISTENCY RUN fsck MANUALLY
    SSH 连接很慢
    解决libc.so.6: version `GLIBC_2.14' not found问题
    Maven 基本参数
    Shc 应用
    JAVA 关于JNI本地库加载
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9422116.html
Copyright © 2011-2022 走看看