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

add simple package structure

reference implementation for Movie, Frames class
scatterplot contrast without plot as function in contrasts module
helper functions in helpers module
parent bcfd1527
let SessionLoad = 1
let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0
let v:this_session=expand("<sfile>:p")
silent only
cd ~/Research/Projects/Cinemetrics/Itten
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
let s:wipebuf = bufnr('%')
endif
set shortmess=aoO
badd +60 testing/ittennb.py
badd +17 itten/movie.py
badd +25 itten/contrasts.py
badd +16 itten/helpers.py
badd +1023 term://.//20282:/usr/bin/zsh\ ;\#neoterm-1
argglobal
silent! argdel *
edit itten/movie.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={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 1 - ((0 * winheight(0) + 33) / 66)
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
endif
unlet! s:wipebuf
set winheight=1 winwidth=20 shortmess=filnxtToO
let s:sx = expand("<sfile>:p:r")."x.vim"
if file_readable(s:sx)
exe "source " . fnameescape(s:sx)
endif
let &so = s:so_save | let &siso = s:siso_save
let g:this_session = v:this_session
let g:this_obsession = v:this_session
let g:this_obsession_status = 2
doautoall SessionLoadPost
unlet SessionLoad
" vim: set ft=vim :
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# TODO import as cv
import cv2
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
def timelabels(val, pos):
min, sec = divmod(int(val), 60)
timelabel = "{0}:{1:02d}".format(min, sec)
return timelabel
# In[6]:
def luminance(img):
# Luminance Faktoren nach http://introcs.cs.princeton.edu/python/31datatype/luminance.py.html
luminance_factors = np.array([.299, .587, .114])
# Erzeugung eines eindimensionalen Arrays für die effizientere Berechnung
_img = img.reshape((img.shape[0]*img.shape[1]), img.shape[2])
_img = np.multiply(_img, luminance_factors)
# addiert alle Werte auf einer bestimmten Achse
luminances = np.sum(_img, axis=1)
return luminances
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pathlib import Path # TODO wie kann ich third-party module nach außen verstecken
# TODO Ist der import aus dem selben Pakte so korrekt?
from . import helpers
from . import contrasts
class Movie(object):
"""main class to interact with the colorspace of movieframes"""
def __init__(self, prefix, folder='./'): # TODO platform independent
self.frames = Frames(folder, prefix)
def scatterpoints(self, channel):
contrast = contrasts.mono_ctrst_scatplt(1, self.frames)
return contrast
class Frames(object):
# TODO wie ist das bei Python mit getters und setters, gibt es eine elegantere Lösung
"""Parses movie frames properties"""
def __init__(self, folder, prefix, start=1, end=0):
self.folder = folder
self.prefix = prefix
self.frames = self.get_frame_list()
self.frm_length = self.count_total_frames()
self.start = start
self.end = self._get_end_frame(end)
self.frm_cnt = self.count_frames()
def get_frame_list(self):
frm_path = Path(self.folder)
return list(frm_path.glob('*.png'))
def count_total_frames(self):
return len(self.frames)
def count_frames(self):
return self.end - (self.start - 1)
def _get_end_frame(self, end):
if end == 0:
return self.frm_length
else:
return end
This diff is collapsed.
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