contrasts.py 1.33 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
#!/usr/bin/env python
# -*- coding: utf-8 -*-


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


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
class LightDark(object):
    """representations of light/dark contrasts"""
    def __init__(self, frames):
        self._channel = 2
        self._frm_step = 50
        self._bins = 16
        self._threshold = 60000
        self._save = False
        self._frames = frames

    def hist_vstack(self):
        contrast_points = []
        # pwd list sollte in Frames sein und hier nur durchlaufen werden
        for frm_nr in range(self._frames.start, self._frames.end, self._frm_step):
            pwd = self._frames.folder + self._frames.prefix + str(frm_nr) + '.png'

            img = cv2.imread(pwd)

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

            else:

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

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

        return contrast_points