Fast Affine Template Matching over Galois Field

http://cvhost.scv.cis.iwate-u.ac.jp/research/projects/affine_matching.html

关于其数据:

http://cvhost.scv.cis.iwate-u.ac.jp/research/projects/benchmark.zip

http://cvhost.scv.cis.iwate-u.ac.jp/research/projects/results.zip

模板图片都是灰色的,我们这边需要彩色的,故生成:

# -*- coding:utf-8 -*-
import os
import cv2
import numpy as np
np.set_printoptions(suppress=True)def mkdir_os(path):if not os.path.exists(path):os.makedirs(path)savepath = "./image_save"
mkdir_os(savepath)oripath = "./targets"
templatespath = "./templates"imgs = os.listdir(oripath)
templates_imgs = os.listdir(templatespath)GT_affine = cv2.FileStorage("./GT_affine.yml", cv2.FileStorage_READ)
GT_coordinate = cv2.FileStorage("./GT_coordinate.yml", cv2.FileStorage_READ)
GT_homography = cv2.FileStorage("./GT_homography.yml", cv2.FileStorage_READ)
GT_SAD = cv2.FileStorage("./GT_SAD.yml", cv2.FileStorage_READ)for index in range(len(imgs)):img = imgs[index]templates = templates_imgs[index]print(img)print(templates)imageMat = cv2.imread(os.path.join(oripath, img), -1)name = 'G'+ str(index+1)homography = GT_homography.getNode(name).mat()result = np.zeros((100, 100, 3), np.uint8)result = cv2.warpPerspective(imageMat, homography, (100, 100), result)cv2.imwrite(os.path.join(savepath, templates), result)
GT_affine.release()
GT_coordinate.release()
GT_homography.release()
GT_SAD.release()

上面的代码最后的代码,在这之前也做了一些其他代码尝试,一并放出:

# -*- coding:utf-8 -*-
import os
import cv2
import numpy as np
np.set_printoptions(suppress=True)def mkdir_os(path):if not os.path.exists(path):os.makedirs(path)savepath = "./image_save"
mkdir_os(savepath)
oripath = "./targets"
templatespath = "./templates"
imgs = os.listdir(oripath)
templates_imgs = os.listdir(templatespath)
GT_affine = cv2.FileStorage("./GT_affine.yml", cv2.FileStorage_READ)
GT_coordinate = cv2.FileStorage("./GT_coordinate.yml", cv2.FileStorage_READ)
GT_homography = cv2.FileStorage("./GT_homography.yml", cv2.FileStorage_READ)
GT_SAD = cv2.FileStorage("./GT_SAD.yml", cv2.FileStorage_READ)debug = 1
for index in range(len(imgs)):img = imgs[index]templates = templates_imgs[index]print(img)imageMat = cv2.imread(os.path.join(oripath,img), -1)templatesMat = cv2.imread(os.path.join(templatespath,templates), -1)HH,WW = imageMat.shape[:2]imageTemp = np.zeros(imageMat.shape, np.uint8)name = 'G'+ str(index+1)coordinate = GT_coordinate.getNode(name).mat()pts = np.array([[coordinate[0][0], coordinate[0][1]], [coordinate[1][0], coordinate[1][1]],[coordinate[2][0], coordinate[2][1]], [coordinate[3][0], coordinate[3][1]]], np.int32)pts = pts.reshape((-1, 1, 2))mask = np.zeros((HH,WW), np.uint8)mask = cv2.polylines(mask, [pts], True, (0, 255, 255))mask2 = cv2.fillPoly(mask.copy(), [pts], (255, 255, 255))intpts = np.int0(pts)x, y, w, h = cv2.boundingRect(intpts)if debug:cv2.imwrite("1.png", mask2)imageTemp = cv2.bitwise_and(imageMat, imageMat, imageTemp, mask2)if debug:cv2.imwrite("2.png", imageTemp)min_rect = cv2.minAreaRect(pts)box = cv2.boxPoints(min_rect)box = np.int0(box)if debug:#cv2.drawContours(imageMat, [box], 0, (0, 0, 255), 2)cv2.imwrite("3.png", imageMat)imgsub = imageTemp[y:y + h, x:x + w]if debug:cv2.imwrite("4.png", imgsub)affine = GT_affine.getNode(name).mat()#仿射变换#points1 = np.float32([[50, 50], [200, 50], [50, 200]])#points2 = np.float32([[10, 100], [200, 50], [100, 250]])#matrix = cv2.getAffineTransform(points1, points2)#output = cv2.warpAffine(img, matrix, (cols, rows))A2 = cv2.warpAffine(templatesMat, affine[:2,:], imageMat.shape[:2], borderValue=255)if debug:cv2.imwrite("5.png", A2)homography = GT_homography.getNode(name).mat()homography_inv = np.linalg.inv(homography)newcoordlist = []for key in range(4):coord = np.array([coordinate[key][0], coordinate[key][1], 1])newcoord = np.matmul(homography,coord)newcoordlist.append([newcoord[0],newcoord[1]])oricoord = np.array(newcoordlist)A2 = cv2.warpAffine(templatesMat, homography[:2,:], imageMat.shape[:2], borderValue=255)if debug:cv2.imwrite("5.png", A2)result = np.zeros((100, 100, 3), np.uint8)#透视变换#points1 = np.float32([[56, 65], [368, 52], [28, 387], [389, 390]])#points2 = np.float32([[0, 0], [300, 0], [0, 300], [300, 300]])#homography = cv2.getPerspectiveTransform(points1, points2)#output = cv2.warpPerspective(img, matrix, (cols, rows))result = cv2.warpPerspective(imageMat, homography, (100, 100), result)cv2.imwrite("6.png", result)
# 关闭文件
GT_affine.release()
GT_coordinate.release()
GT_homography.release()
GT_SAD.release()

