如何组合许多连续的图像来模拟逼真的运动模糊?

How to combine many successive image to simulate a realistic motion blurring?

本文关键字:模拟 真的 运动 模糊 图像 何组合 组合 连续 许多      更新时间:2023-10-16

我想模拟逼真的运动模糊。我不想在整个图像中产生模糊效果,而只想在移动的物体上产生模糊效果。我知道我可以使用滤镜,但模糊效果会在整个图像中传播。我想使用光流,但我不确定它是否会起作用,因为结果在很大程度上取决于提取的特征。

我的主要想法是组合连续帧以生成运动模糊。

谢谢

没那么容易。

您确实可以尝试使用光流。估计每对帧之间的流量。在运动方向上模糊帧(例如各向异性高斯(,滤镜范围等效于位移。最后,通过形成加权平均值来混合模糊的图像和背景,其中每一帧在移动更多的地方都会获得更多权重。

你需要为对象提供一个 [0,1] alpha 掩码。然后,您可以使用方向滤镜来模糊对象及其蒙版,例如,如下所示: https://www.packtpub.com/mapt/book/application_development/9781785283932/2/ch02lvl1sec21/motion-blur

然后使用模糊蒙版将模糊的对象 Alpha 混合回原始未模糊的场景或其他场景:

#Blend the alpha_mask region of the foreground over the image background
#fg is foreground, alpha_mask is a [0,255] mask, image is background scene
foreground = fg.astype(float)
background = image.astype(float)
#Normalize alpha_mask
alpha = alpha_mask.astype(float) / 255
# Multiply the foreground with the alpha_mask
foreground = cv2.multiply(alpha, foreground)
# Multiply the background with ( 1 - alpha )
background = cv2.multiply(1.0 - alpha, background)
# Add the masked foreground and background, turn back to byte image
composit_image = cv2.add(foreground, background).astype(np.uint8)