-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_transform_stokes.c
68 lines (47 loc) · 1.66 KB
/
test_transform_stokes.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
65
66
67
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#define CCOMPASS_IMPLEMENTATION
#include "ccompass.h"
int main(int argc, char *argv[]) {
if(argc != 2) {
fprintf(stderr, "usage: %s [filepath]", argv[0]);
return 1;
}
const char *filepath = argv[1];
printf("loading %s...\n", filepath);
int img_w, img_h, img_n;
unsigned char *data = stbi_load(filepath, &img_w, &img_h, &img_n, 1); // n=1 to enforce greyscale
if(data == NULL) {
fprintf(stderr, "failed: %s\n", stbi_failure_reason());
return 1;
}
printf("successfully loaded image with w=%d h=%d n=%d\n", img_w, img_h, img_n);
int w = img_w/2, h = img_h/2;
struct cc_stokes *stokes_vectors;
stokes_vectors = (struct cc_stokes*) malloc(sizeof(struct cc_stokes) * w * h);
cc_compute_stokes(data, stokes_vectors, w, h);
stbi_image_free(data);
double *aolps;
aolps = (double*) malloc(sizeof(double) * w * h);
cc_transform_stokes(stokes_vectors, w, h);
cc_compute_aolp(stokes_vectors, aolps, w, h);
// unsigned char *data;
data = (unsigned char*) malloc(sizeof(unsigned char) * w * h * 4);
cc_compute_cmap(aolps, w * h, -M_PI / 2.0, M_PI / 2.0, (struct cc_color*) data);
int err;
err = stbi_write_png("test_transform_stokes.png", w, h, 4, data, 0);
if(err == 0) {
fprintf(stderr, "failed: %s\n", stbi_failure_reason());
return 1;
}
free(stokes_vectors);
free(aolps);
free(data);
return 0;
}