Commit ac331330 authored by Niels-Oliver Walkowski's avatar Niels-Oliver Walkowski
Browse files

change scatter contrast into rudimentary class

parent 85207cb0
......@@ -8,36 +8,36 @@ 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
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
......@@ -8,15 +8,17 @@ from . import helpers
from . import contrasts
# zum Problem mit privaten und öffentlichen Eigenschaften http://www.python-course.eu/python3_properties.php
class Movie(object):
"""main class to interact with the colorspace of movieframes"""
def __init__(self, prefix, folder='./'): # TODO platform independent
Movie.frames = Frames(folder, prefix)
self.fsize = Movie.frames.frm_cnt
self._frames = Frames(folder, prefix)
self.fsize = self._frames.frm_cnt
def scatterpoints(self, channel):
contrast = contrasts.mono_ctrst_scatplt(1, Movie.frames)
return contrast
def light_dark(self):
"""compute the light/dark contrast of the movie """
light_dark_ctrst = contrasts.LightDark(self._frames)
return light_dark_ctrst.hist_vstack()
class Frames(object):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment