基于遥感影像的道路完整性与连接性评价指标

网友投稿 701 2022-11-23

基于遥感影像的道路完整性与连接性评价指标

基于遥感影像的道路完整性与连接性评价指标

前言

考虑到道路这一特殊地物的拓扑结构信息,本博文引入两个指标 Road Completeness 和 Road Connectivity 分别用于统计道路结果的完整性与连接性。

Road Completeness

import numpy as npimport skimagefrom skimage import morphologyimport cv2def thin_image(mask_dir, mask_file): im = cv2.imread(mask_dir + mask_file, 0) im = im > 128 selem = skimage.morphology.disk(2) im = skimage.morphology.binary_dilation(im, selem) im = skimage.morphology.thin(im) return im.astype(np.uint8) * 255mask_dir = 'E:/shao_xing/out/result_boost12345/'gt_dir = 'E:/shao_xing/test/lab/'region = 'd'mylogs = open('E:/shao_xing/out/tiny_evalog/new_metric/' + region + '_boost12345.log','w')ratio_list=[]for i in range(-4, 4): for j in range(-4, 4): gt_file = region + '_' + str(i) + '_' + str(j) + '_osm.png' mask_file = gt_file[:-7] + 'merge.png' mask = cv2.imread(mask_dir + mask_file, 0) thin_gt = thin_image(gt_dir, gt_file) num_mask = np.sum(thin_gt[mask > 128]) / 255 num_gt = np.sum(thin_gt) / 255 ratio = num_mask / (num_gt+0.00001) if num_gt != 0: ratio_list.append(ratio) print('test image ', str(i), '_', str(j), 'ratio:', round(ratio, 2), file=mylogs) print('test image ', str(i), '_', str(j), 'ratio:', round(ratio, 2))print('********************************', file=mylogs)print('Average Ratio:', round((sum(ratio_list) / len(ratio_list)), 2), file=mylogs)print('********************************')print('Average Ratio:', round((sum(ratio_list) / len(ratio_list)), 2))mylogs.close()

Road Connectivity

import syssys.path.append("./discoverlib")from discoverlib import geom, graphimport numpy as npimport cv2import skimagefrom skimage import morphology"""evaluate connectivity based on ground truth graphWe split the total graph into segments with length of around 20 pixelsThen, statistic the number of fully connected segments in segmentation masks.The connectivity ratio is the percentage of fully connected segments. """log_name = 'mask' # evaluation log filemask_dir = '~/data/out/mask/' # segmentation masks for evaluatingtotal_gt_number = 0total_connected_number = 0total_not_connected_number = 0total_pred_number = 0total_connected_length = 0total_gt_length = 0total_pred_length = 0mylog = open('~/data/out/eval_log/' + log_name + '_connect.log', 'w')region_name_list = [["amsterdam",-4,-4,4,4], ["chicago",-4,-4,4,4], ["denver",-4,-4,4,4]]for region_info in region_name_list: print("test region: "+region_info[0]) graph_name = '~/data/graph_gt/'+ region_info[0] + ".graph" # ground truth graph gt_graph = graph.read_graph(graph_name) edge_nodes=[] for i,edge in enumerate(gt_graph.edges): if i % 2 ==0: edge_nodes.append([edge.src.point.x,edge.src.point.y,edge.dst.point.x,edge.dst.point.y]) base_gt_mask=np.zeros((1024, 1024)) edge_nodes=np.array(edge_nodes) for i in range(region_info[1], region_info[3]): for j in range(region_info[2], region_info[4]): mask_file = region_info[0] + '_' + str(i) + '_' + str(j) + '_fusion.png' # print(mask_dir + mask_file) mask = cv2.imread(mask_dir + mask_file, 0)/255 patch_gt_number=0 patch_connected_number=0 patch_not_connected_number=0 patch_connected_length = 0 patch_gt_length = 0 offset=[-i*1024, -j*1024, -i*1024, -j*1024] patch_nodes=edge_nodes+offset for seg_edge in patch_nodes: if (seg_edge>=[0,0,0,0]).all() and (seg_edge<[1024,1024,1024,1024]).all(): base_gt_mask = np.zeros((1024, 1024)) patch_gt_number+=1 # number of segments on the ground-truth graph base_gt_mask=cv2.line(base_gt_mask,(seg_edge[0],seg_edge[1]),(seg_edge[2],seg_edge[3]),color=1, thickness=1) pred_seg_length=np.sum(mask[base_gt_mask>0]) gt_length=np.sum(base_gt_mask>0) patch_gt_length += gt_length if pred_seg_length < gt_length: patch_not_connected_number+=1 else: patch_connected_number+=1 patch_connected_length += gt_length else: pass im = (mask*255) > 128 selem = skimage.morphology.disk(2) im = skimage.morphology.binary_dilation(im, selem) im = skimage.morphology.thin(im) thin_mask = im.astype(np.uint8) * 255 patch_pred_length = np.sum(thin_mask > 0) patch_pred_number = patch_pred_length / 20.0 # number of segments on the prediction graph ratio = 2*patch_connected_length/(patch_gt_length+patch_pred_length+0.00001) print('test image {}_{} connected:not:total {}/{}/{}, ratio: {}'.format(i,j,patch_connected_number, patch_not_connected_number, patch_gt_number, round(ratio, 4))) print('test image {}_{} connected:not:total {}/{}/{}, ratio: {}'.format(i, j, patch_connected_number, patch_not_connected_number, patch_gt_number, round(ratio, 4)), file=mylog) total_gt_number += patch_gt_number total_connected_number += patch_connected_number total_not_connected_number += patch_not_connected_number total_pred_number += patch_pred_number total_connected_length += patch_connected_length total_gt_length += patch_gt_length total_pred_length += patch_pred_length# total_ratio = 2*total_connected_number/(total_gt_number+total_pred_number)total_ratio = 2*total_connected_length/(total_gt_length+total_pred_length)print('********************************')print("total connected:not:total {}/{}/{}, ratio: {}".format(total_connected_number, total_not_connected_number, total_gt_number, round(total_ratio, 4)))print("total_gt_length:{}".format(total_gt_length))print("average gt length:{}".format(total_gt_length/total_gt_number))print('********************************', file=mylog)print("total connected:not:total {}/{}/{}, ratio: {}".format(total_connected_number, total_not_connected_number, total_gt_number, round(total_ratio, 4)), file=mylog)print("total_gt_length:{}".format(total_gt_length),file=mylog)print("average gt length:{}".format(total_gt_length/total_gt_number),file=mylog)mylog.close()

参考

​​https://github.com/astro-ck/Road-Extraction​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:基于二值图的角点检测
下一篇:基于遥感影像的语义分割论文简读
相关文章

 发表评论

暂时没有评论,来抢沙发吧~