嗨,我正在尝试在python中实现焦点堆叠。我看过Photoshop以及它如何进行图像堆叠,效果非常好。但是我想使用Python来应用类似的技术。
def stackImagesECC(file_list):
M = np.eye(3, 3, dtype=np.float32)
first_image = None
stacked_image = None
for file in file_list:
image = cv2.imread(file,1).astype(np.float32) / 255
print(file)
if first_image is None:
# convert to gray scale floating point image
first_image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
stacked_image = image
else:
# Estimate perspective transform
s, M = cv2.findTransformECC(cv2.cvtColor(image,cv2.COLOR_BGR2GRAY), first_image, M, cv2.MOTION_HOMOGRAPHY)
w, h, _ = image.shape
# Align image to first image
image = cv2.warpPerspective(image, M, (h, w))
stacked_image += image
stacked_image /= len(file_list)
stacked_image = (stacked_image*255).astype(np.uint8)
return stacked_image
此功能可以对齐图像
images = glob.glob("edges_canny/*.jpg")
kernel = np.ones((3, 3), np.uint8)
for image in images:
with open(image, 'rb') as file:
img = Image.open(file)
# img.show()
indexed = np.array(img)
img_dilate = cv2.dilate(indexed, kernel, iterations=1)
very_blurred = ndimage.gaussian_filter(img_dilate, sigma=5)
ret, thresh5 = cv2.threshold(very_blurred, 100, 255, cv2.THRESH_TOZERO_INV)
cv2.imshow("a",thresh5)
cv2.waitKey(0)
在这里,我再次读取边缘检测到的图像,并对其进行膨胀,高斯模糊和阈值处理以获得感兴趣的区域(我不确定)。我相信有一些方法可以直接从对齐功能读取对齐的图像。