From 95f68d9b4bc3429538291fb996bd34947ec04080 Mon Sep 17 00:00:00 2001 From: JP+ <63192177+joachimpoutaraud@users.noreply.github.com> Date: Sat, 4 Mar 2023 20:08:01 +0100 Subject: [PATCH] Normalized pixel values in motion() #290 --- musicalgestures/__init__.py | 3 ++- musicalgestures/_motionanalysis.py | 3 ++- musicalgestures/_motionvideo.py | 18 +++--------------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/musicalgestures/__init__.py b/musicalgestures/__init__.py index 500505b..591ca79 100644 --- a/musicalgestures/__init__.py +++ b/musicalgestures/__init__.py @@ -141,7 +141,8 @@ def get_video(self): # Convert eventual low-resolution video and thumbnail to mp4 video_formats = ['.avi', '.mp4', '.mov', '.mkv', '.mpg', '.mpeg', '.webm', '.ogg', '.ts', '.wmv', '.3gp'] - if self.fex not in video_formats: + image_formats = ['.gif', '.jpeg', '.jpg', '.jfif', '.pjpeg', '.png', '.svg', '.webp', '.avif', '.apng'] + if self.fex not in video_formats and self.fex not in image_formats: # Create one converted version and register it to the MgVideo filename = convert_to_mp4(self.of + self.fex, overwrite=True) # point of and fex to the mp4 version diff --git a/musicalgestures/_motionanalysis.py b/musicalgestures/_motionanalysis.py index db07a1a..17f669e 100644 --- a/musicalgestures/_motionanalysis.py +++ b/musicalgestures/_motionanalysis.py @@ -4,7 +4,7 @@ def centroid(image, width, height): """ - Computes the centroid of an image or frame. + Computes the centroid and quantity of motion in an image or frame. Args: image (np.array(uint8)): The input image matrix for the centroid estimation function. @@ -20,6 +20,7 @@ def centroid(image, width, height): x = np.arange(width) y = np.arange(height) + # Calculates the sum of the pixels in the input image qom = cv2.sumElems(image)[0] mx = np.mean(image, axis=0) my = np.mean(image, axis=1) diff --git a/musicalgestures/_motionvideo.py b/musicalgestures/_motionvideo.py index d53ba05..92bcd42 100644 --- a/musicalgestures/_motionvideo.py +++ b/musicalgestures/_motionvideo.py @@ -392,19 +392,7 @@ def mg_motionvideo( Returns: MgVideo: A new MgVideo pointing to the output '_motion' video file. """ - # return mg_motion( - # self, - # filtertype=filtertype, - # thresh=thresh, - # blur=blur, - # kernel_size=kernel_size, - # use_median=use_median, - # inverted_motionvideo=inverted_motionvideo, - # save_data=False, - # save_motiongrams=False, - # save_plot=False, - # save_video=True) - + motionvideo = motionvideo_ffmpeg( filename=self.filename, color=self.color, @@ -786,9 +774,9 @@ def save_single_file(of, time, aom, com, qom, motion_analysis, width, height, da elif motion_analysis.lower() == 'com': df = pd.DataFrame({'Time': time, 'ComX': com.transpose()[0]/width, 'ComY': com.transpose()[1]/height}) elif motion_analysis.lower() == 'qom': - df = pd.DataFrame({'Time': time, 'Qom': qom}) + df = pd.DataFrame({'Time': time, 'Qom': qom/max(qom)}) elif motion_analysis.lower() == 'all': - df = pd.DataFrame({'Time': time, 'Qom': qom, 'ComX': com.transpose()[0]/width, 'ComY': com.transpose()[1]/height, + df = pd.DataFrame({'Time': time, 'Qom': qom/max(qom), 'ComX': com.transpose()[0]/width, 'ComY': com.transpose()[1]/height, 'AomX1': aom.transpose()[0], 'AomY1': aom.transpose()[1], 'AomX2': aom.transpose()[2], 'AomY2': aom.transpose()[3]}) if data_format == "tsv":