joint_inversion.c 2.27 KB
Newer Older
1
/*-----------------------------------------------------------------------------------------
Florian Wittkamp's avatar
Florian Wittkamp committed
2
 * Copyright (C) 2016  For the list of authors, see file AUTHORS.
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
 *
 * This file is part of DENISE.
 *
 * DENISE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2.0 of the License only.
 *
 * DENISE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with DENISE. See file COPYING and/or <http://www.gnu.org/licenses/gpl-2.0.html>.
 -----------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------
 *
 * Joint Inversion
 *
 *
 * Florian Wittkamp 13.10.2015
 *  ----------------------------------------------------------------------*/
#include "fd.h"

/* Declare local functions */


float ** joint_inversion_grad ( float ** gradiant_1,float ** gradiant_2, float alpha, int joint_type) {
    /*
     * Input parameters:
     * - gradiant_1 : first gradiant
     * - gradiant_2 : second gradiant
     * - alpha : value for weighting
     * - joint_type:
     *              1: Normalize both and take the arithmetic mean
     *
     */
    
    /* Define local variables  */
    float ** joint_gradiant; // This will be the merged gradiant, which will be returned
    int i, j;
    float max1=0.0,max2=0.0;
    /* Define extern variables */
    extern int NX, NY, NXG, NYG;
    extern int NPROCX, NPROCY, MYID;
    extern FILE *FP;
    
51
    
52 53
    switch (joint_type) {
        case 1:
54 55 56
            /* joint_type=1: Normalize both and take the arithmetic mean */
            max1=global_maximum(gradiant_1);
            max2=global_maximum(gradiant_2);
57
            for (j=1;j<=NY;j++){
58 59 60
                for (i=1;i<=NX;i++){
                    gradiant_1[j][i]=((1-alpha)*gradiant_1[j][i]/max1+alpha*gradiant_2[j][i]/max2);
                }
61
            }
62 63
            joint_gradiant=gradiant_1;
            break;
64 65 66 67 68
    }
    return joint_gradiant;
};