最后关于这篇论文的对比对象是Fast-Match

我们修改matlab代码,使其可以使用这边论文的数据,给出遍历所有图像那部分的代码:

注意这里使用了mexopencv,故可以使用opencv的函数,用来读取yml文件

function FastMatch_demo
%%%%%%%%%%%%%%%%%%%%%%%
clc
% clear all
close all
dbstop if error
% adding 2 subdirectories to Matlab PATH
AddPaths
% compiling the relevant Mex-files
CompileMexvis_resultpath = '.\dataset_FATMoGF\vis_result';
mkdir(vis_resultpath)GT_affine = cv.FileStorage('.\dataset_FATMoGF\GT_affine.yml');
GT_coordinate = cv.FileStorage('.\dataset_FATMoGF\GT_coordinate.yml');
GT_homography = cv.FileStorage('.\dataset_FATMoGF\GT_homography.yml');
GT_SAD = cv.FileStorage('.\dataset_FATMoGF\GT_SAD.yml');affine = struct2cell(GT_affine);
coordinate = struct2cell(GT_coordinate);filename = '.\dataset_FATMoGF\file_ID.txt';
[file_ID] = textread(filename,'%s');compare_txt = fopen(fullfile('.\dataset_FATMoGF','compare.txt'),'w');
fprintf(compare_txt,'overlapError fullError\r\n');for i=1:length(file_ID)optMat = affine{i,1};coord = coordinate{i,1};ID = file_ID(i);Name = ID{1};templateImgName = fullfile('.\dataset_FATMoGF','image_save',['template_', Name]);targetImgName = fullfile('.\dataset_FATMoGF','targets',Name);img = imread(targetImgName);imgColor = im2double(img);%imgColor = MakeOdd(imgColor);img = im2double(rgb2gray(img));%img = MakeOdd(img);template = imread(templateImgName);templateColor = im2double(template);%templateColor = MakeOdd(templateColor);template = im2double(rgb2gray(template));%template = MakeOdd(template);[bestConfig,bestTransMat,sampledError] = FastMatch(template,img,templateColor, imgColor);% Visualize result%[optError,fullError,overlapError] = MatchingResult(template,img,templateColor,imgColor,bestTransMat,[],'example 1');[optError,fullError,overlapError] = MatchingResultOpencv(template,img,templateColor,imgColor,coord, Name, vis_resultpath, bestTransMat,optMat,'example 1');fprintf(compare_txt,'%.6f %.6f\r\n',overlapError,fullError);a = 1;
end
fclose(compare_txt);
return;
end

文件夹布局如下:

顺便给出和Fast-Match方法重叠误差对比图代码

import numpy as np
import matplotlib.pyplot as pltplt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号plt.rcParams['font.family'] = 'Arial'
dataArray = np.genfromtxt('compare.txt', delimiter = ' ', names = True)
print(dataArray.dtype.names)dataArray_my = np.genfromtxt('compare_my.txt', delimiter = ' ', names = True)
print(dataArray_my.dtype.names)plt.figure(figsize=(15,3))ax = plt.gca()
plt.xticks(fontsize = 15,fontname='Arial')
plt.yticks(fontsize = 15,fontname='Arial')
plt.xlim(1,500)
plt.ylim(0,1)
plt.grid()
plt.title(r'重叠误差的比较结果', fontsize=15, fontname='SimHei')
plt.ylabel('重叠误差', fontsize=15, fontname='SimHei')
plt.xlabel('图像序号', fontsize=15, fontname='SimHei')
plt.gcf().subplots_adjust(bottom=0.2)
plt.plot(dataArray['our_error'], 'ok', label='FATMoGF')
plt.plot(dataArray['other_error'], 'o', label='Fast-Match', alpha=.5)
plt.legend(numpoints=1)
plt.savefig("compare.pdf",bbox_inches='tight')
plt.show()

