aboutsummaryrefslogtreecommitdiffstats
path: root/src/blind-temporal-mean.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/blind-temporal-mean.c')
-rw-r--r--src/blind-temporal-mean.c60
1 files changed, 37 insertions, 23 deletions
diff --git a/src/blind-temporal-mean.c b/src/blind-temporal-mean.c
index 8c442d0..4633d75 100644
--- a/src/blind-temporal-mean.c
+++ b/src/blind-temporal-mean.c
@@ -1,7 +1,7 @@
/* See LICENSE file for copyright and license details. */
#include "common.h"
-USAGE("[-g | -h | -l power | -p power | -v]")
+USAGE("[-d | -g | -h | -l power-stream | -p power-stream | -v]")
/* TODO add [-w weight-stream] for [-ghlpv] */
/* Because the syntax for a function returning a function pointer is disgusting. */
@@ -19,24 +19,26 @@ typedef void (*process_func)(struct stream *stream, void *buffer, void *image, s
*/
#define LIST_MEANS(TYPE)\
/* [default] arithmetic mean */\
- X(ARITHMETIC, arithmetic, 1, COPY_FRAME,, *img1 += *buf,\
- a = (TYPE)1 / (TYPE)frame, *img1 *= a)\
+ X(ARITHMETIC, arithmetic, 1, COPY_FRAME,, *img += *buf,\
+ a = (TYPE)1 / (TYPE)frame, *img *= a)\
+ /* standard deviation */\
+ X(STANDARD_DEVIATION, sd, 2, ZERO_AND_PROCESS_FRAME,, (*img += *buf * *buf, *aux += *buf),\
+ a = (TYPE)1 / (TYPE)frame, *img = nnpow((*img - *aux * *aux * a) * a, (TYPE)0.5))\
/* geometric mean */\
- X(GEOMETRIC, geometric, 1, COPY_FRAME,, *img1 *= *buf,\
- a = (TYPE)1 / (TYPE)frame, *img1 = nnpow(*img1, a))\
+ X(GEOMETRIC, geometric, 1, COPY_FRAME,, *img *= *buf,\
+ a = (TYPE)1 / (TYPE)frame, *img = nnpow(*img, a))\
/* harmonic mean */\
- X(HARMONIC, harmonic, 1, ZERO_AND_PROCESS_FRAME,, *img1 += (TYPE)1 / *buf,\
- a = (TYPE)frame, *img1 = a / *img1)\
+ X(HARMONIC, harmonic, 1, ZERO_AND_PROCESS_FRAME,, *img += (TYPE)1 / *buf,\
+ a = (TYPE)frame, *img = a / *img)\
/* Lehmer mean */\
- X(LEHMER, lehmer, 2, ZERO_AND_PROCESS_FRAME, (a = (TYPE)power, b = a - (TYPE)1),\
- (*img1 += nnpow(*buf, a), *img2 += nnpow(*buf, b)),, *img1 /= *img2)\
+ X(LEHMER, lehmer, 2, ZERO_AND_PROCESS_FRAME,,\
+ (*img += nnpow(*buf, *pows), *aux += nnpow(*buf, *pows - (TYPE)1)),, *img /= *aux)\
/* power mean (Hölder mean) (m = 2 for root square mean; m = 3 for cubic mean) */\
- X(POWER, power, 1, ZERO_AND_PROCESS_FRAME, a = (TYPE)power,\
- *img1 += nnpow(*buf, a), (a = (TYPE)1 / (TYPE)frame, b = (TYPE)(1. / power)), \
- *img1 = a * nnpow(*img1, b))\
+ X(POWER, power, 1, ZERO_AND_PROCESS_FRAME,, *img += nnpow(*buf, *pows),\
+ a = (TYPE)1 / (TYPE)frame, *img = a * nnpow(*img, (TYPE)1 / *pows))\
/* variance */\
- X(VARIANCE, variance, 2, ZERO_AND_PROCESS_FRAME,, (*img1 += *buf * *buf, *img2 += *buf),\
- a = (TYPE)1 / (TYPE)frame, *img1 = (*img1 - *img2 * *img2 * a) * a)
+ X(VARIANCE, variance, 2, ZERO_AND_PROCESS_FRAME,, (*img += *buf * *buf, *aux += *buf),\
+ a = (TYPE)1 / (TYPE)frame, *img = (*img - *aux * *aux * a) * a)
enum first_frame_action {
COPY_FRAME,
@@ -48,31 +50,31 @@ enum first_frame_action {
enum method { LIST_MEANS() };
#undef X
-static double power;
+static void *powerbuf = NULL;
#define MAKE_PROCESS(PIXFMT, TYPE,\
_1, NAME, _3, _4, PRE_PROCESS, PROCESS_SUBCELL, PRE_FINALISE, FINALISE_SUBCELL)\
static void\
process_##PIXFMT##_##NAME(struct stream *stream, void *buffer, void *image, size_t frame)\
{\
- TYPE *buf = buffer, *img1 = image, a, b;\
- TYPE *img2 = (TYPE *)(((char *)image) + stream->frame_size);\
+ TYPE *buf = buffer, *img = image, a, *pows = powerbuf;\
+ TYPE *aux = (TYPE *)(((char *)image) + stream->frame_size);\
size_t x, y, z;\
if (!buf) {\
PRE_FINALISE;\
for (z = 0; z < stream->n_chan; z++)\
for (y = 0; y < stream->height; y++)\
- for (x = 0; x < stream->width; x++, img1++, img2++)\
+ for (x = 0; x < stream->width; x++, img++, aux++, pows++)\
FINALISE_SUBCELL;\
} else {\
PRE_PROCESS;\
for (z = 0; z < stream->n_chan; z++)\
for (y = 0; y < stream->height; y++)\
- for (x = 0; x < stream->width; x++, img1++, img2++, buf++) {\
+ for (x = 0; x < stream->width; x++, img++, aux++, pows++, buf++) { \
PROCESS_SUBCELL;\
}\
}\
- (void) img2, (void) a, (void) b, (void) frame;\
+ (void) aux, (void) a, (void) pows, (void) frame;\
}
#define X(...) MAKE_PROCESS(lf, double, __VA_ARGS__)
LIST_MEANS(double)
@@ -93,14 +95,18 @@ static const process_func process_functions_f[] = { LIST_MEANS() };
int
main(int argc, char *argv[])
{
- struct stream stream;
+ struct stream stream, power;
void *buf, *img;
process_func process;
size_t frames, images;
enum method method = ARITHMETIC;
enum first_frame_action first_frame_action;
+ const char *power_file = NULL;
ARGBEGIN {
+ case 'd':
+ method = STANDARD_DEVIATION;
+ break;
case 'g':
method = GEOMETRIC;
break;
@@ -109,11 +115,11 @@ main(int argc, char *argv[])
break;
case 'l':
method = LEHMER;
- power = etolf_flag('l', UARGF());
+ power_file = UARGF();
break;
case 'p':
method = POWER;
- power = etolf_flag('p', UARGF());
+ power_file = UARGF();
break;
case 'v':
method = VARIANCE;
@@ -138,6 +144,13 @@ main(int argc, char *argv[])
#undef X
eopen_stream(&stream, NULL);
+ if (power_file != NULL) {
+ eopen_stream(&power, power_file);
+ echeck_compat(&stream, &power);
+ powerbuf = emalloc(power.frame_size);
+ if (!eread_frame(&power, powerbuf))
+ eprintf("%s is no frames\n", power_file);
+ }
if (stream.encoding == DOUBLE)
process = process_functions_lf[method];
@@ -169,5 +182,6 @@ main(int argc, char *argv[])
ewriteall(STDOUT_FILENO, img, stream.frame_size, "<stdout>");
free(buf);
free(img);
+ free(powerbuf);
return 0;
}