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

feat(mod): Add data and visual extractor

parent 8033b96c
...@@ -17,3 +17,4 @@ itten.egg-info/ ...@@ -17,3 +17,4 @@ itten.egg-info/
tests/data tests/data
.code-workspace.code-workspace .code-workspace.code-workspace
scratchpad.py scratchpad.py
cittena.gsp
import sys
from pathlib import Path from pathlib import Path
from subprocess import Popen, PIPE, CalledProcessError, run from subprocess import PIPE, run
from cv2 import imread, imwrite from cv2 import imread, imwrite
import pandas as pd
import numpy as np import numpy as np
from .movie import Movie from .movie import Movie
from .views import UnivariateSequence, MultivariateSequence
from .visuals import UnivariatePlot, MultivariatePlot
_summary = {'seqmean': {'monochromatic': ['luminance'], _summary = {'seqmean': {'monochromatic': ['luminance'],
'saturation': ['saturation', 'colourfulness'], 'saturation': ['saturation', 'colourfulness'],
...@@ -43,6 +47,7 @@ class Corpus(object): ...@@ -43,6 +47,7 @@ class Corpus(object):
not('_' in str(d.name)[0])] not('_' in str(d.name)[0])]
for m in movie_dirs: for m in movie_dirs:
self.status = {}
movie = m.name movie = m.name
status[movie] = {} status[movie] = {}
...@@ -101,6 +106,30 @@ class Corpus(object): ...@@ -101,6 +106,30 @@ class Corpus(object):
""" """
tasks = self._extraction_tasks() tasks = self._extraction_tasks()
for movie, missing in tasks.items():
# Extract frames
if 'frames' in missing:
self._extract_frames(movie)
# Extract data
try:
for strategy, contrasts in missing['data'].items():
for ctrst, methods in contrasts.items():
for meth in methods:
print('{:15s} (data, {:18s}): {} missing with methods: {}'.format(movie, strategy, ctrst, meth))
self._extract_data(movie, strategy, ctrst, meth)
except KeyError:
print('{0} (data): Nothing to do'.format(movie))
# Extract visuals
try:
for strategy, contrasts in missing['visuals'].items():
for ctrst, methods in contrasts.items():
for meth in methods:
print('{:15s} (visuals, {:15s}): {} missing with methods: {}'.format(movie, strategy, ctrst, meth))
self._extract_visuals(movie, strategy, ctrst, meth)
except KeyError:
print('{0} (visuals): Nothing to do'.format(movie))
# TODO Extractors implementieren # TODO Extractors implementieren
return tasks return tasks
...@@ -138,7 +167,8 @@ class Corpus(object): ...@@ -138,7 +167,8 @@ class Corpus(object):
if contrast not in ctrst_keys: if contrast not in ctrst_keys:
missing.setdefault(m, {component: {}}) missing.setdefault(m, {component: {}})
missing[m][component].setdefault(view, {}) missing[m][component].setdefault(view, {})
missing[m][component][view][contrast] = (_summary[view][contrast]) missing[m][component][view][contrast] = \
(_summary[view][contrast])
else: else:
# For each method in the crrent view and # For each method in the crrent view and
# contrast look out if a key for that method # contrast look out if a key for that method
...@@ -210,11 +240,53 @@ class Corpus(object): ...@@ -210,11 +240,53 @@ class Corpus(object):
else: else:
print('Finished!') print('Finished!')
def _extract_data(self): def _extract_data(self, movie, strategy, contrast, method):
pass try:
m = Movie(movie + '_', str(self.basedir / movie / 'frames' / '240p30') + '/')
def _extract_visuals(self): if strategy == 'seqmean':
pass view = UnivariateSequence(m._frames)
view.seqmean(ctrst=contrast, method=method, frm_stp=4,)
elif strategy == 'distribution':
view = MultivariateSequence(m._frames)
view.populate(ctrst=contrast, method=method, frm_stp=4,)
title = movie + '_' + strategy + '_' + contrast + '_' + method + '_4fps'
Path(self.basedir / movie / 'data').mkdir(parents=True, exist_ok=True)
data = pd.DataFrame(view[:])
data.to_pickle(str(self.basedir / 'data' / (title + '.pkl')))
except:
e = sys.exc_info()[0]
print('{} (data, {}): {} ({}) raised an error:'.format(movie, strategy, contrast, method))
print('Error: {}'.format(e))
def _extract_visuals(self, movie, strategy, contrast, method):
m = Movie(movie + '_', str(self.basedir / movie / 'frames' / '240p30') + '/')
data = pd.read_pickle(str(self.basedir / movie / 'data' / (movie + '_' + strategy + '_' + contrast + '_' + method + '_4fps.pkl')))
try:
if strategy == 'seqmean':
view = UnivariateSequence(m._frames, input_array=data.to_numpy().flatten())
view._contrast = contrast
view._method = method
view.feature = 'mean'
viz = UnivariatePlot(view,)
elif strategy == 'distribution':
view = MultivariateSequence(m._frames, input_array=data.to_numpy())
view._bins = 16
view._threshold = 6000
view._contrast = contrast
view._method = method
viz = MultivariatePlot(view)
viz.plot(view)
title = movie + '_' +\
strategy + '_' +\
contrast + '_' +\
method +\
'_4fps'
file_name = title + '.png'
viz.saveplt(title=title, fname=self.basedir / movie / file_name)
except:
e = sys.exc_info()[0]
print('{} (visual, {}): {} ({}) raised an error:'.format(movie, strategy, contrast, method))
print('Error: {}'.format(e))
def tableau(self, mode='contrast', def tableau(self, mode='contrast',
select=['distribution', 'monochromatic', 'luminance'], select=['distribution', 'monochromatic', 'luminance'],
......
...@@ -62,7 +62,7 @@ class View(np.ndarray): ...@@ -62,7 +62,7 @@ class View(np.ndarray):
obj = np.asarray(input_array).view(cls).copy() obj = np.asarray(input_array).view(cls).copy()
obj._frames = frames obj._frames = frames
obj._contrast = 2 obj._contrast = 2
obj._frame_step = 10 obj._frame_step = 4
obj._bins = 256 obj._bins = 256
return obj return obj
...@@ -150,7 +150,7 @@ class MultivariateSequence(View): ...@@ -150,7 +150,7 @@ class MultivariateSequence(View):
View.__array_finalize__(self, obj) View.__array_finalize__(self, obj)
self._threshold = getattr(obj, '_threshold', None) self._threshold = getattr(obj, '_threshold', None)
def populate(self, ctrst='monochromatic', method='luminance', frm_stp=10, def populate(self, ctrst='monochromatic', method='luminance', frm_stp=4,
bins=16, thrsh=6000, start=1, end=0): bins=16, thrsh=6000, start=1, end=0):
"""doc (aus __new__ zusammentragen) """doc (aus __new__ zusammentragen)
""" """
...@@ -254,7 +254,7 @@ class UnivariateSequence(View): ...@@ -254,7 +254,7 @@ class UnivariateSequence(View):
# TODO: Kurve muß unbeding von cuts bereinigt werde und interpolation # TODO: Kurve muß unbeding von cuts bereinigt werde und interpolation
# funktioniert da nicht # funktioniert da nicht
def seqmean(self, ctrst='monochromatic', def seqmean(self, ctrst='monochromatic',
method='luminance', frm_stp=10, bins=256): method='luminance', frm_stp=4, bins=256):
"""Creates a scatterplot for the dynamic of contrast across movie frames """Creates a scatterplot for the dynamic of contrast across movie frames
frm_fld: path to folder with movie images frm_fld: path to folder with movie images
......
...@@ -141,7 +141,7 @@ class MultivariatePlot(SequencePlot): ...@@ -141,7 +141,7 @@ class MultivariatePlot(SequencePlot):
self._ax, axt = self.ittenstyle(self._ax, view) self._ax, axt = self.ittenstyle(self._ax, view)
# Plotten # Plotten
axt.scatter(x, y, c=(0, 0, 0), s=thickness, linewidths=0) axt.scatter(x, y, c='black', s=thickness, linewidths=0)
# axt.scatter(x, y, c=y, cmap='Greys_r', s=thickness, linewidths=0) # axt.scatter(x, y, c=y, cmap='Greys_r', s=thickness, linewidths=0)
# # DOC: vmin/vmax sorgt für die Verteilung der Fraben der Colorm # # DOC: vmin/vmax sorgt für die Verteilung der Fraben der Colorm
# ax.scatter(x, y, c=y, cmap='hsv', s=thickness, linewidths=0) # ax.scatter(x, y, c=y, cmap='hsv', s=thickness, linewidths=0)
......
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