forked from mnhrdt/imscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcdeint.c
64 lines (57 loc) · 1.65 KB
/
cdeint.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <stdlib.h>
#include "iio.h"
// deinterlace and produce two images
int main(int c, char *v[])
{
if (c != 4) {
fprintf(stderr, "usage:\n\t%s in out1 out2\n", *v);
// 0 1 2 3
return EXIT_FAILURE;
}
int w, h, pd;
void *xx = iio_read_image_float_vec(v[1], &w, &h, &pd);
float (*x)[w][pd] = xx;
float (*y)[w][pd] = calloc(w*h*pd,sizeof(float));
float (*z)[w][pd] = calloc(w*h*pd,sizeof(float));
for (int j = 1; j < h; j += 2) {
for (int i = 0; i < w; i++)
for (int l = 0; l < pd; l++)
z[j][i][l] = x[j][i][l];
if (j+2 < h)
for (int i = 0; i < w; i++)
for (int l = 0; l < pd; l++)
z[j+1][i][l] = (x[j][i][l] + x[j+2][i][l])/2;
}
for (int j = 0; j < h; j += 2) {
for (int i = 0; i < w; i++)
for (int l = 0; l < pd; l++)
y[j][i][l] = x[j][i][l];
if (j+2 < h)
for (int i = 0; i < w; i++)
for (int l = 0; l < pd; l++)
y[j+1][i][l] = (x[j][i][l] + x[j+2][i][l])/2;
}
// the other way to interpet it:
// for (int j = 0; j < h-1; j += 2) {
// for (int i = 0; i < w; i++)
// for (int l = 0; l < pd; l++)
// z[j][i][l] = x[j+1][i][l];
// if (j+3 < h)
// for (int i = 0; i < w; i++)
// for (int l = 0; l < pd; l++)
// z[j+1][i][l] = (x[j+1][i][l] + x[j+3][i][l])/2;
// }
// for (int j = 0; j < h; j += 2) {
// for (int i = 0; i < w; i++)
// for (int l = 0; l < pd; l++)
// y[j][i][l] = x[j][i][l];
// if (j+2 < h)
// for (int i = 0; i < w; i++)
// for (int l = 0; l < pd; l++)
// y[j+1][i][l] = (x[j][i][l] + x[j+2][i][l])/2;
// }
iio_save_image_float_vec(v[2], y[0][0], w, h, pd);
iio_save_image_float_vec(v[3], z[0][0], w, h, pd);
return EXIT_SUCCESS;
}