Fast Affine Template Matching over Galois Field仿射模板匹配数据测试问题相关推荐

  1. OpenCV模板匹配Template Matching

    OpenCV模板匹配Template Matching 模板匹配Template Matching 目标 理论 什么是模板匹配? OpenCV提供哪些匹配方法? 代码 解释 结果 模板匹配Templa ...

  2. Python+OpenCV:模板匹配(Template Matching)

    Python+OpenCV:模板匹配(Template Matching) Template Matching with Single Objects ######################## ...

  3. Very fast template matching(非常快的模板匹配)

    Very fast template matching(非常快的模板匹配) Integral image 代数矩的快速计算 快速模板匹配 算法步骤 结果 主要讲述文章"Very Fast T ...

  4. Optic Disc Detection using Template Matching based on Color Plane Histograms

    Optic Disc Detection using Template Matching based on Color Plane Histograms 论文翻译:基于彩色平面直方图的模板匹配的视盘检 ...

  5. Python文档阅读笔记-OpenCV中Template Matching

    目标 通过模板匹配在一张图中找相似图. 原理 模板匹配这个方法是在一个大图中找小图的功能,OpenCV中使用cv.matchTemplate()这个函数实现.在OpenCV中可以填写几种参数.这个函数 ...

  6. 学习template算法(template matching)以及改进(二)

    学习template算法(template matching)以及改进(二) 为了实现跨越在不同两张图片内的模板和该两张搜索图片的模板匹配,现在先尝试使用图像拼接的方法,获得两个图像的拼接后的全景图像 ...

  7. 伽罗华域(Galois Field,GF,有限域)

    原文见链接DataMatrix 编码生成和译码原理即方法 原文见链接存储系统中的纠删码(Erasure Codes)-XOR 码和RS 码 原文见链接(讲的很好)Galois 域上的运算(规则) 原文 ...

  8. 伽罗华域(Galois Field)有限域元素生成和运算原理

    存储编码,矩阵等之间的运算都是在伽罗华域(Galois Field,GF,有限域)上进行的,所以要实现底层的运算库,必须了解 GF 上的运算规则. 域: 一组元素的集合,以及在集合上的四则运算,构成一 ...

  9. 伽罗华域(Galois Field, GF, 有限域)的四则运算

    有限域的构造之常见本原多项式 伽罗华域(Galois Field,GF,有限域)乘法运算 伽罗华域(Galois Field)理解.基于伽罗华域的四则运算(附详细python代码)

最新文章

  1. php4.3-5.x,4.3 案例之 ThinkPHP 5.0 集成方法
  2. 丹麦见闻(转自王重合原创)
  3. 淘宝SEO培训视频课程【22讲】
  4. 对VMware自动安装linux系统说“不”!
  5. SpringBoot自动化配置的注解开关原理
  6. matlab实验函数编写与程序设计,matlab实验四函数编写与程序设计.doc
  7. 简单粗暴入门JAVA之方法
  8. typora绑定github博客_零基础搭建个人博客
  9. 获取系统当前时间(多语言版)
  10. 成都睿铂盘点无人机航测三个极端恶劣环境的人员与设备防护指南
  11. 2021年SWPUACM暑假集训day4KMP算法
  12. 帆软高级函数应用之文本函数
  13. java web开发实战经典 李兴华_MLDN李兴华JavaWeb开发实战经典(高级案例篇)全部源码...
  14. zblog php 调用缩略图,zblog调用文章缩略图的方法
  15. 华为云服务器配置过程
  16. 阿诺德·施瓦辛格的演讲(拼命才会优秀,自律才会自由~)
  17. 华为云ModelArts文本分类–外卖评论(附详细图解)
  18. Win10早期版本下月终止服务、百万医疗设备存在漏洞风险|11月10日全球网络安全热点
  19. 部署项目vue +阿里云服务器 + 宝塔面板
  20. VariantsTransport_SAP刘梦_新浪博客

热门文章

  1. 外星人计算机组装配置方案,最好的电脑配置_2020年最强最牛的笔记本配置与组装电脑方案...
  2. 将串口转换成TCP连接
  3. Android 自定义图片点击放大、缩小
  4. 使用vfork、exec系列函数、wait/waited实现system函数的功能
  5. python鲜花_【实战案例】90 行Python代码实现一棵鲜花盛开树
  6. Oculus内下游戏报错,OVR40779122解决办法
  7. Word在方框中插入对勾和×
  8. icewm+rox-filer美化过程(转)
  9. Win10提示“PL2303HXA自2012已停产,请联系供货商”的解决方法
  10. B站弹幕姬()分析与开发(上篇)