contrasts.py 1.38 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
# -*- coding: utf-8 -*-


# TODO import as cv
import cv2
import numpy as np
from .helpers import luminance


# TODO nicht benötigte Parameter löschen
def mono_ctrst_scatplt(channel, frames, frm_step=1, bins=16, threshold=60000, save=False, **kwargs):
    """Creates a scatterplot for the dynamic of contrast across movie frames

       frm_fld: path to folder with movie images
       frm_pref: file nave in fron of the count value
       frm_step: take every x frame
       channel: channel in the HSV color space
       save: save plot also to disk
       threshold: TODO
    """
    contrast_points = []
    # pwd list sollte in Frames sein und hier nur durchlaufen werden
    for frm_nr in range(frames.start, frames.end, frm_step):
        pwd = frames.folder + frames.prefix + str(frm_nr) + '.png'

        img = cv2.imread(pwd)

        if channel == 2:
            _img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
            luminances = luminance(_img)
            hist_value, _ = np.histogram(luminances, bins=bins, range=(0, 255))

        else:

            img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV_FULL)
            hist_value = cv2.calcHist([img_hsv], [channel], None, [16], [0, 256])

        for bin_index, point in enumerate(hist_value):
            if point > threshold:
                contrast_points.append((frm_nr, bin_index, int(point)))

    return contrast_points