"Fossies" - the Fresh Open Source Software Archive

Member "gnuastro-0.8/bin/noisechisel/kernel-2d.h" (12 May 2018, 4813 Bytes) of package /linux/privat/gnuastro-0.8.tar.lz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "kernel-2d.h" see the Fossies "Dox" file reference documentation.

    1 /*********************************************************************
    2 The default 2D kernel to be used in NoiseChisel.
    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, 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_KERNEL2D_H__
   24 #define __GAL_KERNEL2D_H__
   25 
   26 
   27 /* How to produce this kernel
   28    ==========================
   29 
   30    Below, the steps necessary to easily create the C contents of this file
   31    are described. The first step can be modified to change the default
   32    kernel properties and put the new contents into this file.
   33 
   34    Make the kernel
   35    ---------------
   36 
   37    We'll first make the kernel using MakeProfiles with the following
   38    commands. IMPORTANT NOTE: because the kernel is so sharp, random
   39    sampling is going to be used for all the pixels (the center won't be
   40    used). So it is important to have a large number of random points to
   41    make the very slight differences between symmetric parts of the profile
   42    even less significant.
   43 
   44      export GSL_RNG_SEED=1
   45      export GSL_RNG_TYPE=ranlxs2
   46      astmkprof --kernel=gaussian,2,5 --oversample=1 --envseed --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_2d_dsize[2]={%zu, %zu};\n",
   68               img->dsize[0], img->dsize[1]);
   69        printf("float kernel_2d[%zu]={", img->size);
   70        for(i=0;i<img->size;++i)
   71          {
   72            if(i>0)
   73              {
   74                if(i % img->dsize[1] == 0 ) printf("\n\n");
   75              }
   76 
   77            // We cannot use `\b' here, since we are writing directly
   78            // to the command-line, so we'll first write the number,
   79            // then decide if any subsequent character (a comma)
   80            // should be written.
   81            printf("%.7g", arr[i]);
   82 
   83            // The last element doesn't need a comma. In each line,
   84            // the last character must not be a space, but for easy
   85            // readability, the elements in between need a space.
   86            if( i!=(img->size-1) )
   87              printf("%s", ((i+1)%img->dsize[1]) ? ", " : ",");
   88          }
   89        printf("};\n");
   90 
   91        gal_data_free(img);
   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-2d.h' after
  100    these comments.
  101 
  102      $ astbuildprog -q kernel.c > kernel-2d.h
  103  */
  104 
  105 size_t kernel_2d_dsize[2]={11, 11};
  106 float kernel_2d[121]={0, 0, 0, 0, 0, 2.599797e-08, 0, 0, 0, 0, 0,
  107 
  108 0, 0, 3.008479e-08, 6.938075e-07, 4.493532e-06, 8.276223e-06, 4.515019e-06, 6.947793e-07, 3.04628e-08, 0, 0,
  109 
  110 0, 3.009687e-08, 2.556034e-06, 5.936867e-05, 0.0003808578, 0.0007126221, 0.0003827095, 5.902729e-05, 2.553342e-06, 2.978137e-08, 0,
  111 
  112 0, 7.021852e-07, 5.912285e-05, 0.00137637, 0.008863639, 0.01648383, 0.008855942, 0.001365171, 5.925718e-05, 7.021184e-07, 0,
  113 
  114 0, 4.490787e-06, 0.0003826718, 0.008857355, 0.05742518, 0.1062628, 0.05727194, 0.008880079, 0.0003826067, 4.478989e-06, 0,
  115 
  116 2.595735e-08, 8.31301e-06, 0.0007113572, 0.01640853, 0.1061298, 0.1971036, 0.1062611, 0.01647962, 0.000708363, 8.379878e-06, 2.593496e-08,
  117 
  118 0, 4.516684e-06, 0.0003846966, 0.008860709, 0.05739478, 0.1062216, 0.05725683, 0.00881713, 0.000383981, 4.473017e-06, 0,
  119 
  120 0, 6.950547e-07, 5.920586e-05, 0.00137483, 0.00887785, 0.0164709, 0.008855232, 0.001372743, 5.939038e-05, 7.016624e-07, 0,
  121 
  122 0, 3.006322e-08, 2.587011e-06, 5.92911e-05, 0.0003843824, 0.0007118155, 0.000386519, 5.974654e-05, 2.585581e-06, 3.048036e-08, 0,
  123 
  124 0, 0, 3.041056e-08, 7.05225e-07, 4.497418e-06, 8.388542e-06, 4.478833e-06, 7.018358e-07, 2.995504e-08, 0, 0,
  125 
  126 0, 0, 0, 0, 0, 2.567377e-08, 0, 0, 0, 0, 0};
  127 
  128 
  129 #endif