-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimstretch.c
174 lines (149 loc) · 5.37 KB
/
imstretch.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/** @file imstretch.c
*/
#include <math.h>
#include "CommandLineInterface/CLIcore.h"
#include "COREMOD_arith/COREMOD_arith.h"
#include "COREMOD_memory/COREMOD_memory.h"
imageID basic_stretch(const char *__restrict name_in,
const char *__restrict name_out,
float coeff,
long Xcenter,
long Ycenter)
{
uint32_t naxes[2];
imageID IDin;
imageID IDout;
long i, j;
IDin = image_ID(name_in);
naxes[0] = data.image[IDin].md[0].size[0];
naxes[1] = data.image[IDin].md[0].size[1];
create_2Dimage_ID(name_out, naxes[0], naxes[1], &IDout);
for(uint32_t ii = 0; ii < naxes[0]; ii++)
for(uint32_t jj = 0; jj < naxes[0]; jj++)
{
i = Xcenter + (long)(1.0 * (ii - Xcenter) * coeff);
j = Ycenter + (long)(1.0 * (jj - Ycenter) * coeff);
if((i < naxes[0]) && (j < naxes[1]) && (i > -1) && (j > -1))
{
data.image[IDout].array.F[jj * naxes[0] + ii] +=
data.image[IDin].array.F[j * naxes[0] + i] / coeff / coeff;
}
}
arith_image_cstmult_inplace(name_out,
arith_image_total(name_in) /
arith_image_total(name_out));
return IDout;
}
imageID basic_stretch_range(const char *__restrict name_in,
const char *__restrict name_out,
float coeff1,
float coeff2,
long Xcenter,
long Ycenter,
long NBstep,
float ApoCoeff)
{
DEBUG_TRACE_FSTART();
// ApoCoeff should be between 0 and 1
uint32_t naxes[2];
imageID IDin, IDout;
long i, j;
float coeff;
long step;
float mcoeff;
float x, y;
float eps = 1.0e-5;
float u, t, tmp;
IDin = image_ID(name_in);
naxes[0] = data.image[IDin].md[0].size[0];
naxes[1] = data.image[IDin].md[0].size[1];
FUNC_CHECK_RETURN(create_2Dimage_ID(name_out, naxes[0], naxes[1], &IDout));
for(step = 0; step < NBstep; step++)
{
fprintf(stdout, ".");
fflush(stdout);
coeff = coeff1 + (coeff2 - coeff1) * (1.0 * step / (NBstep - 1));
x = (coeff - (coeff1 + coeff2) / 2.0) / ((coeff2 - coeff1) / 2.0);
// x goes from -1 to 1
if(ApoCoeff > eps)
{
mcoeff =
pow((1.0 - pow((fabs(x) - (1.0 - ApoCoeff)) / ApoCoeff, 2.0)),
4.0);
}
else
{
mcoeff = 1.0;
}
if((1.0 - x * x) < eps)
{
mcoeff = 0.0;
}
if(fabs(x) < ApoCoeff)
{
mcoeff = 1.0;
}
// fprintf(stdout,"(%f %f %f %f %f)",coeff,coeff1,coeff2,x,mcoeff);
for(uint32_t ii = 0; ii < naxes[0]; ii++)
for(uint32_t jj = 0; jj < naxes[1]; jj++)
{
x = (1.0 * (ii - Xcenter) * coeff) + Xcenter;
y = (1.0 * (jj - Ycenter) * coeff) + Ycenter;
i = (long) x;
j = (long) y;
u = x - i;
t = y - j;
if((i < naxes[0] - 1) && (j < naxes[1] - 1) && (i > -1) &&
(j > -1))
{
tmp = (1.0 - u) * (1.0 - t) *
data.image[IDin].array.F[j * naxes[0] + i];
tmp += (1.0 - u) * t *
data.image[IDin].array.F[(j + 1) * naxes[0] + i];
tmp += u * (1.0 - t) *
data.image[IDin].array.F[j * naxes[0] + i + 1];
tmp += u * t *
data.image[IDin].array.F[(j + 1) * naxes[0] + i + 1];
data.image[IDout].array.F[jj * naxes[0] + ii] +=
mcoeff * tmp / coeff / coeff;
}
}
}
fprintf(stdout, "\n");
arith_image_cstmult_inplace(name_out,
arith_image_total(name_in) /
arith_image_total(name_out));
DEBUG_TRACE_FEXIT();
return IDout;
}
imageID basic_stretchc(const char *__restrict name_in,
const char *__restrict name_out,
float coeff)
{
DEBUG_TRACE_FSTART();
uint32_t naxes[2];
imageID IDin;
imageID IDout;
long i, j;
long Xcenter, Ycenter;
IDin = image_ID(name_in);
naxes[0] = data.image[IDin].md[0].size[0];
naxes[1] = data.image[IDin].md[0].size[1];
Xcenter = naxes[0] / 2;
Ycenter = naxes[1] / 2;
FUNC_CHECK_RETURN(create_2Dimage_ID(name_out, naxes[0], naxes[1], &IDout));
for(uint32_t ii = 0; ii < naxes[0]; ii++)
for(uint32_t jj = 0; jj < naxes[0]; jj++)
{
i = Xcenter + (long)(1.0 * (ii - Xcenter) * coeff);
j = Ycenter + (long)(1.0 * (jj - Ycenter) * coeff);
if((i < naxes[0]) && (j < naxes[1]) && (i > -1) && (j > -1))
{
data.image[IDout].array.F[jj * naxes[0] + ii] +=
data.image[IDin].array.F[j * naxes[0] + i] / coeff / coeff;
}
}
/* basic_mult(name_out,arith_image_total(name_in)/arith_image_total(name_out));*/
DEBUG_TRACE_FEXIT();
return IDout;
}