-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage_to_vec.c
190 lines (163 loc) · 5.01 KB
/
image_to_vec.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include "CommandLineInterface/CLIcore.h"
// Local variables pointers
static char *inimname;
static char *inpixiname;
static char *inpixmultname;
static char *outvecname;
static CLICMDARGDEF farg[] = {{
CLIARG_IMG,
".inim",
"input image",
"im",
CLIARG_VISIBLE_DEFAULT,
(void **) &inimname,
NULL
},
{
CLIARG_IMG,
".inpixi",
"input pixel index image",
"pixi",
CLIARG_VISIBLE_DEFAULT,
(void **) &inpixiname,
NULL
},
{
CLIARG_IMG,
".inpixmult",
"input pixel mult image",
"pixmult",
CLIARG_VISIBLE_DEFAULT,
(void **) &inpixmultname,
NULL
},
{
CLIARG_STR,
".outvec",
"output vector image",
"vecim",
CLIARG_VISIBLE_DEFAULT,
(void **) &outvecname,
NULL
}
};
static CLICMDDATA CLIcmddata =
{
"im2vec", "remap image to vector", CLICMD_FIELDS_DEFAULTS
};
// detailed help
static errno_t help_function()
{
return RETURN_SUCCESS;
}
//
//
//
errno_t linopt_imtools_image_to_vec(const char *__restrict ID_name,
const char *__restrict IDpixindex_name,
const char *__restrict IDpixmult_name,
const char *__restrict IDvec_name,
imageID *outID)
{
DEBUG_TRACE_FSTART();
DEBUG_TRACEPOINT("FARG %s %s %s %s",
ID_name,
IDpixindex_name,
IDpixmult_name,
IDvec_name);
imageID ID;
imageID IDpixindex, IDpixmult;
imageID IDvec;
long NBpix;
long naxisin;
long sizexy;
uint8_t datatype;
ID = image_ID(ID_name);
naxisin = data.image[ID].md[0].naxis;
datatype = data.image[ID].md[0].datatype;
IDpixindex = image_ID(IDpixindex_name);
IDpixmult = image_ID(IDpixmult_name);
NBpix = data.image[IDpixindex].md[0].nelement;
if(naxisin < 3)
{
FUNC_CHECK_RETURN(create_2Dimage_ID(IDvec_name, NBpix, 1, &IDvec));
for(long k = 0; k < NBpix; k++)
{
data.image[IDvec].array.F[k] =
data.image[IDpixmult].array.F[k] *
data.image[ID].array.F[data.image[IDpixindex].array.SI64[k]];
}
}
else
{
sizexy = data.image[ID].md[0].size[0] * data.image[ID].md[0].size[1];
if(datatype == _DATATYPE_FLOAT)
{
FUNC_CHECK_RETURN(create_2Dimage_ID(IDvec_name,
NBpix,
data.image[ID].md[0].size[2],
&IDvec));
for(uint32_t kk = 0; kk < data.image[ID].md[0].size[2]; kk++)
for(long k = 0; k < NBpix; k++)
{
data.image[IDvec].array.F[kk * NBpix + k] =
data.image[IDpixmult].array.F[k] *
data.image[ID]
.array.F[kk * sizexy +
data.image[IDpixindex].array.SI64[k]];
}
}
if(datatype == _DATATYPE_COMPLEX_FLOAT)
{
FUNC_CHECK_RETURN(create_2Dimage_ID(IDvec_name,
NBpix * 2,
data.image[ID].md[0].size[2],
&IDvec));
for(uint32_t kk = 0; kk < data.image[ID].md[0].size[2]; kk++)
for(long k = 0; k < NBpix; k++)
{
data.image[IDvec].array.F[kk * NBpix * 2 + 2 * k] =
data.image[IDpixmult].array.F[k] *
data.image[ID]
.array
.CF[kk * sizexy +
data.image[IDpixindex].array.SI64[k]]
.re;
data.image[IDvec].array.F[kk * NBpix * 2 + 2 * k + 1] =
data.image[IDpixmult].array.F[k] *
data.image[ID]
.array
.CF[kk * sizexy +
data.image[IDpixindex].array.SI64[k]]
.im;
}
}
}
if(outID != NULL)
{
*outID = IDvec;
}
DEBUG_TRACE_FEXIT();
return RETURN_SUCCESS;
}
static errno_t compute_function()
{
DEBUG_TRACE_FSTART();
INSERT_STD_PROCINFO_COMPUTEFUNC_START
linopt_imtools_image_to_vec(inimname,
inpixiname,
inpixmultname,
outvecname,
NULL);
INSERT_STD_PROCINFO_COMPUTEFUNC_END
DEBUG_TRACE_FEXIT();
return RETURN_SUCCESS;
}
INSERT_STD_FPSCLIfunctions
// Register function in CLI
errno_t
CLIADDCMD_linopt_imtools__image_to_vec()
{
INSERT_STD_CLIREGISTERFUNC
return RETURN_SUCCESS;
}