我写了一个代码,取多个图像的平均值来检索背景,这基本上删除了图像中的移动对象。我试着在取平均值之前去掉离群值,这样我就可以得到背景而不是褪色的对象。我尝试了一些技巧,最近的一个是:#!/usr/bin/env python3
import numpy as np
from PIL import Image
from scipy import stats
# Load images
im0 = np.array(Image.open('test1/1.jpg'))
im1 = np.array(Image.open('test1/2.jpg'))
im2 = np.array(Image.open('test1/3.jpg'))
# Stack the 3 images into a 4d sequence
sequence = np.stack((im0, im1, im2), axis=3)
mean = np.mean(sequence, axis=3)
sd = np.std(sequence, axis=3)
finalSequence = [x for x in sequence if (x > mean - 2 * sd)]
finalSequence = [x for x in finalSequence if (x < mean + 2 * sd)]
# Repace each pixel by mean of the sequence
result = np.mean(finalSequence, axis=3).astype(np.uint8)
# Save to disk
Image.fromarray(result).save('result.png')
这给了我一个错误:
^{pr2}$
如果你能帮上忙,我会很感激的。谢谢!在