• Matlab编程循环规避


    Matlab对于for循环的执行效率极低

    本人在实现计算rand error算法的时候得

    使用了4层for循环结果算了几天都没算完

    最后换了算法以后1s就出来结果了

    一开始使用的方法是:

    I1=imread(origlabel);
    I2=imread(predlabel);
    [L1,num1] = bwlabel(I1);
    [L2,num2] = bwlabel(I2);
    [h1,w1] = size(I1);
    [h2,w2] = size(I2);

    a=0;b=0;c=0;d=0;

    for i1=1:h1

      for j1=1:w1

        for i2=1:h2

          for j2=1:w2

            if(L1(i1,j1)==L1(i2,j2)&&L2(i1,j1)==L2(i2,j2))

            a=a+1;

            end

            if(L1(i1,j1)~=L1(i2,j2)&&L2(i1,j1)~=L2(i2,j2))

            b=b+1;

            end

          end

        end

      end

    end

    n=h1*w1;

    t=0.5*n*(n-1);

    rand=(a+b)/t;

    rand_error=1-rand                   

    计算方法如下:

    I1=imread(origlabel);
    I2=imread(predlabel);
    [L1,num1] = bwlabel(I1);
    [L2,num2] = bwlabel(I2);
    [h1,w1] = size(I1);
    [h2,w2] = size(I2);
    % ind1=find(L1==0);
    % L1(ind2)=num1+1;
    % ind2=find(L2==0);
    % L1(ind2)=num2+1;
    n=h1*w1
    count=zeros(num1,num2);
    if(h1==h2&&w1==w2)
    for p=1:n
    if(L1(p)~=0&&L2(p)~=0)
    count(L1(p),L2(p))=count(L1(p),L2(p))+1;
    end
    end
    else
    return
    end
    row=sum(count,1);
    col=sum(count,2);
    row_s=sum(row.^2);
    col_s=sum(col.^2);
    t3=0.5*(row_s+col_s)
    t2=sum(sum(count.*count))
    t1=0.5*n*(n-1)
    rand=(t1+t2-t3)/t1;
    rand_error=1-rand

  • 相关阅读:
    special word count
    Regular Expression
    position 之 fixed vs sticky
    查看linux并发连接数的方法
    Linux/Unix环境下的make命令详解(转)
    Redis数据结构(转)
    maven中依懒scope说明
    mysql主从复制
    linux查看是否已经安装某个软件
    在mac下使用py2app打包python项目
  • 原文地址:https://www.cnblogs.com/Erdos001/p/4806201.html
Copyright © 2020-2023  润新知