轮廓改进程度量化

function measure_distance_1 (a)
%groundTruth修改程度的测量(以原始gT为基准)
%测量方法是计算有改动的原groundTruth中每一个坐标点与距其最近的改动后坐标之距离,并将此距离求和。
%输入为一个数字,为图像的索引(名称标号)。示例输入:measure_distance_1(8048).


    global pic;
    global pic1;
    global ori;
    global n;
    global m;
    ori = [-1,0;0,1;1,0;0,-1;-1,1;1,1;1,-1;-1,-1];%移动方向坐标,正方向在前,斜向在后;(一个改进思路:正方向和斜向设定权值)
    
    %载入精确化后的groundTruth
    patha = strcat('/home/hetianjian/matlab2010/R2010b/BSR/GroundTruth/',num2str(a),'.mat');
    load(patha)
    pic1 = groundTruth{1}.Boundaries;
    %载入BSDS500提供的原始groundTruth。罗灿修改了每个groundTruth中的一个,并且将其是哪个保存在details.txt中。
    pathb = strcat('/home/hetianjian/matlab2010/R2010b/BSR/bench/data/groundTruth/',num2str(a),'.mat');
    load(pathb);
    inputfile = fopen('details.txt','r');
	detail = fscanf(inputfile,'%d ',[2,101]);
    %在文件中找到罗灿是修改的哪个groundTruth
    gTindex = -1;
	for i = 1:101,
		if detail(1,i) == a,
           gTindex = detail(2,i);
           break;
        end
    end
    if gTindex == -1,%输入数据出现错误,
       fprintf('cannot find the groundTruth...');
       return;
    end
    pic2 = groundTruth{gTindex}.Boundaries;
    %pic1是精确化后的groundTruth,pic2是原始的groundTruth
    [n,m] = size(pic1);
    del_outer();%罗灿改动后的gT在图片四周会增加一圈,删除它
    pic = bitxor(pic1,pic2);
    pic1 = pic1 & pic;
    pic2 = pic2 & pic;
%     dlmwrite('pic.txt',[n,m],'-append','delimiter',' ','newline','unix');
%     dlmwrite('pic.txt',pic1,'-append','delimiter',' ','newline','unix');
%     dlmwrite('pic.txt',pic2,'-append','delimiter',' ','newline','unix');
    %计算修改程度
    sum = 0;
    for i = 1:n,
       for j = 1:m,
          if pic2(i,j) == 1,
             sum = sum + cal(i,j,pic1); 
          end
       end
    end
    fprintf('%d\n',sum);
    imshow(pic);
end

%删除罗灿改动后gT在四周出现的一圈标定
function del_outer(pic)
    global pic1;
    global n;
    global m;
    for i = 1:n,
       pic1(i,1) = 0;
       pic1(i,m) = 0;
    end
    for i = 2:m-1,
       pic1(1,i) = 0;
       pic1(n,i) = 0;
    end
end

%对每个基准点计算距离它最近的另一个gT中点的距离
function dis = cal(x,y,another_pic)
    global ori;
    for dis = 1:5,
       for i = 1:8,
           xx = x+ori(i,1)*dis;
           yy = y+ori(i,2)*dis;
           if check(xx,yy) && another_pic(xx,yy) == 1,
              fill_image(x,y,i,dis);
              return ; 
           end
       end
    end
end

%判断坐标是否在图像内
function check = check(x,y)
    global n;
    global m;
    if x<1||y<1||x>=n+1||y>=m+1
       check = 0;
    else
       check = 1;
    end
end


%将得出距离的路径描实
function fill_image(x,y,orient,dis)
    global pic;
    global ori;
    for i = 1:dis,
       pic(x+ori(orient,1)*i,y+ori(orient,2)*i) = 1; 
    end
end

你可能感兴趣的:(轮廓改进程度量化)