#!/usr/bin/env python # -*- coding: utf-8 -*- import numpy as np import pandas as pd # import math # def lab2hc(labpixel, out='both'): # """returns hue and colorfulness of a pixel # # the image pixel has to have CIE Lab colors. # the conversion follows Fairchild's 2013 conversion equations # # labpixel : pixel from image using CIE Lab color model # out : 'h' (hue), 'c' (colorfulness) or 'both' (tuple containing hue # and colorfulness : default) # """ # # def get_hue(a, b): # hue = math.degrees(math.atan(b/a)) # return hue # # def get_colorfulness(a, b): # colorfulness = (a**2 + b**2)**(1/2) # return colorfulness # # a = labpixel[1] # b = labpixel[2] # # hc = {} # # if not(out == 'c'): # hc['h'] = get_hue(a, b) # elif not(out == 'h'): # hc['c'] = get_colorfulness(a, b) # # return hc # TODO fps muss noch implementiert werden def time2framenr(time, fps=4): """counts the frame index for a given timestamp time : timestamp needs to have the form [HH:]MM:SS fps : frequency with which frames were taken from the movie """ timestmp = time.split(':') in_sec = 0 if len(timestmp) > 2: in_sec += int(timestmp[0]) * 3600 in_sec += int(timestmp[-2]) * 60 in_sec += int(timestmp[-1]) return in_sec * fps def frame2time(val, fps=4): """transforms framenumbers into timecodes Arguments: val {int} -- number of frame in the movie fps {int} -- time interval by which frames were extracted from the movie Returns: np.datetime64 -- timecode of the frame in the movie """ val = round(val/fps) # scale frame number to the unit of 1 sec tstmp = pd.Timedelta(val, unit='s') return tstmp def luminance(img): """Creates an array of luminance value for each pixel of an image The array has the same dimensions as the image. However the third does only have the size 1 which contains the luminance value """ # Luminance Faktoren nach # http://introcs.cs.princeton.edu/python/31datatype/luminance.py.html luminance_factors = np.array([.299, .587, .114]) # Erzeugung eines eindimensionalen Arrays für die effizientere Berechnung img = np.multiply(img, luminance_factors) # addiert alle Werte auf einer bestimmten Achse luminances = np.sum(img, axis=2) return luminances