Line | |
---|
1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | |
---|
4 | |
---|
5 | int **imatrix (long nr, long nc) { |
---|
6 | int i; |
---|
7 | int **m; |
---|
8 | |
---|
9 | m=(int **) malloc((size_t)(nr * sizeof(int *))); |
---|
10 | if (!m) { fprintf(stderr,"imatrix: allocation failure 1 \n"); exit(1); } |
---|
11 | |
---|
12 | m[0] = (int *) malloc((size_t)((nr*nc)*sizeof(int))); |
---|
13 | if (!m[0]) { fprintf(stderr,"imatrix: allocation failure 2\n"); exit(1); } |
---|
14 | |
---|
15 | for (i=1;i<nc;i++) m[i] = m[i - 1] + nc; |
---|
16 | return m; |
---|
17 | } |
---|
18 | |
---|
19 | unsigned char **ucmatrix (long nr, long nc) { |
---|
20 | int i; |
---|
21 | unsigned char **m; |
---|
22 | |
---|
23 | m=(unsigned char **) malloc((size_t)(nr * sizeof(unsigned char *))); |
---|
24 | if (!m) { fprintf(stderr,"ucmatrix: allocation failure 1 \n"); exit(1); } |
---|
25 | |
---|
26 | m[0] = (unsigned char *) malloc((size_t)((nr*nc)*sizeof(unsigned char))); |
---|
27 | if (!m[0]) { fprintf(stderr,"ucmatrix: allocation failure 2\n"); exit(1); } |
---|
28 | |
---|
29 | for (i=1;i<nc;i++) m[i] = m[i - 1] + nc; |
---|
30 | return m; |
---|
31 | } |
---|
32 | |
---|
33 | |
---|
34 | |
---|
35 | int |
---|
36 | int2uchar(int **input, unsigned char **output, int width, int height){ |
---|
37 | int x,y; |
---|
38 | double loval, hival, valrange; |
---|
39 | |
---|
40 | loval = 1e20; hival = -1e20; |
---|
41 | for(y=0;y<height;y++){ |
---|
42 | for(x=0;x<width;x++){ |
---|
43 | if (input[y][x] < loval) loval = input[y][x]; |
---|
44 | if (input[y][x] > hival) hival = input[y][x]; |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | valrange = hival - loval; |
---|
49 | |
---|
50 | for(y=0;y<height;y++){ |
---|
51 | for(x=0;x<width;x++){ |
---|
52 | if (valrange == 0.0) { |
---|
53 | output[y][x] = 0; |
---|
54 | } else { |
---|
55 | output[y][x] = (unsigned char) 255 * ((input[y][x]-loval)/valrange); |
---|
56 | } |
---|
57 | } |
---|
58 | } |
---|
59 | return 0; |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
Note: See
TracBrowser
for help on using the repository browser.