我有一系列的海底图像,这些图像是从胶片上扫描得来的,需要进行注册处理。
from pylab import *
import cv2
import urllib
urllib.urlretrieve('http://geoport.whoi.edu/images/frame014.png','frame014.png');
urllib.urlretrieve('http://geoport.whoi.edu/images/frame015.png','frame015.png');
gray1=cv2.imread('frame014.png',0)
gray2=cv2.imread('frame015.png',0)
figure(figsize=(14,6))
subplot(121);imshow(gray1,cmap=cm.gray);
subplot(122);imshow(gray2,cmap=cm.gray);
我希望利用每张图片左侧的黑色区域进行配准,因为该区域位于相机内部且应在时间上固定。因此,我只需要计算黑色区域之间的仿射变换。
我通过阈值处理和寻找最大轮廓来确定这些区域:
def find_biggest_contour(gray,threshold=40):
# threshold a grayscale image
ret,thresh = cv2.threshold(gray,threshold,255,1)
# find the contours
contours,h = cv2.findContours(thresh,mode=cv2.RETR_LIST,method=cv2.CHAIN_APPROX_NONE)
# measure the perimeter
perim = [cv2.arcLength(cnt,True) for cnt in contours]
# find contour with largest perimeter
i=perim.index(max(perim))
return contours[i]
c1=find_biggest_contour(gray1)
c2=find_biggest_contour(gray2)
x1=c1[:,0,0];y1=c1[:,0,1]
x2=c2[:,0,0];y2=c2[:,0,1]
figure(figsize=(8,8))
imshow(gray1,cmap=cm.gray, alpha=0.5);plot(x1,y1,'b-')
imshow(gray2,cmap=cm.gray, alpha=0.5);plot(x2,y2,'g-')
axis([0,1500,1000,0]);
蓝色线条是第一帧中最长的轮廓,绿色线条则是第二帧中最长的轮廓。
如何最好地确定蓝色和绿色轮廓之间的旋转和偏移?
我只想在台阶周围的某个区域使用轮廓的右侧,类似于箭头之间的区域。
当然,如果有更好的方法来对齐这些图像,我很乐意听取建议。我已经尝试了标准的特征匹配方法,但效果不太好。