如何解决关于 skimage.transform.PolynomialTransform 的问题
我有两个图像(通道 1 和通道 2),我正在尝试计算将一个图像变形为另一个图像的多项式变换。首先,我创建了一个 ORB 对象并计算了两个图像之间的仿射变换(后仿射)。然后我决定尝试使用 skimage.transform.PolynomialTransform。但是,当我尝试计算变换时,返回的 NumPy 数组具有 NaN 值或 0 值,即使原始图像在该位置(后多项式)具有非零浮点值。我究竟做错了什么?下面包含代码,以下链接中的图像。 https://drive.google.com/drive/folders/1mWxUvLFLK5-rYCrxs3-uGKFxKq2wXDjS?usp=sharing 提前致谢!
注意:我知道问题 Image warping with scikit-image and transform.PolynomialTransform 是相似的,但在我看来这两个不是重复的。尽管该用户的问题是使用相同的函数,但他们转换后的图像中的像素具有值,而我的基本上没有。
import cv2
from ImageConversion import ImageConversion # self-written,irrelevant
import matplotlib
matplotlib.use('macosX')
import matplotlib.pyplot as plt
from scipy.ndimage import uniform_filter
from skimage.draw import circle_perimeter
from skimage.transform import PolynomialTransform,warp
def affine_transform(self):
channel1_u8 = self.channel1.astype('uint8') # necessary for detectAndCompute
channel2_u8 = self.channel2.astype('uint8')
orb = cv2.ORB_create(100)
#kp1,des1 = orb.detectAndCompute(channel1_32,None)
#kp2,des2 = orb.detectAndCompute(channel2_32,None)
kp1,des1 = orb.detectAndCompute(channel1_u8,None)
kp2,des2 = orb.detectAndCompute(channel2_u8,None)
matcher = cv2.DescriptorMatcher_create(cv2.DESCRIPTOR_MATCHER_BRUTEFORCE_HAMMING)
matches = matcher.match(des1,des2,None)
matches = sorted(matches,key = lambda x:x.distance)
points1 = np.zeros((len(matches),2),dtype = np.float32)
points2 = np.zeros((len(matches),dtype = np.float32)
for i,match in enumerate(matches):
points1[i,:] = kp1[match.queryIdx].pt # index of descriptor in query descriptors,ie index of descriptor in channel 1 which is the image we wish to map to channel 2
points2[i,:] = kp2[match.trainIdx].pt
mat_coeff,inliers = cv2.estimateAffine2D(points1,points2) # inliers only here because estimateAffine2D returns both matrix coefficients and inliers
print(mat_coeff)
rows,cols = channel1_u8.shape
#dst = cv2.warpAffine(channel1_u8,mat_coeff,(cols,rows))
dst = cv2.warpAffine(self.channel1,rows))
return mat_coeff,dst
tform = PolynomialTransform()
tform.estimate(self.channel2,dst,order = 3)
warped_1 = warp(dst,tform,mode = 'constant')
解决方法
我发现了错误。我试图输入 PolynomialTransform.estimate 整个图像,而不是识别图像中的关键点。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。