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

implement UnivariateSequence class

change my own deviation method to numpy std. Leads to different results
parent f0ae83cc
......@@ -18,7 +18,7 @@ from . import contrasts
# Use __init__ when you need to control initialization of a new instance."
class View(np.ndarray):
"""Core class for the representation of colour contrasts in Movies
View is the basis class for specific ways to represent colour contrasts.
It does hold the definitions of contrasts itself. Objects of class View
subclass the numpy array class and hence inherit numpy methods. However,
......@@ -151,7 +151,7 @@ class MultivariateSequence(View):
ctrst_cls = self._get_ctrst_cls_name(self._contrast)
ctrst_img = ctrst_cls(img).ctrst
hist_value, _ = np.histogram(ctrst_img.flatten(), bins=self._bins,
range=(0, 256))
......@@ -194,7 +194,7 @@ class BivariateSequence(View):
# das kann ich jetzt auch mit quantilen machen
def populate(self, variant='peak', ctrst='light_dark',
method='luminance', frm_stp=10, bins=256, **kwargs):
method='luminance', frm_stp=10, bins=256):
"""Creates a scatterplot for the dynamic of contrast across movie frames
variant: peak or bin (one of max/min peak; uper/lower mean)
......@@ -311,3 +311,90 @@ class BivariateSequence(View):
contrast_points = None
class UnivariateSequence(View):
def __new__(cls, frames, input_array=None):
"""Represents a movie contrast in terms of a single feature
Parameters
----------
Returns
-------
Object : BivariateSequence
"""
obj = View.__new__(cls, frames, input_array=input_array)
return obj
def __array_finalize__(self, obj):
if obj is None: return
View.__array_finalize__(self, obj)
# TODO später ersetzen durch numpy mean/deviation in Kombination mit anderen Möglichkeiten
@staticmethod
def meanmad(values):
values = values.flatten()
length = values.size
points = np.sum(values)
# range nicht array und histogram verschachtelt (siehe slice)
bin_values = np.apply_along_axis(lambda x: x * values[x-1], 0,
range(1, length+1))
mean = np.sum(bin_values) / points
absolutes = np.apply_along_axis(lambda x: abs(x - mean) * values[x-1],
0, range(1, length+1))
mad = np.sum(absolutes) / points
return mean, mad
# TODO: Kurve muß unbeding von cuts bereinigt werde und interpolation funktioniert da nicht
def populate(self, variant=['mean', 'dev'], ctrst='light_dark',
method='luminance', frm_stp=10, bins=256):
"""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
"""
# set class properties
self._variant = variant
self._contrast = ctrst
self._method = method
self._frame_step = frm_stp
self._bins = bins
# TODO um start und end in der Methode zu parametrisieren müssen erst
# getters und setters in movie.frames definiert werden
# self._frames.start = start
# self._frames.end = end
contrast_points = np.empty((0, 4), dtype=np.uint8)
# pwd list sollte in Frames sein und hier nur durchlaufen werden
for frm_nr in range(self._frames.start, self._frames.end,
self._frame_step):
pwd = self._frames.folder + self._frames.prefix + str(frm_nr) + '.png'
img = cv2.imread(pwd)
ctrst_cls = self._get_ctrst_cls_name(self._contrast)
ctrst_img = ctrst_cls(img).ctrst
hist_value, _ = np.histogram(ctrst_img.flatten(),
bins=self._bins, range=(0, 256))
hist_value = hist_value.flatten()
hist_value = hist_value.astype(np.uint8, copy=False)
# eigenes mean und devi durch numpy ersetzt
# TODO Ergebnisse der unterschiedlichen Verfahrenstimmt nicht überein
contrast = hist_value.mean()
deviation = hist_value.std()
_contrast, _deviation = UnivariateSequence.meanmad(hist_value)
contrast_points = np.vstack((contrast_points,
[contrast, deviation, _contrast, _deviation]))
contrast_points = np.asarray(contrast_points, np.uint8)
shape = contrast_points.shape
self.resize(shape, refcheck=False)
self[:, :] = contrast_points
contrast_points = None
from itten.movie import Movie
from itten.views import BivariateSequence
from itten.views import UnivariateSequence
movie = Movie(prefix='rec_', folder='../DHd-2017/Data/Frames/Rec/')
cont = BivariateSequence(movie._frames)
mean = UnivariateSequence(movie._frames)
Markdown is supported
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