阿齐兹的PyCV学习笔记——匹配地理标记图像
2018-03-08 13:32
483 查看
匹配地理标记图像
在imlist和featlist列表中保存图像文件名,对所有组合图像进行逐个匹配,并将每对图像间的匹配特征数保存在matchscores矩阵中:import sift nbr_images = len(imlist) matchscores = zeros((nbr_images,nbr_images)) for i in range(nbr_images): for j in range(i,nbr_images): #仅仅计算上三角 print 'comparing ', imlist[i], imlist[j] l1,d1 = sift.read_features_from_file(featlist[i]) l2,d2 = sift.read_features_from_file(featlist[j]) matches = sift.match_twosided(d1,d2) nbr_matches = sum(matches>0) print 'number of matches = ', nbr_matches matchscores[i,j] = nbr_matches #复制值 for i in range(nbr_images): for j in range(i+1,nbr_images): #不需要复制对角线 matchscores[j,i] = matchscores[i,j]
[pydot][7]工具包是功能强大的[GraphViz][8]图形库的Python接口,使用pydot创建一个图:
import pydot g = pydot.Dot(graph_type='graph') g.add_node(pydot.Node(str(0),fontcolor='transparent')) for i in range(5): g.add_node(pydot.Node(str(i+1))) g.add_edge(pydot.Edge(str(0),str(i+1))) for j in range(5): g.add_node(pydot.Node(str(j+1)+'-'+str(i+1))) g.add_edge(pydot.Edge(str(j+1)+'-'+str(i+1),str(j+1))) g.write_png('graph.png',prog='neato')
效果图:
使用pydot可视化地连接匹配的图像,为了得到图像需要使用图像的全路径,为了使图像更美观将每幅图像尺度化为缩略图形式:
import pydot threshold = 2 #创建关联需要的最小匹配数目 g = pydot.Dot(graph_type='graph') #不使用默认的有向图 for i in range(nbr_images): for j in range(i+1,nbr_images): if matchscores[i,j] > threshold: #图像对中的第一幅图像 im = Image.open(imlist[i]) im.thumbnail((100,100)) filename = str(i)+'.png' im.save(filename) #需要一定大小的临时文件 g.add_node(pydot.Node(str(i),fontcolor='transparent',shape='rectangle',image=path+filename)) #图像对中的第二幅图像 im = Image.open(imlist[j]) im.thumbnail((100,100)) filename = str(j)+'.png' im.save(filename) #需要一定大小的临时文件 g.add_node(pydot.Node(str(j),fontcolor='transparent',shape='rectangle',image=path+filename)) g.add_edge(pydot.Edge(str(i),str(j))) g.write_png('whitehouse.png')
相关文章推荐
- 阿齐兹的PyCV学习笔记——图像去噪
- 阿齐兹的PyCV学习笔记——SciPy
- Python OpenCV学习笔记之:图像模板匹配
- Matlab图像处理学习笔记(三):基于匹配的目标识别
- HTML学习笔记:图像标记
- Matlab图像处理学习笔记(三):基于匹配的目标识别
- Matlab图像处理学习笔记(三):基于匹配的目标识别
- 阿齐兹的PyCV学习笔记——PIL、Matplotlib
- 阿齐兹的PyCV学习笔记——SIFT(尺度不变特征变换)
- 阿齐兹的PyCV学习笔记——Harris角点检测器
- OpenCV学习笔记(四):ROI区域图像叠加和图像线性混合
- opencv学习笔记(2017年8月21日)之图像腐蚀操作
- scala学习笔记07--样本类(case class)和模式匹配
- opencv学习笔记1:矩阵和图像基本操作
- MATLAB图像处理学习笔记之一
- 《数字图像处理》冈萨雷斯学习笔记4:图像复原
- 【图像处理笔记】直方图匹配(规定化)
- 【学习笔记】〖九度OJ〗题目1153:括号匹配问题
- PHP学习笔记1. PHP的标记风格与注释
- ios学习笔记:利用sizeclass匹配不同设备