diff --git a/src/caldir.c b/src/caldir.c index fa36f95e7..824eeea7e 100644 --- a/src/caldir.c +++ b/src/caldir.c @@ -15,6 +15,7 @@ #include "misc/mmio.h" #include "misc/misc.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/opts.h" #include "misc/debug.h" diff --git a/src/calib/calmat.c b/src/calib/calmat.c index 791d64ba2..19f4c9ab8 100644 --- a/src/calib/calmat.c +++ b/src/calib/calmat.c @@ -17,6 +17,7 @@ #include "misc/misc.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/debug.h" #include "calmat.h" diff --git a/src/calib/estvar.c b/src/calib/estvar.c index 849e516a7..e8b01f777 100644 --- a/src/calib/estvar.c +++ b/src/calib/estvar.c @@ -16,6 +16,7 @@ #include "misc/debug.h" #include "misc/misc.h" +#include "misc/mri2.h" #include "calib/calib.h" #include "calib/calmat.h" diff --git a/src/calmat.c b/src/calmat.c index d5734abe8..880d3a650 100644 --- a/src/calmat.c +++ b/src/calmat.c @@ -12,6 +12,7 @@ #include "misc/mmio.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/misc.h" #include "misc/debug.h" #include "misc/opts.h" diff --git a/src/cc.c b/src/cc.c index d9ce5b3d5..7de32869f 100644 --- a/src/cc.c +++ b/src/cc.c @@ -14,6 +14,7 @@ #include "misc/mmio.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/misc.h" #include "misc/debug.h" #include "misc/opts.h" diff --git a/src/ecalib.c b/src/ecalib.c index a30251c4e..192caba5f 100644 --- a/src/ecalib.c +++ b/src/ecalib.c @@ -16,6 +16,7 @@ #include "misc/mmio.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/misc.h" #include "misc/debug.h" #include "misc/opts.h" diff --git a/src/estdelay.c b/src/estdelay.c index 01eee4392..bec4c0c48 100644 --- a/src/estdelay.c +++ b/src/estdelay.c @@ -42,6 +42,77 @@ #endif +static void traj_radial_angles(int N, float angles[N], const long tdims[DIMS], const complex float* traj) +{ + assert(N == tdims[2]); + + long tdims1[DIMS]; + md_select_dims(DIMS, ~MD_BIT(1), tdims1, tdims); + + complex float* traj1 = md_alloc(DIMS, tdims1, CFL_SIZE); + + md_slice(DIMS, MD_BIT(1), (long[DIMS]){ 0 }, tdims, traj1, traj, CFL_SIZE); + + for (int i = 0; i < N; i++) + angles[i] = M_PI + atan2f(crealf(traj1[3 * i + 0]), crealf(traj1[3 * i + 1])); + + md_free(traj1); +} + + + +static float traj_radial_dcshift(const long tdims[DIMS], const complex float* traj) +{ + long tdims1[DIMS]; + md_select_dims(DIMS, ~MD_BIT(1), tdims1, tdims); + + complex float* traj1 = md_alloc(DIMS, tdims1, CFL_SIZE); + // Extract what would be the DC component in Cartesian sampling + + md_slice(DIMS, MD_BIT(1), (long[DIMS]){ [1] = tdims[1] / 2 }, tdims, traj1, traj, CFL_SIZE); + + NESTED(float, dist, (int i)) + { + return sqrtf(powf(crealf(traj1[3 * i + 0]), 2.) + powf(crealf(traj1[3 * i + 1]), 2.)); + }; + + float dc_shift = dist(0); + + for (int i = 0; i < tdims[2]; i++) + if (fabsf(dc_shift - dist(i)) > 0.0001) + debug_printf(DP_WARN, "Inconsistently shifted spoke: %d %f != %f\n", i, dist(i), dc_shift); + + md_free(traj1); + + return dc_shift; +} + + +static float traj_radial_dk(const long tdims[DIMS], const complex float* traj) +{ + long tdims1[DIMS]; + md_select_dims(DIMS, ~MD_BIT(1), tdims1, tdims); + + complex float* traj1 = md_alloc(DIMS, tdims1, CFL_SIZE); + // Extract what would be the DC component in Cartesian sampling + + md_slice(DIMS, MD_BIT(1), (long[DIMS]){ [1] = tdims[1] / 2 }, tdims, traj1, traj, CFL_SIZE); + + NESTED(float, dist, (int i)) + { + return sqrtf(powf(crealf(traj1[3 * i + 0]), 2.) + powf(crealf(traj1[3 * i + 1]), 2.)); + }; + + float dc_shift = dist(0); + + md_slice(DIMS, MD_BIT(1), (long[DIMS]){ [1] = tdims[1] / 2 + 1 }, tdims, traj1, traj, CFL_SIZE); + + float shift1 = dist(0) - dc_shift; + + md_free(traj1); + + return shift1; +} diff --git a/src/estdims.c b/src/estdims.c index f60e6d2d0..11c0c7cf3 100644 --- a/src/estdims.c +++ b/src/estdims.c @@ -14,6 +14,7 @@ #include "misc/misc.h" #include "misc/opts.h" #include "misc/mri.h" +#include "misc/mri2.h" diff --git a/src/lrmatrix.c b/src/lrmatrix.c index cd90db3c6..68086f218 100644 --- a/src/lrmatrix.c +++ b/src/lrmatrix.c @@ -31,6 +31,7 @@ #include "misc/debug.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/mmio.h" #include "misc/misc.h" #include "misc/opts.h" diff --git a/src/misc/mri.h b/src/misc/mri.h index 1ea4c4a8e..509270e41 100644 --- a/src/misc/mri.h +++ b/src/misc/mri.h @@ -62,19 +62,6 @@ enum mri_dims { #define MOTION_DIM ITER_DIM #define MOTION_FLAG ITER_FLAG -extern void estimate_pattern(int D, const long dims[__VLA(D)], unsigned long flags, _Complex float* pattern, const _Complex float* kspace_data); -extern _Complex float* extract_calib(long caldims[DIMS], const long calsize[3], const long in_dims[DIMS], const _Complex float* in_data, _Bool fixed); -extern _Complex float* extract_calib2(long caldims[DIMS], const long calsize[3], const long in_dims[DIMS], const long in_strs[DIMS], const _Complex float* in_data, _Bool fixed); -extern void data_consistency(const long dims[DIMS], _Complex float* dst, const _Complex float* pattern, const _Complex float* kspace1, const _Complex float* kspace2); -extern void calib_geom(long caldims[DIMS], long calpos[DIMS], const long calsize[3], const long in_dims[DIMS], const _Complex float* in_data); - -extern void estimate_im_dims(int N, unsigned long flags, long dims[__VLA(N)], const long tdims[__VLA(N)], const _Complex float* traj); -extern void estimate_fast_sq_im_dims(int N, long dims[3], const long tdims[__VLA(N)], const _Complex float* traj); - -extern void traj_radial_angles(int N, float angles[__VLA(N)], const long tdims[DIMS], const _Complex float* traj); -extern float traj_radial_dcshift(const long tdims[DIMS], const _Complex float* traj); -extern float traj_radial_dk(const long tdims[DIMS], const _Complex float* traj); - #include "misc/cppwrap.h" #endif // __MRI_H diff --git a/src/misc/mri.c b/src/misc/mri2.c similarity index 80% rename from src/misc/mri.c rename to src/misc/mri2.c index 7ee6fe9e4..de985bfa5 100644 --- a/src/misc/mri.c +++ b/src/misc/mri2.c @@ -21,11 +21,7 @@ #include "sense/optcom.h" -#include "mri.h" - - - - +#include "mri2.h" @@ -52,13 +48,6 @@ void data_consistency(const long dims[DIMS], complex float* dst, const complex f - - - - - - - void estimate_pattern(int D, const long dims[D], unsigned long flags, complex float* pattern, const complex float* kspace_data) { md_zrss(D, dims, flags, pattern, kspace_data); @@ -308,77 +297,3 @@ void estimate_fast_sq_im_dims(int N, long dims[3], const long tdims[N], const co dims[j] = (0. == max_dims[j]) ? 1 : fast_size; } - - -void traj_radial_angles(int N, float angles[N], const long tdims[DIMS], const complex float* traj) -{ - assert(N == tdims[2]); - - long tdims1[DIMS]; - md_select_dims(DIMS, ~MD_BIT(1), tdims1, tdims); - - complex float* traj1 = md_alloc(DIMS, tdims1, CFL_SIZE); - - md_slice(DIMS, MD_BIT(1), (long[DIMS]){ 0 }, tdims, traj1, traj, CFL_SIZE); - - for (int i = 0; i < N; i++) - angles[i] = M_PI + atan2f(crealf(traj1[3 * i + 0]), crealf(traj1[3 * i + 1])); - - md_free(traj1); -} - - -float traj_radial_dcshift(const long tdims[DIMS], const complex float* traj) -{ - long tdims1[DIMS]; - md_select_dims(DIMS, ~MD_BIT(1), tdims1, tdims); - - complex float* traj1 = md_alloc(DIMS, tdims1, CFL_SIZE); - // Extract what would be the DC component in Cartesian sampling - - md_slice(DIMS, MD_BIT(1), (long[DIMS]){ [1] = tdims[1] / 2 }, tdims, traj1, traj, CFL_SIZE); - - NESTED(float, dist, (int i)) - { - return sqrtf(powf(crealf(traj1[3 * i + 0]), 2.) + powf(crealf(traj1[3 * i + 1]), 2.)); - }; - - float dc_shift = dist(0); - - for (int i = 0; i < tdims[2]; i++) - if (fabsf(dc_shift - dist(i)) > 0.0001) - debug_printf(DP_WARN, "Inconsistently shifted spoke: %d %f != %f\n", i, dist(i), dc_shift); - - md_free(traj1); - - return dc_shift; -} - - -float traj_radial_dk(const long tdims[DIMS], const complex float* traj) -{ - long tdims1[DIMS]; - md_select_dims(DIMS, ~MD_BIT(1), tdims1, tdims); - - complex float* traj1 = md_alloc(DIMS, tdims1, CFL_SIZE); - // Extract what would be the DC component in Cartesian sampling - - md_slice(DIMS, MD_BIT(1), (long[DIMS]){ [1] = tdims[1] / 2 }, tdims, traj1, traj, CFL_SIZE); - - NESTED(float, dist, (int i)) - { - return sqrtf(powf(crealf(traj1[3 * i + 0]), 2.) + powf(crealf(traj1[3 * i + 1]), 2.)); - }; - - float dc_shift = dist(0); - - md_slice(DIMS, MD_BIT(1), (long[DIMS]){ [1] = tdims[1] / 2 + 1 }, tdims, traj1, traj, CFL_SIZE); - - float shift1 = dist(0) - dc_shift; - - md_free(traj1); - - return shift1; -} - - diff --git a/src/misc/mri2.h b/src/misc/mri2.h new file mode 100644 index 000000000..ff3d54029 --- /dev/null +++ b/src/misc/mri2.h @@ -0,0 +1,23 @@ + +#ifndef __MRI2_H +#define __MRI2_H + +#include "misc/cppwrap.h" + +#ifndef DIMS +#define DIMS 16 +#endif + +extern void estimate_pattern(int D, const long dims[__VLA(D)], unsigned long flags, _Complex float* pattern, const _Complex float* kspace_data); +extern _Complex float* extract_calib(long caldims[DIMS], const long calsize[3], const long in_dims[DIMS], const _Complex float* in_data, _Bool fixed); +extern _Complex float* extract_calib2(long caldims[DIMS], const long calsize[3], const long in_dims[DIMS], const long in_strs[DIMS], const _Complex float* in_data, _Bool fixed); +extern void data_consistency(const long dims[DIMS], _Complex float* dst, const _Complex float* pattern, const _Complex float* kspace1, const _Complex float* kspace2); +extern void calib_geom(long caldims[DIMS], long calpos[DIMS], const long calsize[3], const long in_dims[DIMS], const _Complex float* in_data); + +extern void estimate_im_dims(int N, unsigned long flags, long dims[__VLA(N)], const long tdims[__VLA(N)], const _Complex float* traj); +extern void estimate_fast_sq_im_dims(int N, long dims[3], const long tdims[__VLA(N)], const _Complex float* traj); + +#include "misc/cppwrap.h" + +#endif // __MRI2_H + diff --git a/src/moba.c b/src/moba.c index 14438f849..d18aa272b 100644 --- a/src/moba.c +++ b/src/moba.c @@ -18,6 +18,7 @@ #include "num/filter.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/misc.h" #include "misc/mmio.h" #include "misc/utils.h" diff --git a/src/ncalib.c b/src/ncalib.c index 32042f530..9566b49e0 100644 --- a/src/ncalib.c +++ b/src/ncalib.c @@ -13,6 +13,7 @@ #include "misc/mmio.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/misc.h" #include "misc/debug.h" #include "misc/opts.h" diff --git a/src/networks/misc.c b/src/networks/misc.c index 843d3490a..d669812a2 100644 --- a/src/networks/misc.c +++ b/src/networks/misc.c @@ -10,6 +10,7 @@ #include "misc/misc.h" #include "misc/mmio.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/version.h" #include "num/multind.h" diff --git a/src/nlinv.c b/src/nlinv.c index 79e4a5f27..8b213f7e1 100644 --- a/src/nlinv.c +++ b/src/nlinv.c @@ -38,6 +38,7 @@ #include "linops/linop.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/misc.h" #include "misc/version.h" #include "misc/mmio.h" diff --git a/src/nlinvnet.c b/src/nlinvnet.c index 0b2c018ec..f6cee1c75 100644 --- a/src/nlinvnet.c +++ b/src/nlinvnet.c @@ -22,6 +22,7 @@ #include "nlops/nlop.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/misc.h" #include "misc/mmio.h" #include "misc/utils.h" diff --git a/src/nn/layers.h b/src/nn/layers.h index 0d180ed15..44dd88e7b 100644 --- a/src/nn/layers.h +++ b/src/nn/layers.h @@ -24,4 +24,6 @@ extern const struct nlop_s* append_flatten_layer(const struct nlop_s* network, i extern const struct nlop_s* append_batchnorm_layer(const struct nlop_s* network, int o, unsigned long norm_flags, enum NETWORK_STATUS status); +#include "misc/cppwrap.h" + #endif diff --git a/src/nufft.c b/src/nufft.c index 438b29010..fb5b15bb1 100644 --- a/src/nufft.c +++ b/src/nufft.c @@ -15,6 +15,7 @@ #include "misc/mmio.h" #include "misc/misc.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/debug.h" #include "misc/opts.h" diff --git a/src/pattern.c b/src/pattern.c index e82a0e3c6..a63b86f15 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -17,6 +17,7 @@ #include "misc/mmio.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/misc.h" #include "misc/opts.h" diff --git a/src/pics.c b/src/pics.c index 091d655a2..46d5b9cc7 100644 --- a/src/pics.c +++ b/src/pics.c @@ -39,6 +39,7 @@ #include "misc/debug.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/utils.h" #include "misc/mmio.h" #include "misc/misc.h" diff --git a/src/pocsense.c b/src/pocsense.c index cb683c380..d74b19c29 100644 --- a/src/pocsense.c +++ b/src/pocsense.c @@ -34,6 +34,7 @@ #include "sense/optcom.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/mmio.h" #include "misc/misc.h" #include "misc/debug.h" diff --git a/src/rtnlinv.c b/src/rtnlinv.c index 02705a813..5ec24ecf9 100644 --- a/src/rtnlinv.c +++ b/src/rtnlinv.c @@ -42,6 +42,7 @@ #include "num/init.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/misc.h" #include "misc/version.h" #include "misc/mmio.h" diff --git a/src/sake/sake.c b/src/sake/sake.c index c9c34e310..64fbbb7e0 100644 --- a/src/sake/sake.c +++ b/src/sake/sake.c @@ -32,6 +32,7 @@ #include "misc/misc.h" #include "misc/debug.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "sake.h" diff --git a/src/sense/optcom.c b/src/sense/optcom.c index 38c1795cc..bd8d02cbe 100644 --- a/src/sense/optcom.c +++ b/src/sense/optcom.c @@ -18,6 +18,7 @@ #include "num/fltools.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/misc.h" #include "misc/debug.h" diff --git a/src/sense/pocs.c b/src/sense/pocs.c index 6421654ad..df3d51824 100644 --- a/src/sense/pocs.c +++ b/src/sense/pocs.c @@ -21,6 +21,7 @@ #include "misc/misc.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/debug.h" #include "misc/types.h" diff --git a/src/simu/phantom.c b/src/simu/phantom.c index dc0c860b6..5ebb517cb 100644 --- a/src/simu/phantom.c +++ b/src/simu/phantom.c @@ -22,6 +22,7 @@ #include "misc/misc.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/debug.h" #include "geom/logo.h" diff --git a/src/sqpics.c b/src/sqpics.c index 183f7cf6a..826dfc9bf 100644 --- a/src/sqpics.c +++ b/src/sqpics.c @@ -46,6 +46,7 @@ #include "misc/debug.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/utils.h" #include "misc/mmio.h" #include "misc/misc.h" diff --git a/src/walsh.c b/src/walsh.c index f159bdcee..e6a6a1461 100644 --- a/src/walsh.c +++ b/src/walsh.c @@ -13,6 +13,7 @@ #include "misc/mmio.h" #include "misc/misc.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/opts.h" #include "misc/debug.h" diff --git a/src/wave.c b/src/wave.c index fd5446fa5..f54e90e2f 100644 --- a/src/wave.c +++ b/src/wave.c @@ -42,6 +42,7 @@ #include "misc/debug.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "misc/utils.h" #include "misc/mmio.h" #include "misc/misc.h" diff --git a/utests/test_pattern.c b/utests/test_pattern.c index acf89607e..51b6ea893 100644 --- a/utests/test_pattern.c +++ b/utests/test_pattern.c @@ -15,6 +15,7 @@ #include "misc/debug.h" #include "misc/misc.h" #include "misc/mri.h" +#include "misc/mri2.h" #include "utest.h"