| 1 | /* |
| 2 | * localmotion2transform.h |
| 3 | * |
| 4 | * Copyright (C) Georg Martius - January 2013 |
| 5 | * georg dot martius at web dot de |
| 6 | * |
| 7 | * This file is part of vid.stab video stabilization library |
| 8 | * |
| 9 | * vid.stab is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License, |
| 11 | * as published by the Free Software Foundation; either version 2, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * vid.stab is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with GNU Make; see the file COPYING. If not, write to |
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #ifndef __LOCALMOTION2TRANSFORM_H |
| 26 | #define __LOCALMOTION2TRANSFORM_H |
| 27 | |
| 28 | |
| 29 | #include "transform.h" |
| 30 | #include "transformtype.h" |
| 31 | #include "serialize.h" |
| 32 | |
| 33 | |
| 34 | /** converts for each frame the localmotions into a transform |
| 35 | */ |
| 36 | int vsLocalmotions2Transforms(VSTransformData* td, |
| 37 | const VSManyLocalMotions* motions, |
| 38 | VSTransformations* trans ); |
| 39 | |
| 40 | /** calculates rotation angle for the given transform and |
| 41 | * field with respect to the given center-point |
| 42 | */ |
| 43 | double vsCalcAngle(const LocalMotion* lm, int center_x, int center_y); |
| 44 | |
| 45 | /** calculates the transformation that caused the observed motions. |
| 46 | Using a simple cleaned-means approach to eliminate outliers. |
| 47 | translation and rotation is calculated. |
| 48 | calculate shift as cleaned mean of all local motions |
| 49 | calculate rotation angle of each field in respect to center of fields |
| 50 | after shift removal |
| 51 | calculate rotation angle as cleaned mean of all angles |
| 52 | compensate for possibly off-center rotation |
| 53 | */ |
| 54 | VSTransform vsSimpleMotionsToTransform(VSFrameInfo fi, const char* modname, |
| 55 | const LocalMotions* motions); |
| 56 | |
| 57 | |
| 58 | /** calculates the transformation that caused the observed motions. |
| 59 | Using a gradient descent algorithm. |
| 60 | Outliers are removed by repeated gaussianizing error distribution. |
| 61 | (File for exporting transforms) |
| 62 | */ |
| 63 | VSTransform vsMotionsToTransform(VSTransformData* td, |
| 64 | const LocalMotions* motions, |
| 65 | FILE* f); |
| 66 | |
| 67 | |
| 68 | |
| 69 | /** general purpose gradient descent algorithm |
| 70 | |
| 71 | * Parameters: |
| 72 | * eval: evaluation function (value/energy to be minimized) |
| 73 | * params: initial starting parameters |
| 74 | * dat: custom data for eval function |
| 75 | * N: number of iterations (100) |
| 76 | * stepsizes: stepsizes for each dimension of the gradient {0.1,0.1...} (will be deleted) |
| 77 | * threshold: value below which the value/energy is considered to be minimized (0) |
| 78 | * residual: residual value (call by reference) (can be NULL) |
| 79 | * Return Value: |
| 80 | * Optimized parameters |
| 81 | */ |
| 82 | VSArray vsGradientDescent(double (*eval)(VSArray, void*), |
| 83 | VSArray params, void* dat, |
| 84 | int N, VSArray stepsizes, double threshold, double* residual); |
| 85 | |
| 86 | #endif |