18 #ifndef PIC_UTIL_MASK_HPP 19 #define PIC_UTIL_MASK_HPP 21 #include "../base.hpp" 22 #include "../util/math.hpp" 23 #include "../util/buffer.hpp" 39 int width,
int height)
46 dataOut =
new bool[width * height];
49 #pragma omp parallel for 51 for(
int i = 0; i < height; i++) {
54 for(
int j = 0; j < width; j++) {
59 for(
int k = -1; k <= 1; k++) {
60 int ci =
CLAMP((i + k), height) * width;
62 for(
int l = -1; l <= 1; l++) {
63 if((l != 0) && (k != 0)) {
64 int cj =
CLAMP((j + l), width);
73 dataOut[c] = counter > 0;
89 static bool *
erode(
bool *dataOut,
bool *dataIn,
int width,
int height,
97 dataOut =
new bool[width * height];
100 int halfKernelSize = kernelSize >> 1;
102 #pragma omp parallel for 104 for(
int i = 0; i < height; i++) {
107 for(
int j = 0; j < width; j++) {
112 for(
int k = -halfKernelSize; k <= halfKernelSize; k++) {
113 int ci =
CLAMP((i + k), height) * width;
115 for(
int l = -halfKernelSize; l <= halfKernelSize; l++) {
116 int cj =
CLAMP((j + l), width);
117 out = out || (!dataIn[ci + cj]);
137 static bool *
dilate(
bool *dataOut,
bool *dataIn,
int width,
int height,
144 if(dataOut == NULL) {
145 dataOut =
new bool[width * height];
148 int halfKernelSize = kernelSize >> 1;
150 #pragma omp parallel for 152 for(
int i = 0; i < height; i++) {
155 for(
int j = 0; j < width; j++) {
160 for(
int k = -halfKernelSize; k <= halfKernelSize; k++) {
161 int ci =
CLAMP((i + k), height) * width;
163 for(
int l = -halfKernelSize; l <= halfKernelSize; l++) {
164 int cj =
CLAMP((j + l), width);
165 out = out || (dataIn[ci + cj]);
183 static bool empty(
bool *dataIn,
int width,
int height)
189 for(
int i = 0; i < height; i++) {
192 for(
int j = 0; j < width; j++) {
193 if(dataIn[ind + j]) {
209 static bool*
thinning(
bool *dataOut,
bool *dataIn,
int width,
int height)
215 dataOut =
clone(dataOut, dataIn, width * height, 1);
220 std::vector< int > list;
221 for(
int i = 1; i < (height - 1); i++) {
223 for(
int j = 1; j < (width - 1); j++) {
226 if(!dataOut[index]) {
230 P[0] = dataOut[index];
231 P[1] = dataOut[index + 1];
232 P[2] = dataOut[index - width + 1];
233 P[3] = dataOut[index - width];
234 P[4] = dataOut[index - width - 1];
235 P[5] = dataOut[index - 1];
236 P[6] = dataOut[index + width - 1];
237 P[7] = dataOut[index + width];
238 P[8] = dataOut[index + width + 1];
243 for(
int k = 1; k <= 4; k++) {
245 bool x_2km1 = P[k_2 - 1];
247 bool x_2kp1 = P[k_2 + 1];
249 if( !x_2km1 && (x_2k || x_2kp1) ) {
262 int min_12 =
MIN(n1, n2);
264 bool G1 = (X_h == 1);
265 bool G2 = (min_12 > 1) && (min_12 < 4);
266 bool G3 = P[1] && ( P[2] || P[3] || !P[8]);
269 list.push_back(index);
275 for(
unsigned int i = 0; i < list.size(); i++) {
276 dataOut[list[i]] =
false;
281 for(
int i = 1; i < (height - 1); i++) {
283 for(
int j = 1; j < (width - 1); j++) {
286 if(!dataOut[index]) {
290 P[0] = dataOut[index];
291 P[1] = dataOut[index + 1];
292 P[2] = dataOut[index - width + 1];
293 P[3] = dataOut[index - width];
294 P[4] = dataOut[index - width - 1];
295 P[5] = dataOut[index - 1];
296 P[6] = dataOut[index + width - 1];
297 P[7] = dataOut[index + width];
298 P[8] = dataOut[index + width + 1];
303 for(
int k = 1; k <= 4; k++) {
305 bool x_2km1 = P[k_2 - 1];
307 bool x_2kp1 = P[k_2 + 1];
309 if( !x_2km1 && (x_2k || x_2kp1) ) {
322 int min_12 =
MIN(n1, n2);
324 bool G1 = (X_h == 1);
325 bool G2 = (min_12 > 1) && (min_12 < 4);
326 bool G3 = P[5] && (P[6] || P[7] || !P[4]);
329 list.push_back(index);
335 for(
unsigned int i = 0; i < list.size(); i++) {
336 dataOut[list[i]] =
false;
static bool * clone(bool *bufferOut, bool *bufferIn, int n, int channels)
clone
Definition: filter_radial_basis_function.hpp:704
Definition: buffer.hpp:30
static bool * erode(bool *dataOut, bool *dataIn, int width, int height, int kernelSize=3)
erode erodes a mask.
Definition: mask.hpp:89
static bool empty(bool *dataIn, int width, int height)
MaskEmpty checks if a mask is empty.
Definition: mask.hpp:183
#define MIN(a, b)
Definition: math.hpp:69
static bool * dilate(bool *dataOut, bool *dataIn, int width, int height, int kernelSize=3)
MaskDilate dilates a mask.
Definition: mask.hpp:137
Definition: bilateral_separation.hpp:25
#define CLAMP(x, a)
Definition: math.hpp:77
static bool * removeIsolatedPixels(bool *dataOut, bool *dataIn, int width, int height)
removeIsolatedPixels removes isolated pixels.
Definition: mask.hpp:38
static bool * thinning(bool *dataOut, bool *dataIn, int width, int height)
thinning thins a mask.
Definition: mask.hpp:209