helpers.py 829 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np


def timelabels(val, pos):
    min, sec = divmod(int(val), 60)
    timelabel = "{0}:{1:02d}".format(min, sec)
    return timelabel

def luminance(img):
13
14
15
16
17
    """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
    """
18
19
20
21
    # 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
22
    img = np.multiply(img, luminance_factors)
23
24

    # addiert alle Werte auf einer bestimmten Achse
25
    luminances = np.sum(img, axis=2)
26
27

    return luminances