1 /*********************************************************************
2 binary -- Work on binary (0 and 1 valued) datasets.
3 This is part of GNU Astronomy Utilities (Gnuastro) package.
4 
5 Original author:
6      Mohammad Akhlaghi <mohammad@akhlaghi.org>
7 Contributing author(s):
8 Copyright (C) 2017-2021, Free Software Foundation, Inc.
9 
10 Gnuastro is free software: you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by the
12 Free Software Foundation, either version 3 of the License, or (at your
13 option) any later version.
14 
15 Gnuastro is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
22 **********************************************************************/
23 #ifndef __GAL_BINARY_H__
24 #define __GAL_BINARY_H__
25 
26 /* Include other headers if necessary here. Note that other header files
27    must be included before the C++ preparations below */
28 #include <gnuastro/data.h>
29 #include <gnuastro/blank.h>
30 
31 /* C++ Preparations */
32 #undef __BEGIN_C_DECLS
33 #undef __END_C_DECLS
34 #ifdef __cplusplus
35 # define __BEGIN_C_DECLS extern "C" {
36 # define __END_C_DECLS }
37 #else
38 # define __BEGIN_C_DECLS                /* empty */
39 # define __END_C_DECLS                  /* empty */
40 #endif
41 /* End of C++ preparations */
42 
43 
44 
45 /* Actual header contants (the above were for the Pre-processor). */
46 __BEGIN_C_DECLS  /* From C++ preparations */
47 
48 
49 
50 /* The binary functions will be working on a 'uint8_t' type dataset with
51    values of 1 or 0 (no other pixel will be touched). However, in some
52    cases, it is necessary to put temporary values in each element during
53    the processing of the functions. So if your input datasets have values
54    other than 0 and 1 that you don't want these functions to work on, be
55    sure they are not equal to this value. It is chosen as the immediate
56    value before the maximum value for this type (which is the blank value
57    for this type), so blank values will also not be touched by this
58    function. */
59 #define GAL_BINARY_TMP_VALUE GAL_BLANK_UINT8-1
60 
61 
62 
63 
64 
65 
66 /*********************************************************************/
67 /*****************      Erosion and dilation      ********************/
68 /*********************************************************************/
69 gal_data_t *
70 gal_binary_erode(gal_data_t *input, size_t num, int connectivity,
71                  int inplace);
72 
73 gal_data_t *
74 gal_binary_dilate(gal_data_t *input, size_t num, int connectivity,
75                   int inplace);
76 
77 gal_data_t *
78 gal_binary_open(gal_data_t *input, size_t num, int connectivity,
79                 int inplace);
80 
81 
82 
83 
84 
85 /*********************************************************************/
86 /*****************      Connected components      ********************/
87 /*********************************************************************/
88 size_t
89 gal_binary_connected_components(gal_data_t *binary, gal_data_t **out,
90                                 int connectivity);
91 
92 gal_data_t *
93 gal_binary_connected_indexs(gal_data_t *binary, int connectivity);
94 
95 gal_data_t *
96 gal_binary_connected_adjacency_matrix(gal_data_t *adjacency,
97                                       size_t *numnewlabs);
98 
99 gal_data_t *
100 gal_binary_connected_adjacency_list(gal_list_sizet_t **listarr,
101                                     size_t number, size_t minmapsize,
102                                     int quietmmap, size_t *numconnected);
103 
104 /*********************************************************************/
105 /*****************            Fill holes          ********************/
106 /*********************************************************************/
107 gal_data_t *
108 gal_binary_holes_label(gal_data_t *input, int connectivity,
109                        size_t *numholes);
110 
111 void
112 gal_binary_holes_fill(gal_data_t *input, int connectivity, size_t maxsize);
113 
114 
115 
116 __END_C_DECLS    /* From C++ preparations */
117 
118 #endif           /* __GAL_BINARY_H__ */
119