1 /*********************************************************************
2 The default 3D kernel to be used in NoiseChisel and Segment.
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) 2018-2019, 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_KERNEL3D_H__
24 #define __GAL_KERNEL3D_H__
25 
26 /* How to produce this kernel
27    ==========================
28 
29    Below, the steps necessary to easily create the C contents of this file
30    are described. The first step can be modified to change the default
31    kernel properties and put the new contents into this file.
32 
33    Make the kernel
34    ---------------
35 
36    We'll first make the kernel using MakeProfiles with the following
37    commands. IMPORTANT NOTE: because the kernel is so sharp, random
38    sampling is going to be used for all the pixels (the center won't be
39    used). So it is important to have a large number of random points to
40    make the very slight differences between symmetric parts of the profile
41    even less significant.
42 
43      export GSL_RNG_SEED=1
44      export GSL_RNG_TYPE=ranlxs2
45      astmkprof --kernel=gaussian-3d,1.5,5,0.5 --oversample=1 --envseed \
46                --numrandom=100000
47 
48    Convert it to C code
49    --------------------
50 
51    Put the following C program into a file called `kernel.c'.
52 
53        #include <stdio.h>
54        #include <stdlib.h>
55        #include <gnuastro/fits.h>
56 
57        int
58        main(void)
59        {
60          size_t i;
61          float *arr;
62          gal_data_t *img=gal_fits_img_read_to_type("kernel.fits", "1",
63                                                    GAL_TYPE_FLOAT32, -1);
64 
65          arr=img->array;
66 
67          printf("size_t kernel_3d_dsize[3]={%zu, %zu, %zu};\n",
68                 img->dsize[0], img->dsize[1], img->dsize[2]);
69          printf("float kernel_3d[%zu]={", img->size);
70          for(i=0;i<img->size;++i)
71            {
72              if(i>0)
73                {
74                  if(i % img->dsize[2]                 == 0 ) printf("\n");
75 	         if(i % (img->dsize[2]*img->dsize[1]) == 0 ) printf("\n");
76 	       }
77 
78 	     // We cannot use `\b' here, since we are writing directly
79 	     // to the command-line, so we'll first write the number,
80 	     // then decide if any subsequent character (a comma)
81 	     // should be written.
82 	     printf("%.7g", arr[i]);
83 
84 	     // The last element doesn't need a comma. In each line,
85 	     // the last character must not be a space, but for easy
86 	     // readability, the elements in between need a space.
87 	     if( i!=(img->size-1) )
88 	       printf("%s", ((i+1)%img->dsize[2]) ? ", " : ",");
89            }
90          printf("};\n");
91 
92          return EXIT_SUCCESS;
93        }
94 
95    Run the C program
96    -----------------
97 
98    We can now compile and run that C program and put the outputs in
99    `kernel.c'. Once its created, copy the contents of `kernel-3d.h' after
100    these comments.
101 
102      $ astbuildprog -q kernel.c > kernel-3d.h
103  */
104 
105 size_t kernel_3d_dsize[3]={3, 7, 7};
106 float kernel_3d[147]={0, 0, 5.219212e-07, 1.43663e-06, 5.288961e-07, 0, 0,
107 0, 4.890969e-06, 0.0001122713, 0.0003051736, 0.0001101779, 4.908836e-06, 0,
108 5.281005e-07, 0.0001115758, 0.002482525, 0.006792462, 0.002476586, 0.0001099998, 5.217535e-07,
109 1.451268e-06, 0.0003033727, 0.006850741, 0.01871265, 0.006743792, 0.0003061892, 1.43298e-06,
110 5.209756e-07, 0.000110545, 0.002490561, 0.006798376, 0.002503618, 0.0001109581, 5.295083e-07,
111 0, 4.884327e-06, 0.0001122016, 0.0003074409, 0.0001103678, 4.984748e-06, 0,
112 0, 0, 5.224761e-07, 1.425723e-06, 5.33545e-07, 0, 0,
113 
114 0, 3.538044e-07, 7.891201e-06, 2.166429e-05, 7.979216e-06, 3.570717e-07, 0,
115 3.536664e-07, 7.511148e-05, 0.001693119, 0.004623666, 0.001691994, 7.563465e-05, 3.541075e-07,
116 7.921932e-06, 0.001687588, 0.03788469, 0.1038283, 0.03776859, 0.001679332, 7.979274e-06,
117 2.200398e-05, 0.004617298, 0.1038528, 0.2849551, 0.1039089, 0.004635326, 2.165271e-05,
118 7.955934e-06, 0.001697289, 0.0379024, 0.1037254, 0.03768558, 0.001666544, 7.878737e-06,
119 3.523428e-07, 7.45342e-05, 0.001689582, 0.00461954, 0.001684659, 7.568914e-05, 3.499421e-07,
120 0, 3.56209e-07, 7.915472e-06, 2.17837e-05, 7.854093e-06, 3.555503e-07, 0,
121 
122 0, 0, 5.263017e-07, 1.431613e-06, 5.12058e-07, 0, 0,
123 0, 4.907304e-06, 0.0001125078, 0.00030509, 0.000111018, 5.084412e-06, 0,
124 5.256628e-07, 0.0001103357, 0.002493239, 0.006835639, 0.002478384, 0.0001131122, 5.260213e-07,
125 1.442301e-06, 0.0003005426, 0.006833205, 0.01862562, 0.006816466, 0.000302246, 1.436046e-06,
126 5.298979e-07, 0.0001107397, 0.002476231, 0.006837885, 0.00252707, 0.0001124105, 5.305631e-07,
127 0, 5.012419e-06, 0.0001110889, 0.0003017522, 0.0001124517, 4.790862e-06, 0,
128 0, 0, 5.104474e-07, 1.45196e-06, 5.191671e-07, 0, 0};
129 
130 #endif
131