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

add legend to UnivariatePlot

parent b2f51085
......@@ -7,7 +7,8 @@ image files or frames that were extracted from moving image files.
ToDo
====
[] `MultivariatePlot` muss noch auf die selbe Simplizität wie `UnivariatePlot`
umgestellt werden
[] Bisher funktioniert nur der LightDark Contrast, andere Kontraste
implementieren
[] `MultivariatePlot` muss noch auf die selbe Simplizität wie `UnivariatePlot`
umgestellt werden
[] gettter und setter für Frames.start setzen und das Rekursionsproblem lösen
[x] Bisher funktioniert nur der LightDark Contrast, andere Kontraste
implementieren
......@@ -3,11 +3,16 @@ import cv2 as cv
# TODO create generic class
class Contrast(object):
"""Base class for color contrasts"""
def __init__(self, img):
self._img = img
class LightDark(object):
class LightDark(Contrast):
"""docstring for LightDark"""
def __init__(self, img, method='luminance'):
self._img = img
super(LightDark, self).__init__(img)
meth = getattr(LightDark, method)
self.ctrst = meth(self)
......@@ -43,3 +48,41 @@ class LightDark(object):
lightness = img[:, :, 1].copy()
return lightness
class Saturation(Contrast):
"""docstring for Saturation"""
def __init__(self, img, method='saturation'):
super(Saturation, self).__init__(img)
meth = getattr(Saturation, method)
self.ctrst = meth(self)
def saturation(self):
"""docstring for saturation"""
img = cv.cvtColor(self._img, cv.COLOR_BGR2HSV)
saturations = img[:, :, 1].copy()
return saturations
def chroma(self):
"""docstring for chroma"""
pass
class Hue(Contrast):
"""docstring for Saturation"""
def __init__(self, img, method='hue'):
super(Hue, self).__init__(img)
meth = getattr(Hue, method)
self.ctrst = meth(self)
def hue(self):
"""docstring for hue"""
img = cv.cvtColor(self._img, cv.COLOR_BGR2HSV)
hues = img[:, :, 0].copy()
return hues
......@@ -33,6 +33,10 @@ class Frames(object):
self.end = end
self.frm_cnt = 0
# TODO start als property erzeugt bisher eine Endlosschleife wei
# count_frames sart und end brauchen und so gegenseitig sart und end nicht
# gesetzt wird
@property
def end(self):
return self.__end
......@@ -41,16 +45,16 @@ class Frames(object):
def end(self, nr):
if nr == 0:
self.__end = self.frm_length
self.frm_cnt = self.count_frames
self.frm_cnt = self.count_frames()
elif nr > self.frm_length:
self.__end = self.frm_length - 1
self.frm_cnt = self.count_frames
self.frm_cnt = self.count_frames()
elif nr < self.start:
self.__end = self.start + 1
self.frm_cnt = self.count_frames
self.frm_cnt = self.count_frames()
else:
self.__end = nr
self.frm_cnt = self.count_frames
self.frm_cnt = self.count_frames()
@property
def frm_cnt(self):
......
......@@ -327,15 +327,18 @@ class UnivariateSequence(View):
"""
obj = View.__new__(cls, frames, input_array=input_array)
obj.feature = None
return obj
def __array_finalize__(self, obj):
if obj is None: return
self._threshold = getattr(obj, 'feature', None)
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)
......@@ -360,6 +363,7 @@ class UnivariateSequence(View):
save: save plot also to disk
"""
# set class properties
self.feature = 'mean'
self._contrast = ctrst
self._method = method
self._frame_step = frm_stp
......@@ -413,6 +417,7 @@ class UnivariateSequence(View):
save: save plot also to disk
"""
# set class properties
self.feature = 'absolute_deviation'
self._contrast = ctrst
self._method = method
self._frame_step = frm_stp
......
......@@ -124,6 +124,7 @@ class UnivariatePlot(SequencePlot):
# Interpolation mit savitzky_golay funktioniert nicht
# contrast_points = savitzky_golay(np.array(contrast_points), 51, 7)
self._axt.plot(self._x, view)
self._axt.plot(self._x, view, label=view.feature)
self._axt.legend()
return self.fig
......@@ -2,12 +2,14 @@ from itten.movie import Movie
from itten.views import UnivariateSequence
from itten.visuals import UnivariatePlot
movie = Movie(prefix='rec_', folder='../DHd-2017/Data/Frames/Rec/', end=1100)
cont = UnivariateSequence(movie._frames)
cont.seqmean(frm_stp=2)
movie = Movie(prefix='rec_', folder='../DHd-2017/Data/Frames/Rec/')
# movie._frames.start = 367
# movie._frames.end = 784
cont = UnivariateSequence(movie._frames,)
cont.seqmean(frm_stp=3, ctrst='saturation')
viz = UnivariatePlot(cont)
viz.plot(cont)
cont.seqmad(frm_stp=2)
# viz.plot(cont)
cont.seqmad(frm_stp=3, ctrst='saturation')
viz.plot(cont)
viz.saveplt()
......
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