forked from gfacciol/imgutils
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqauto.cpp
More file actions
39 lines (38 loc) · 1.09 KB
/
Copy pathqauto.cpp
File metadata and controls
39 lines (38 loc) · 1.09 KB
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
#include <stdio.h> // only for "fprintf"
#include <stdlib.h> // only for "free"
#include <stdint.h>
#include <cmath>
extern "C" {
#include "iio.h"
}
// read an image in any format from STDIN and writethe same image with 8bit range stretched to min-max
int main(int c, char *v[])
{
if (c != 3) {
fprintf(stderr, "usage:\n\t%s infile outfile\n", *v);
return 1;
}
int w, h, pd;
//uint16_t *x = iio_read_image_uint16_vec(v[1], &w, &h, &pixeldim);
float *x = iio_read_image_float_vec(v[1], &w, &h, &pd);
if (!x) {
fprintf(stderr, "failed to read an image from file "
"\"%s\"\n", v[1]);
return 1;
}
float vmin = INFINITY;
float vmax = -INFINITY;
for (int i=0;i<w*h*pd;i++) {
vmin = std::fmin(vmin,x[i]);
vmax = std::fmax(vmax,x[i]);
}
for (int i=0;i<w*h*pd;i++)
x[i] = (x[i] - vmin)*(255./(vmax-vmin));
//fprintf(stderr, "got a %dx%d image with %d channels\n", w, h, pd);
//for (int i = 0; i < pd; i++)
// fprintf(stderr, "p0: %g\n", (float)x[i]);
//iio_save_image_uint16_vec(v[2], x, w, h, pd);
iio_save_image_float_vec(v[2], x, w, h, pd);
free(x);
return 0;
}