zoukankan      html  css  js  c++  java
  • matlab保存画框图像去白边

    在matlab图像处理中,为了标识出图像的目标区域来,需要利用plot函数或者rectangle函数,这样标识目标后,就保存图像。

    一般saves保存的图像存在白边,可以采用imwrite对图像进行保存,保留原始图像大小。

    代码如下:

        set(gca,'units','pixels','Visible','off');
        axes('position', [0 0 1.0 1.0]);
        [rows cols]=size(img);
        imshow(img);
        hold on
         s = regionprops(logicmap);
          for r = 1:length(s)   
               plot(s(r).Centroid(:,1), s(r).Centroid(:,2), 'r*')
               rectangle('Position',s(r).BoundingBox,'EdgeColor','r');
           end
         frame=getframe(gcf,[0,0,cols,rows]);
         im=frame2im(frame);
         imwrite(im,'a.jpg','jpg');%可以修改保存的格式

    保存结果如下:

    附加:在matlab2012,win7情况下,上述保存图像的方法还是会存在白边,

    可采用如下方法设置figure与图像一致,图像能填充显示窗口,并进行画框保存。

    % 显示
    set
    (gcf,'Position',[400,400,cols,rows]); %设置figure位置和大小
    imshow(videoclip(:,:,nrames),
    'border','tight','initialmagnification','fit'); %图像填充figure axis normal;
    % 保存
    frame=getframe(gcf,[0,0,cols,rows]);
    im=frame2im(frame);
    imwrite(im,outdir);
  • 相关阅读:
    Centos Another app is currently holding the yum lock
    Centos 重置密码
    Effective c#学习笔记(1)
    浅谈计算机编码
    mongodb java spring data
    VS2013 好用的插件
    xml存储bug
    VS 2008 生成操作中各个选项的差别
    程序权限控制
    给钛度产品的一些建议(Note)
  • 原文地址:https://www.cnblogs.com/yingying0907/p/3209138.html
Copyright © 2011-2022 走看看