Question: : = , + Code + Text Q v v MotionDetection class def ( self , num _ sigmas = 4 . , discount =

:=,+ Code + Text
Q vv MotionDetection class
def (self, num_sigmas=4., discount=0.96):
"""Motion detection implemented via averagerator.
@param num_sigmas: by how many standard deviations should a pixel
differ from the average for motion to be detected. This is
the \kappa of the above explanation.
@param discount: discount factor for the averagerator.
""""
self.num_sigmas = num_sigmas
self.discount = discount
self. average = None
def detect_motion(self, img):
"""Detects motion.
@param img: an hw3 image.
areturns: an hw boolean matrix, indicating where motion occurred.
A pixel is considered a motion pixel if one of its color bands deviates
by more than num_sigmas standard deviations from the average.""."
if self.average is None:
self. average =np.f loat32(img)
return np.zeros_like(img, dtype=bool)
diff =np. abs(np.float32(img)- self.average)
diff_threshold = self.num_sigmas ** np.std(diff, axis=2, keepdims=True)
motion_mask =np.any (diff > diff_threshold, axis =2
self.average = self.discount ** self.average self.discount
 :=,+ Code + Text Q vv MotionDetection class def (self, num_sigmas=4.,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!