461. Hamming Distance-Python


The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

Given two integers x and y, calculate the Hamming distance.

Note:

0 ≤ x, y < 2^31.

Example:

Input: x = 1, y = 4

Output: 
图像对齐是指将多幅图像对齐到同一个坐标系下,以方便进行后续处理,例如图像融合、图像拼接等。在进行图像对齐时,常常需要考虑到图像的亮度、对比度等因素,因此可以使用直方图均衡化来增强图像的对比度。 下面是使用opencv-python实现图像对齐的示例代码,其中包括了直方图均衡化的步骤: ```python import cv2 import numpy as np # 读取两张待对齐的图片 img1 = cv2.imread('img1.jpg') img2 = cv2.imread('img2.jpg') # 将图片转为灰度图 gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY) gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY) # 对灰度图进行直方图均衡化 equ1 = cv2.equalizeHist(gray1) equ2 = cv2.equalizeHist(gray2) # 初始化ORB检测器 orb = cv2.ORB_create() # 使用ORB检测关键点和描述子 kp1, des1 = orb.detectAndCompute(equ1, None) kp2, des2 = orb.detectAndCompute(equ2, None) # 初始化暴力匹配器 bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True) # 匹配两幅图片的描述子 matches = bf.match(des1, des2) # 根据匹配结果筛选出较好的匹配点 matches = sorted(matches, key=lambda x: x.distance) good_matches = matches[:50] # 获取匹配点的坐标 src_pts = np.float32([kp1[m.queryIdx].pt for m in good_matches]).reshape(-1, 1, 2) dst_pts = np.float32([kp2[m.trainIdx].pt for m in good_matches]).reshape(-1, 1, 2) # 计算透视变换矩阵 M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0) # 对第一张图片进行透视变换,以将其对齐到第二张图片上 aligned_img = cv2.warpPerspective(img1, M, (img2.shape[1], img2.shape[0])) # 显示对齐后的图片 cv2.imshow('Aligned Image', aligned_img) cv2.waitKey(0) cv2.destroyAllWindows() ``` 在上述代码中,我们首先使用`cv2.cvtColor`函数将两张图片转为灰度图,然后分别对灰度图进行直方图均衡化,以增强图像的对比度。接着使用ORB特征检测器和暴力匹配器来匹配两幅图片的关键点,并筛选出较好的匹配点。最后使用`cv2.findHomography`函数计算透视变换矩阵,并对第一张图片进行透视变换,以将其对齐到第二张图片上。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值