Skip to content

Commit

Permalink
invert: option for regularization
Browse files Browse the repository at this point in the history
  • Loading branch information
uecker committed May 13, 2024
1 parent 0628f55 commit 7709c2d
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/invert.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/* Copyright 2016. The Regents of the University of California.
* Copyright 2024. TU Graz. Institute of Biomedical Imaging.
* All rights reserved. Use of this source code is governed by
* a BSD-style license which can be found in the LICENSE file.
*
*
* Authors:
* 2016 Jon Tamir <[email protected]>
* 2016 Jon Tamir
*/

#include <stdlib.h>
#include <assert.h>
#include <complex.h>
#include <stdio.h>
#include <math.h>

#include "num/multind.h"
#include "num/init.h"
Expand All @@ -36,7 +38,12 @@ int main_invert(int argc, char* argv[argc])
ARG_OUTFILE(true, &out_file, "output"),
};

const struct opt_s opts[] = { };
float reg = 0.;

const struct opt_s opts[] = {

OPT_FLOAT('r', &reg, "reg", "regularization"),
};

cmdline(&argc, argv, ARRAY_SIZE(args), args, help_str, ARRAY_SIZE(opts), opts);

Expand All @@ -48,8 +55,18 @@ int main_invert(int argc, char* argv[argc])
complex float* odata = create_cfl(out_file, DIMS, dims);

#pragma omp parallel for
for (long i = 0; i < md_calc_size(DIMS, dims); i++)
odata[i] = idata[i] == 0 ? 0. : 1. / idata[i];
for (long i = 0; i < md_calc_size(DIMS, dims); i++) {

odata[i] = 0.;

if (0. == idata[i])
continue;

if (0. == reg)
odata[i] = 1. / idata[i];
else
odata[i] = conjf(idata[i]) / (powf(crealf(idata[i]), 2.) + powf(cimagf(idata[i]), 2.) + reg);
}

unmap_cfl(DIMS, dims, idata);
unmap_cfl(DIMS, dims, odata);
Expand Down

0 comments on commit 7709c2d

Please sign in to comment.