Skip to content

Commit

Permalink
Normalized pixel values in motion() #290
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimpoutaraud committed Mar 4, 2023
1 parent 91c9da1 commit 95f68d9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
3 changes: 2 additions & 1 deletion musicalgestures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion musicalgestures/_motionanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
18 changes: 3 additions & 15 deletions musicalgestures/_motionvideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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":
Expand Down

0 comments on commit 95f68d9

Please sign in to comment.