-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimgetcircsym.c
172 lines (148 loc) · 4.78 KB
/
imgetcircsym.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
/** @file imgetcircsym.c
*/
#include <math.h>
#include "CommandLineInterface/CLIcore.h"
#include "COREMOD_memory/COREMOD_memory.h"
// ==========================================
// Forward declaration(s)
// ==========================================
imageID IMAGE_BASIC_get_circsym_component(const char *__restrict ID_name,
const char *__restrict ID_out_name,
float xcenter,
float ycenter);
// ==========================================
// Command line interface wrapper function(s)
// ==========================================
static errno_t IMAGE_BASIC_get_circsym_component_cli()
{
if(0 + CLI_checkarg(1, 4) + CLI_checkarg(2, 3) + CLI_checkarg(3, 1) +
CLI_checkarg(4, 1) ==
0)
{
IMAGE_BASIC_get_circsym_component(data.cmdargtoken[1].val.string,
data.cmdargtoken[2].val.string,
data.cmdargtoken[3].val.numf,
data.cmdargtoken[4].val.numf);
return CLICMD_SUCCESS;
}
else
{
return CLICMD_INVALID_ARG;
}
}
// ==========================================
// Register CLI command(s)
// ==========================================
errno_t __attribute__((cold)) imgetcircsym_addCLIcmd()
{
RegisterCLIcommand("imgetcircsym",
__FILE__,
IMAGE_BASIC_get_circsym_component_cli,
"extract circular symmetric part of image",
"<inim> <outim> <xcenter> <ycenter>",
"imcgetcircsym imin imout 256.0 230.5",
"long IMAGE_BASIC_get_sym_component(const char "
"*ID_name, const char *ID_out_name, float "
"xcenter, float ycenter)");
return RETURN_SUCCESS;
}
imageID IMAGE_BASIC_get_circsym_component(const char *__restrict ID_name,
const char *__restrict ID_out_name,
float xcenter,
float ycenter)
{
float step = 1.0;
imageID ID;
uint32_t naxes[2];
float distance;
float *dist;
float *mean;
float *rms;
long *counts;
long i;
long nb_step;
imageID IDout;
float ifloat, x;
ID = image_ID(ID_name);
naxes[0] = data.image[ID].md[0].size[0];
naxes[1] = data.image[ID].md[0].size[1];
nb_step = naxes[0] / 2;
dist = (float *) malloc(sizeof(float) * nb_step);
if(dist == NULL)
{
C_ERRNO = errno;
PRINT_ERROR("malloc() error");
exit(0);
}
mean = (float *) malloc(sizeof(float) * nb_step);
if(mean == NULL)
{
C_ERRNO = errno;
PRINT_ERROR("malloc() error");
exit(0);
}
rms = (float *) malloc(sizeof(float) * nb_step);
if(rms == NULL)
{
C_ERRNO = errno;
PRINT_ERROR("malloc() error");
exit(0);
}
counts = (long *) malloc(sizeof(long) * nb_step);
if(counts == NULL)
{
C_ERRNO = errno;
PRINT_ERROR("malloc() error");
exit(0);
}
for(i = 0; i < nb_step; i++)
{
dist[i] = 0;
mean[i] = 0;
rms[i] = 0;
counts[i] = 0;
}
for(uint32_t jj = 0; jj < naxes[1]; jj++)
for(uint32_t ii = 0; ii < naxes[0]; ii++)
{
distance = sqrt((1.0 * ii - xcenter) * (1.0 * ii - xcenter) +
(1.0 * jj - ycenter) * (1.0 * jj - ycenter));
i = (long)(1.0 * distance / step + 0.5);
if(i < nb_step)
{
dist[i] += distance;
mean[i] += data.image[ID].array.F[jj * naxes[0] + ii];
rms[i] += data.image[ID].array.F[jj * naxes[0] + ii] *
data.image[ID].array.F[jj * naxes[0] + ii];
counts[i] += 1;
}
}
for(i = 0; i < nb_step; i++)
{
dist[i] /= counts[i];
mean[i] /= counts[i];
rms[i] = sqrt(rms[i] - 1.0 * counts[i] * mean[i] * mean[i]) /
sqrt(counts[i]);
}
printf("%u %u\n", naxes[0], naxes[1]);
create_2Dimage_ID(ID_out_name, naxes[0], naxes[1], &IDout);
for(uint32_t jj = 0; jj < naxes[1]; jj++)
for(uint32_t ii = 0; ii < naxes[0]; ii++)
{
distance = sqrt((1.0 * ii - xcenter) * (1.0 * ii - xcenter) +
(1.0 * jj - ycenter) * (1.0 * jj - ycenter));
i = (long)(1.0 * distance / step);
ifloat = 1.0 * distance / step;
x = ifloat - i;
if((i + 1) < nb_step)
{
data.image[IDout].array.F[jj * naxes[0] + ii] =
((1.0 - x) * mean[i] + x * mean[i + 1]);
}
}
free(counts);
free(dist);
free(mean);
free(rms);
return (IDout);
}