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

change contrast class as numpy subclass

just as a reference implementation for the value contrast and not generacilly
parent ac331330
......@@ -14,34 +14,11 @@ badd +16 itten/helpers.py
badd +1023 term://.//20282:/usr/bin/zsh\ ;\#neoterm-1
argglobal
silent! argdel *
edit itten/movie.py
edit testing/ittennb.py
set splitbelow splitright
wincmd _ | wincmd |
vsplit
1wincmd h
wincmd w
wincmd t
set winheight=1 winwidth=1
wincmd =
argglobal
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 17 - ((15 * winheight(0) + 15) / 31)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
17
normal! 0
wincmd w
argglobal
edit testing/ittennb.py
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
......@@ -51,14 +28,12 @@ setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 1 - ((0 * winheight(0) + 33) / 66)
let s:l = 1 - ((0 * winheight(0) + 34) / 68)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
1
normal! 0
wincmd w
wincmd =
tabnext 1
if exists('s:wipebuf') && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'
silent exe 'bwipe ' . s:wipebuf
......
......@@ -6,7 +6,72 @@
import cv2
import numpy as np
from .helpers import luminance
from copy import deepcopy
# subclassing numpy ndarray
# Vorgehen: https://docs.scipy.org/doc/numpy/user/basics.subclassing.html
# resize Probleme https://sourceforge.net/p/numpy/mailman/message/12594801/
# andere ownership Probleme könne angeblich mit out= gelöst werden
class Contrast(np.ndarray):
"""Core class for a color contrast in a movie
subclasses a numpy array"""
def __new__(cls, frames, input_array=None):
obj = input_array
if type(obj) == np.ndarray:
obj = np.asarray(input_array, dtype=np.uint8).view(cls).copy()
else:
input_array = np.zeros((0), dtype=np.uint8)
obj = np.asarray(input_array).view(cls).copy()
obj._frames = frames
obj._channel = 2
obj._frm_step = 50
obj._bins = 16
obj._threshold = 60000
obj._save = False
return obj
def __array_finalize__(self, obj):
if obj is None: return
self._frames = getattr(obj, '_frames', None)
self._channel = getattr(obj, '_channel', None)
self._frm_step = getattr(obj, '_frame_step', None)
self._bins = getattr(obj, '_bins', None)
self._threshold = getattr(obj, '_threshold', None)
self._save = getattr(obj, '_save', None)
def __array_wrap__(self, out_arr, context=None):
return np.ndarray.__array_wrap__(self, out_arr, context)
# TODO jetzt ausschließlich mit self numpy rechnen statt mit contrast_points liste
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)))
contrast_points = np.asarray(contrast_points, np.uint8)
shape = contrast_points.shape
self.resize(shape, refcheck=False)
self[:,:] = contrast_points
return deepcopy(self) # TODO does not create a new object
class LightDark(object):
"""representations of light/dark contrasts"""
......
#!/usr/bin/env python
#!/ur/bin/env python
# -*- coding: utf-8 -*-
from pathlib import Path # TODO wie kann ich third-party module nach außen verstecken
......@@ -7,8 +7,8 @@ from pathlib import Path # TODO wie kann ich third-party module nach außen ver
from . import helpers
from . import contrasts
# zum Problem mit privaten und öffentlichen Eigenschaften http://www.python-course.eu/python3_properties.php
# zum Problem mit privaten und öffentlichen Eigenschaften http://www.python-course.eu/python3_properties.php und 'Fluent Python' relativ weit vorne
# numpy gibt beim Versuch zB. size zu schreiben auch ein AttributeError() aus.
class Movie(object):
"""main class to interact with the colorspace of movieframes"""
def __init__(self, prefix, folder='./'): # TODO platform independent
......
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