-
Notifications
You must be signed in to change notification settings - Fork 1
/
mask_to_pixtable.c
157 lines (128 loc) · 3.67 KB
/
mask_to_pixtable.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
#include "CommandLineInterface/CLIcore.h"
// Local variables pointers
// Local variables pointers
static char *inimname;
static char *outpixiimname;
static char *outpixmimname;
static CLICMDARGDEF farg[] = {{
CLIARG_IMG,
".inim",
"input image",
"",
CLIARG_VISIBLE_DEFAULT,
(void **) &inimname,
NULL
},
{
CLIARG_STR,
".outpixi",
"output index image",
"out1",
CLIARG_VISIBLE_DEFAULT,
(void **) &outpixiimname,
NULL
},
{
CLIARG_STR,
".outpixm",
"output mask image",
"out1",
CLIARG_VISIBLE_DEFAULT,
(void **) &outpixmimname,
NULL
}
};
static CLICMDDATA CLIcmddata =
{
"mask2pixtable", "make pixel tables from mask", CLICMD_FIELDS_DEFAULTS
};
// detailed help
static errno_t help_function()
{
return RETURN_SUCCESS;
}
// Maps image to array of pixel values using mask
// to decompose image into modes:
// STEP 1: create index and mult tables (linopt_imtools_mask_to_pixtable)
//
errno_t linopt_imtools_mask_to_pixtable(const char *IDmask_name,
const char *IDpixindex_name,
const char *IDpixmult_name,
long *outNBpix)
{
DEBUG_TRACE_FSTART();
long NBpix;
imageID ID;
long size;
float eps = 1.0e-8;
long k;
uint32_t *sizearray;
imageID IDpixindex, IDpixmult;
ID = image_ID(IDmask_name);
size = data.image[ID].md[0].nelement;
NBpix = 0;
for(long ii = 0; ii < size; ii++)
if(data.image[ID].array.F[ii] > eps)
{
NBpix++;
}
sizearray = (uint32_t *) malloc(sizeof(uint32_t) * 2);
if(sizearray == NULL)
{
FUNC_RETURN_FAILURE("malloc returns NULL pointer");
}
sizearray[0] = NBpix;
sizearray[1] = 1;
FUNC_CHECK_RETURN(create_image_ID(IDpixindex_name,
2,
sizearray,
_DATATYPE_INT64,
0,
0,
0,
&IDpixindex));
FUNC_CHECK_RETURN(create_image_ID(IDpixmult_name,
2,
sizearray,
_DATATYPE_FLOAT,
0,
0,
0,
&IDpixmult));
free(sizearray);
k = 0;
for(long ii = 0; ii < size; ii++)
if(data.image[ID].array.F[ii] > eps)
{
data.image[IDpixindex].array.SI64[k] = ii;
data.image[IDpixmult].array.F[k] = data.image[ID].array.F[ii];
k++;
}
// printf("%ld active pixels in mask %s\n", NBpix, IDmask_name);
if(outNBpix != NULL)
{
*outNBpix = NBpix;
}
DEBUG_TRACE_FEXIT();
return RETURN_SUCCESS;
}
static errno_t compute_function()
{
DEBUG_TRACE_FSTART();
INSERT_STD_PROCINFO_COMPUTEFUNC_START
linopt_imtools_mask_to_pixtable(inimname,
outpixiimname,
outpixmimname,
NULL);
INSERT_STD_PROCINFO_COMPUTEFUNC_END
DEBUG_TRACE_FEXIT();
return RETURN_SUCCESS;
}
INSERT_STD_FPSCLIfunctions
// Register function in CLI
errno_t
CLIADDCMD_linopt_imtools__mask_to_pixtable()
{
INSERT_STD_CLIREGISTERFUNC
return RETURN_SUCCESS;
}