API documentation¶
Overview of all methods included in quat.
video.py¶
General video helper
-
quat.video.
advanced_pooling
(x, name, parts=3, stats=True, minimal=False)[source]¶ advanced_pooling temporal pooling method,
-
quat.video.
calc_per_second_scores
(per_frame_scores, segment_duration)[source]¶ converts per frame scores to per second scores, using mean values per second
-
quat.video.
iterate_by_frame
(video_filename, convert=True)[source]¶ iterator over all frames a video given by video_filename, if convert is true, than a conversion to uint will be performed
-
quat.video.
iterate_by_frame_two_videos
(distortedvideo, referencevideo, convert=True)[source]¶ interates over a pair of videos (distortedvideo, referencevideo) and returns pairs of frames (dis_frame, ref_frame), if convert is true, uint conversion will be performed, Important, if videos don’t have the same number of frames it will stop after min(frames(dis), frames(ref)) frames.
log.py¶
Logging helpers
parallel.py¶
Helpers for parallel processing
-
quat.parallel.
run_parallel
(items, function, arguments=[], num_cpus=8, multi_item=False)[source]¶ run a function call parallel, for each item
- Parameters
items (list) – list of items passed to function
function (function name) – function that should be applied on each item
arguments (list) – constant arguments that are passed to function
num_cpus (int) – number of cpu’s that should be used
multi_item (bool) – in case multi_item is true, it is assumed each item is a list
- Returns
- Return type
results of function performed on all items as a list
unsorted.py¶
Unsorted methods
-
quat.unsorted.
align_vectors
(x, y)[source]¶ align the length of two vectors x and y using the min length of both
-
quat.unsorted.
create_colormap
(start, mid, end, steps=256)[source]¶ creates a color map between three color points using steps intermediate colors.
-
quat.unsorted.
p_bar
(iterable, total=100)[source]¶ progress bar TODO: mark that this is an internal function
-
quat.unsorted.
powerset
(iterable)[source]¶ returns powerset of an iterable,
powerset([1,2,3]) –> () (1) (2) (3) (1,2) (1,3) (2,3) (1,2,3) from: https://stackoverflow.com/a/16915734
module ff¶
ffmpeg and ffprobe related helper
segmenting¶
Tools to segment videos
TODO: check dash_encoder.py
ffprobe¶
ffprobe related helpers
encoding¶
Collected python methods for building up automated ffmpeg commands
-
quat.ff.encoder.
analyze_video_file
(filename)[source]¶ run ffprobe to get some information of a given video file TODO: check if still required
-
quat.ff.encoder.
build_commands_to_convert_to_4k_and_lossless
(processes_video_dir, lossless_output_dir)[source]¶ - read all files in processes_video_dir and create commands to convert
to 4k resolution and lossless codec
TODO: check if still required
-
quat.ff.encoder.
build_ffmpeg_command
(pvs, output_dir)[source]¶ Creates strings out of PVS information for running a ffmpeg instances in a separate shell :param pvs: complete PVS (= dict) :return: return built string
-
quat.ff.encoder.
generic_two_pass
(inputfile, bitrate, resolution, framerate, outputfilename, profile, logfile, ffmpeg_base_command, codecsettings)[source]¶ a general two pass command building, e.g. for vp9 and h264 usable
-
quat.ff.encoder.
h264_encoding
(inputfile, bitrate, resolution, framerate, outputfilename, profile, passes, logfile, ffmpeg_base_command)[source]¶ h264 encoding
converting¶
ffmpeg methods to convert, rescale, and center crop a given video
-
quat.ff.convert.
check_ffmpeg
()[source]¶ checks if ffmpeg is installed in the system
- Returns
- Return type
true if ffmpeg can be used, otherwise an Exception is thrown
-
quat.ff.convert.
convert_to_avpvs
(input_file, tmp_folder, framerate='60/1', width=3840, height=- 2, pix_fmt='yuv422p10le')[source]¶ converts a video to a unified resolution, framerate and pixel format, can be used, e.g. in case of a full reference model, to unify a distorted video with the source video
- Parameters
input_file (str) – input video file
tmp_folder (str) – folder where converted video is stored
framerate (str) – framerate of final video
width (int) – width of final video
height (int) – height of final video, use -2 to automatically determine height based on width
pix_fmt (str) – pixel format of final video
- Returns
- Return type
filename and path of the converted video
-
quat.ff.convert.
convert_to_avpvs_and_crop
(input_file, tmp_folder, framerate='60/1', width=3840, height=- 2, pix_fmt='yuv422p10le', ccheight=360)[source]¶ converts a video to a unified resolution, framerate and pixel format and performs afterwards a center cropping can be used, e.g. in case of a full reference model, to unify a distorted video with the source video
- Parameters
input_file (str) – input video file
tmp_folder (str) – folder where converted video is stored
framerate (str) – framerate of final video
width (int) – width of final video
height (int) – height of final video, use -2 to automatically determine height based on width
pix_fmt (str) – pixel format of final video
ccheight (int) – center crop height of final crop
- Returns
- Return type
filename and path of the converted and center cropped video
recording¶
FFmpeg based screen recorder
# TODO: audio is ususally not synced
-
class
quat.ff.recorder.
Recorder
(resultfolder='tmp')[source]¶ Bases:
object
ffmpeg based screen recording
-
start
(filebasename, hardwareAcceleration=False, width=1366, height=768, fps=24, shift='')[source]¶ starts the screen record
- Parameters
filebasename (str) – basename of recording filename (will be extended by .mkv and stored in the recordfolder)
hardwareAcceleration (bool) – if true try to used hardware acceleration for intel graphics cards (TODO: experimental)
width (int) – recording width (screen resolution must be at least having this width)
height (int) – recording height
fps (int) – frames per second to record
shift (str) – ffmpeg specific shift, e.g. “+100,200” TODO: explain better
-
module ml¶
machine learning related methods
dimension visualization¶
Preparation for visualisation of high dimensial data using TSNE approach
genetic evolution¶
Genetic evolution experiments, uses multiprocessing
-
class
quat.ml.gen_alg.
GeneticEvolution
(population_size, mutation_rate, max_num_generations, individual_class, cpu_count=8, verbose=False, live_plot=True, checkpoint_folder='checkpoint', checkpoint_intervall=10)[source]¶ Bases:
object
simple base class for genetic evolution
-
class
quat.ml.gen_alg.
HelloWorld
(number_genes=10)[source]¶ Bases:
quat.ml.gen_alg.Individual
example individual class, starting from a random string, evolution will get “HelloWorld”
-
target
= array([ 7, 36, 43, 43, 46, 22, 46, 49, 43, 35])¶
-
classification/regression¶
mlcore lib for machine learning experiments, collection of regression, classification approaches
-
quat.ml.mlcore.
plot_confusion_matrix
(cm, classes, normalize=False, title='Confusion matrix', cmap=<matplotlib.colors.LinearSegmentedColormap object>, folder='figures')[source]¶ This function prints and plots the confusion matrix. Normalization can be applied by setting normalize=True.
-
quat.ml.mlcore.
plot_confusion_matrix_new
(confusion_matrix, display_labels, include_values=True, values_format=None, xticks_rotation=0, pdf=None, cmap=<matplotlib.colors.LinearSegmentedColormap object>)[source]¶ - fig = plot_confusion_matrix(
confusion_matrix=cm_norm, display_labels=[“1pass”, “2pass”], pdf=”../figures/confusion_rf_norm.pdf”
)
-
quat.ml.mlcore.
print_trees
(pipeline, feature_columns, name='trees')[source]¶ exports and creates pdf/dot files for trees that are part of the pipeline
- Parameters
pipeline (scikit learn pipeline) – needs to have named_steps[“regressor”] and named_steps[“feature_selection”] storing all data
feature_columns (list of str) – name of feature_columns
name (str) – folder name where all trees are finally stored
-
quat.ml.mlcore.
train_dummy_class
(x, y)[source]¶ trains a dummy classifier, x is feature matrix, y target classes
statistics¶
Collection of statistics methods to evauluate machine learning classification and regression.
-
quat.ml.statistics.
calc_correlations
(data, X, Y)[source]¶ Take a data frame as input and calculate ‘pearson’, ‘kendall’, ‘spearman’ correlations.
-
quat.ml.statistics.
calc_regression_metrics
(data, X, Y)[source]¶ calculates several regression metrics: r2, rmse, cohen_d, mean_absolute_error, median_absolute_error
-
quat.ml.statistics.
cos_sim
(x, y)[source]¶ calculates cosine similartiy between vector x and vector y
- Parameters
x (list/np.array) –
y (list/np.array) –
module tools¶
some useful command line tools, that are mostly independent of quat.
do_parallel.py¶
tool for running scripts parallel
example usage: $ ./do_parallel.py *.gz –script ./whatever.sh -s
the script ./whatever.sh will be called with each of the *.gz files
do_parallel_by_file.py¶
tool for running scripts parallel
example usage: $ ./do_parallel_by_file.py commands.list
where in commands.list all commandas are stored
extract_cuts.py¶
Script for automatic detection of scene cuts in a video stream
Note: specifically tuned for big bucks bunny
Authors: Serge Molina, Steve Göring
-
quat.tools.extract_cuts.
cuts_iterator
(video_filename)[source]¶ Function that takes an opencv video stream and yields cuts timing when detected The cuts detection is based on detection of peaks in the standard deviation of two successive frames
TODO: some parts can be replaced by cuts-feature inside quat
psnr.py¶
measure psnr TODO/FIXME: use quat methods, maybe remove
siti.py¶
tool to extract si ti values of a given video
Note: the extracted values are [0,1] normalized, due to a float conversion of the given video frames, if you need values in range [0,255], just multiply the extracted values by 255
-
quat.tools.siti.
extract_siti
(video)[source]¶ extracts siti values of a given video the resulting values are [0,1] scaled
- Parameters
video (str) – filename of the video that should be processed
- Returns
- Return type
dict of per frame results and filename
Examples
>>> import quat.tools.siti extract_siti >>> res = extract_siti("myvideo.mkv")
module utils¶
general utils, e.g. filesystem, os related
assertions.py¶
Collection of assertions helper.
-
quat.utils.assertions.
json_assert
(json, required_keys)[source]¶ checks if required_keys are present in json object
fileutils.py¶
Some collected and hopefully usefule methods for file handling
-
quat.utils.fileutils.
file_open
(filename, mode='r')[source]¶ Open a file (depending on the mode), and if you add bz2 or gz to filename a compressed file will be opened, file_open can replace a typical with open(filename) statement
-
quat.utils.fileutils.
get_filename_without_extension
(full_filename)[source]¶ extract the plain filename without basename and extension of a given path and full filename
-
quat.utils.fileutils.
get_files_by_extension
(base_dir, extension)[source]¶ get list of files in a base_dir with specified extension
-
quat.utils.fileutils.
get_files_by_extensions
(base_dir, extensions=[''])[source]¶ get files by a list of extensions, see get_files_by_extension
system¶
Collection of system helper functions.
TODO: unify documentation (e.g. parameters)
-
quat.utils.system.
get_shebang
(file_name)[source]¶ read shebang of a file :file_name file to open :return shebang
module visual¶
collection of image and video features
base_features.py¶
Video and image no-reference based features. Base features can also be applied for full-ref calculations, using the calc_ref_dis method.
-
class
quat.visual.base_features.
BlockMotion
[source]¶ calculates block motion of two following frames, block size is estimated by 5% of the height of the input frame, this is done to be resolution independent and faster
-
class
quat.visual.base_features.
Blockiness
[source]¶ calculate blockness of a video, assume that compression blocks have the same NxN size, where N = [8, 16, 32, 64, 128],
calculation performs the following steps, explained for N=8:
apply canny edge detection, K=[X,Y]-axis, normalized by num-rows/cols
calculate mean for all K summed values (A)
calculate for a shift (0,7) and for every 8th value of the K summed values the mean (B) - all shifts will be considered, and only the one with max_mean value is used
assume that the distribution should differe, if blocks are there
difference of A, and B is then the feature value
overall blockiness value – per frame:
value = \(\sqrt{(|x\_mean\_diff \cdot y\_mean\_diff | / 2^{(|max\_shift_x - max\_shift_y|/N)}}\)
-
class
quat.visual.base_features.
CuboidCol
(col)[source]¶ Motion estimation using a window of 60 frames and a cuboid video of the video, handles only columns of the frames
-
class
quat.visual.base_features.
CuboidRow
(row)[source]¶ Motion estimation using a window of 60 frames and a cuboid video of the video, handles only rows of the frames
-
class
quat.visual.base_features.
CutDetectionFeatures
[source]¶ Estimates scene cuts of a given video (approximation), implemented by Serge Molina
-
class
quat.visual.base_features.
Feature
[source]¶ abstract base class for all features, handles automatic storage and loading of calculated feature values
-
calc_ref_dis
(dframe, rframe)[source]¶ performs a full-ref style calculation, where the resulting features are calculated on both frames, and further difference values are stored,
-
-
class
quat.visual.base_features.
ImageFeature
(img_f)[source]¶ a generic image feature class, ususally all methods implemented in quat.visual.images can be passes as argument in the constructor
-
class
quat.visual.base_features.
MovementFeatures
[source]¶ Calculates movement feature, using background removement, based on master thesis of julian zebelein
-
class
quat.visual.base_features.
SiFeatures
[source]¶ Calculates SI values of a video frame important: SI values are finally in a 0..1 range, due to float conversion
-
class
quat.visual.base_features.
StrredNoRefFeatures
[source]¶ calculate entropy of subbands, with the feature that is used in strred, however, this feature does not consider a reference video, it justs calculates mean of spatial and temporal features of strred
-
class
quat.visual.base_features.
TemporalFeatures
[source]¶ A temporal feature, using RMSE of consecutive frames, somehow similar to TI, but not applied on gray frames
fullref.py¶
Full reference features.
All full-reference features share a common interface, e.g. in case of SSIM,
...
ssim = SSIM()
v = ssim.calc_ref_dis(dis_frame, ref_frame)
# will return the calculated ssim value in `v`
TODO: add references to metrics
-
class
quat.visual.fullref.
FramerateEstimator
[source]¶ based on frame differences of src and distorted video estimate framerate of distorted video
TODO: check: could be also an no-reference feature
-
class
quat.visual.fullref.
ResolutionSimilarities
[source]¶ Tries to estimate resolution of the distorted video
image¶
Purely image based features
-
quat.visual.image.
calc_blur_features
(frame, debug=False)[source]¶ estimates blurriness using Laplacian filter,
based on julian zebelein’s master thesis
-
quat.visual.image.
calc_brisque_features
(image, gray=False)[source]¶ calcualte brisque no-reference features,
References
scikit-video
Mittal, A. K. Moorthy and A. C. Bovik, “No-Reference Image Quality Assessment in the Spatial Domain” In: IEEE Transactions on Image Processing, 2012.
Mittal, A. K. Moorthy and A. C. Bovik, “Referenceless Image Spatial Quality Evaluation Engine,” In: 45th Asilomar Conference on Signals, Systems and Computers , November 2011.
-
quat.visual.image.
calc_contrast_features
(frame)[source]¶ calculates contrast based on histogram equalization,
based on julan zebelein’s master thesis
-
quat.visual.image.
calc_fft_features
(frame, debug=False)[source]¶ calculates fft feature,
based on julan zebelein’s master thesis
References
I. Katsavounidis et al. “Native resolution detection of video sequences”. In: Annual Technical Conference and Exhibition, SMPTE 2015. SMPTE. 2015, pp. 1–20.
-
quat.visual.image.
calc_niqe_features
(image, gray=False)[source]¶ calculate niqe features
References
scikit-video
Mittal, Anish, Rajiv Soundararajan, and Alan C. Bovik. “Making a ‘completely blind’ image quality analyzer.” In: IEEE Signal Processing Letters 20.3 (2013): 209-212.
-
quat.visual.image.
calc_noise
(frame)[source]¶ calcualtes noise std based on skimage.restoration.estimate_sigma “Robust wavelet-based estimator of the (Gaussian) noise standard deviation.”
- Returns
- Return type
mean value of all channels for std value of noise assuming that the noise has a Gaussian distribution
-
quat.visual.image.
calc_saturation_features
(frame, debug=True)[source]¶ calculates saturation of a given image,
re-implemented by Serge Molina
References
T. O. Aydın, A. Smolic, and M. Gross. “Automated aesthetic analysis of photographic images”. In: IEEE transactions on visualization and computer graphics 21.1 2015, pp. 31–42.””
-
quat.visual.image.
calc_tone_features
(image, gray=False)[source]¶ calculate tone feature,
re-implemented by Serge Molina
References
T. O. Aydın, A. Smolic, and M. Gross. “Automated aesthetic analysis of photographic images”. In: IEEE transactions on visualization and computer graphics 21.1 (2015), pp. 31–42.
-
quat.visual.image.
ceiq
(image, gray=False)[source]¶ re-implemented and extended version of https://github.com/mtobeiyf/CEIQ/blob/master/CEIQ.m features for “No-Reference Quality Assessment of Contrast-Distorted Images using Contrast Enhancement”
References
Jia Yan, Jie Li, Xin Fu: “No-Reference Quality Assessment of Contrast-Distorted Images using Contrast Enhancement”, In: Journal of Visual Communication and Image Representation, 2018
-
quat.visual.image.
color_fulness_features
(image_rgb)[source]¶ calculates color fullness
re-implementated by Serge Molina
References
Hasler, David, and Sabine E. Suesstrunk. “Measuring colorfulness in natural images.” In: Human vision and electronic imaging VIII. Vol. 5007. International Society for Optics and Photonics, 2003.
sseq¶
Re-implementation of sseq features based on matlab version and the research paper, see
References
Lixiong Liu, Bao Liu, Hua Huang, and Alan Conrad Bovik, “No-reference Image Quality Assessment Based on Spatial and Spectral Entropies”, In: Signal Processing: Image Communication, Vol. 29, No. 8, pp. 856-863, Sep. 2014.
Lixiong Liu, Bao Liu, Hua Huang, and Alan Conrad Bovik, “SSEQ Software Release”, URL: http://live.ece.utexas.edu/research/quality/SSEQ_release.zip, 2014
-
quat.visual.sseq.
calc_sseq_features
(image, scale=3, gray=False)[source]¶ calculate sseq features of an images with several scales
vifp – CHECK¶
Other Video Quality Metrics¶
For other video quality metrics or methods see scikit-video or sporco