Matlab Win7 imwrite 写入tiff stack 出错

在win7,使用imwrite函数写入多张tiff图像的时候,经常会出现一个错误:

??? Error using ==> writetif at 100
Couldn’t open ‘file.tif’ for writing.
You may not have write permission.

原因是在win7里面,Windows程序管理器(Windows Explorer)在检测到文件改动之后,会lock文件,进行一些操作。此时,会出现权限问题。

解决办法:
(1)换个系统环境(例如win10)
(2)使用下面的程序来实现正确的写入(解决权限问题)

imwrite(ImStack(:,:,1),filename) %write the first image
tries = 10; %maximum number of interruptions
kk = 1;
   while kk < size(h.vol,3) && tries > 0
         kk = kk+1;

         try imwrite(ImStack(:,:,kk),filename,'WriteMode','append')
         catch e 
                if strcmp(e.identifier,'MATLAB:imagesci:imwrite:fileOpen')
                    pause(0.1) %Let Windows Explorer release the file
                    kk = kk-1; %Try again
                    tries = tries-1;
                    continue
                else
                    rethrow(e)
                end
          end

   end

参考链接
[1]https://cn.mathworks.com/matlabcentral/newsreader/view_thread/301697

[2]http://blogs.mathworks.com/steve/2010/11/09/the-mystery-of-the-failing-tiff-append-loop/

[3]https://cn.mathworks.com/matlabcentral/answers/98467-why-do-i-receive-a-couldn-t-open-file-for-writing-error-when-using-imwrite-on-matlab-7-8-r2009a

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值