我正在进行一个项目,以自动旋转流体实验的显微镜图像堆栈,以便它们与微流控芯片的CAD模板图像对齐。我正在使用Python中的OpenCV软件包进行图像处理。必须具有正确的旋转方向,以便可以正确遮盖图像以进行分析。我们的芯片具有在每个帧中都可见的充满荧光染料的标记。模板和示例图像如下所示(模板可以缩放到任意大小,但是图像的相关区域通常约为100x100像素左右):
我无法将图像旋转对齐到CAD模板。通常,CAD模板与图像之间的未对准小于几度,这仍然足以干扰分析,因此即使它相对较小,我也需要能够测量旋转差异。
在线以下示例我正在使用以下过程:
这是我的代码示例(部分从此处借来):
import numpy as np
import cv2
import matplotlib.pyplot as plt
MAX_FEATURES = 500
GOOD_MATCH_PERCENT = 0.5
def alignImages(im1, im2,returnpoints=False):
# Detect ORB features and compute descriptors.
size1 = int(0.1*(np.mean(np.shape(im1))))
size2 = int(0.1*(np.mean(np.shape(im2))))
orb1 = cv2.ORB_create(MAX_FEATURES,edgeThreshold=size1,patchSize=size1)
orb2 = cv2.ORB_create(MAX_FEATURES,edgeThreshold=size2,patchSize=size2)
keypoints1, descriptors1 = orb1.detectAndCompute(im1, None)
keypoints2, descriptors2 = orb2.detectAndCompute(im2, None)
matcher = cv2.BFMatcher(cv2.NORM_HAMMING,crossCheck=True)
matches = matcher.match(descriptors1,descriptors2)
# Sort matches by score
matches.sort(key=lambda x: x.distance, reverse=False)
# Remove not …Run Code Online (Sandbox Code Playgroud) python opencv image-processing image-rotation feature-detection