/** * Compute Strang's circulant preconditioner * * Strang's reconditioner is simply the cropped psf in the image domain * */ static complex float* compute_precond(unsigned int N, const long* pre_dims, const long* pre_strs, const long* psf_dims, const long* psf_strs, const complex float* psf, const complex float* linphase) { int ND = N + 1; unsigned long flags = FFT_FLAGS; complex float* pre = md_alloc(ND, pre_dims, CFL_SIZE); complex float* psft = md_alloc(ND, psf_dims, CFL_SIZE); // Transform psf to image domain ifftuc(ND, psf_dims, flags, psft, psf); // Compensate for linear phase to get cropped psf md_clear(ND, pre_dims, pre, CFL_SIZE); md_zfmacc2(ND, psf_dims, pre_strs, pre, psf_strs, psft, psf_strs, linphase); md_free(psft); // Transform to Fourier domain fftuc(N, pre_dims, flags, pre, pre); md_zabs(N, pre_dims, pre, pre); md_zsadd(N, pre_dims, pre, pre, 1e-3); return pre; }
static void homodyne(struct wdata wdata, unsigned int flags, unsigned int N, const long dims[N], const long strs[N], complex float* data, const complex float* idata, const long pstrs[N], const complex float* phase) { md_zmul2(N, dims, strs, data, strs, idata, wdata.wstrs, wdata.weights); ifftuc(N, dims, flags, data, data); md_zmulc2(N, dims, strs, data, strs, data, pstrs, phase); md_zreal(N, dims, data, data); }
static complex float* estimate_phase(struct wdata wdata, unsigned int flags, unsigned int N, const long dims[N], const complex float* idata) { long cdims[N]; md_copy_dims(N, cdims, dims); // cdims[0] = cdims[1] = cdims[2] = 24; cdims[wdata.pfdim] = (wdata.frac - 0.5) * dims[wdata.pfdim]; complex float* center = md_alloc(N, cdims, CFL_SIZE); complex float* phase = md_alloc(N, dims, CFL_SIZE); md_resize_center(N, cdims, center, dims, idata, CFL_SIZE); md_resize_center(N, dims, phase, cdims, center, CFL_SIZE); md_free(center); ifftuc(N, dims, flags, phase, phase); md_zphsr(N, dims, phase, phase); return phase; }
int main_homodyne(int argc, char* argv[]) { bool clear = false; const char* phase_ref = NULL; int com; while (-1 != (com = getopt(argc, argv, "hCP:"))) { switch (com) { case 'C': clear = true; break; case 'P': phase_ref = strdup(optarg); break; case 'h': help(argv[0], stdout); exit(0); default: help(argv[0], stderr); exit(1); } } if (argc - optind != 4) { usage(argv[0], stderr); exit(1); } const int N = DIMS; long dims[N]; complex float* idata = load_cfl(argv[optind + 2], N, dims); complex float* data = create_cfl(argv[optind + 3], N, dims); int pfdim = atoi(argv[optind + 0]); float frac = atof(argv[optind + 1]); assert((0 <= pfdim) && (pfdim < N)); assert(frac > 0.); long strs[N]; md_calc_strides(N, strs, dims, CFL_SIZE); struct wdata wdata; wdata.frac = frac; wdata.pfdim = pfdim; md_select_dims(N, MD_BIT(pfdim), wdata.wdims, dims); md_calc_strides(N, wdata.wstrs, wdata.wdims, CFL_SIZE); wdata.weights = md_alloc(N, wdata.wdims, CFL_SIZE); md_loop(N, wdata.wdims, &wdata, comp_weights); long pstrs[N]; long pdims[N]; complex float* phase = NULL; if (NULL == phase_ref) { phase = estimate_phase(wdata, FFT_FLAGS, N, dims, idata); md_copy_dims(N, pdims, dims); } else phase = load_cfl(phase_ref, N, pdims); md_calc_strides(N, pstrs, pdims, CFL_SIZE); complex float* cdata = NULL; complex float* idata2 = NULL; if (clear) { long cdims[N]; md_select_dims(N, ~MD_BIT(pfdim), cdims, dims); cdims[pfdim] = (int)(dims[pfdim] * frac); cdata = md_alloc(N, cdims, CFL_SIZE); idata2 = anon_cfl(NULL, N, dims); md_resize(N, cdims, cdata, dims, idata, CFL_SIZE); md_resize(N, dims, idata2, cdims, cdata, CFL_SIZE); md_free(cdata); unmap_cfl(N, dims, idata); idata = idata2; } if ((1 == dims[PHS2_DIM]) || (PHS2_DIM == pfdim)) { homodyne(wdata, FFT_FLAGS, N, dims, strs, data, idata, pstrs, phase); } else { unsigned int pardim = PHS2_DIM; ifftuc(N, dims, MD_CLEAR(FFT_FLAGS, pfdim), data, idata); long rdims[N]; md_select_dims(N, ~MD_BIT(pardim), rdims, dims); long rstrs[N]; md_calc_strides(N, rstrs, rdims, CFL_SIZE); #pragma omp parallel for for (unsigned int i = 0; i < dims[pardim]; i++) { complex float* tmp = md_alloc(N, rdims, CFL_SIZE); long pos[N]; md_set_dims(N, pos, 0); pos[pardim] = i; md_copy_block(N, pos, rdims, tmp, dims, data, CFL_SIZE); homodyne(wdata, MD_BIT(pfdim), N, rdims, rstrs, tmp, tmp, pstrs, phase); md_copy_block(N, pos, dims, data, rdims, tmp, CFL_SIZE); md_free(tmp); } } md_free(wdata.weights); if (NULL == phase_ref) md_free(phase); else { unmap_cfl(N, pdims, phase); free((void*)phase_ref); } unmap_cfl(N, dims, idata); unmap_cfl(N, dims, data); exit(0); }
int main_homodyne(int argc, char* argv[]) { mini_cmdline(argc, argv, 4, usage_str, help_str); const int N = DIMS; long dims[N]; complex float* idata = load_cfl(argv[3], N, dims); complex float* data = create_cfl(argv[4], N, dims); int pfdim = atoi(argv[1]); float frac = atof(argv[2]); assert((0 <= pfdim) && (pfdim < N)); assert(frac > 0.); long strs[N]; md_calc_strides(N, strs, dims, CFL_SIZE); struct wdata wdata; wdata.frac = frac; wdata.pfdim = pfdim; md_select_dims(N, MD_BIT(pfdim), wdata.wdims, dims); md_calc_strides(N, wdata.wstrs, wdata.wdims, CFL_SIZE); wdata.weights = md_alloc(N, wdata.wdims, CFL_SIZE); md_loop(N, wdata.wdims, &wdata, comp_weights); if ((1 == dims[PHS2_DIM]) || (PHS2_DIM == pfdim)) { homodyne(wdata, FFT_FLAGS, N, dims, strs, data, idata); } else { unsigned int pardim = PHS2_DIM; ifftuc(N, dims, MD_CLEAR(FFT_FLAGS, pfdim), data, idata); long rdims[N]; md_select_dims(N, ~MD_BIT(pardim), rdims, dims); long rstrs[N]; md_calc_strides(N, rstrs, rdims, CFL_SIZE); #pragma omp parallel for for (unsigned int i = 0; i < dims[pardim]; i++) { complex float* tmp = md_alloc(N, rdims, CFL_SIZE); long pos[N]; md_set_dims(N, pos, 0); pos[pardim] = i; md_copy_block(N, pos, rdims, tmp, dims, data, CFL_SIZE); homodyne(wdata, MD_BIT(pfdim), N, rdims, rstrs, tmp, tmp); md_copy_block(N, pos, dims, data, rdims, tmp, CFL_SIZE); md_free(tmp); } } md_free(wdata.weights); unmap_cfl(N, dims, idata); unmap_cfl(N, dims, data); exit(0); }
int main_rsense(int argc, char* argv[]) { bool usegpu = false; int maps = 2; int ctrsh = 0.; bool sec = false; bool scale_im = false; const char* pat_file = NULL; struct sense_conf sconf = sense_defaults; struct grecon_conf conf = { NULL, &sconf, false, false, false, true, 30, 0.95, 0. }; int c; while (-1 != (c = getopt(argc, argv, "l:r:s:i:p:Sgh"))) { switch(c) { case 'r': conf.lambda = atof(optarg); break; case 's': conf.step = atof(optarg); break; case 'i': conf.maxiter = atoi(optarg); break; case 'l': if (1 == atoi(optarg)) conf.l1wav = true; else if (2 == atoi(optarg)) conf.l1wav = false; else { usage(argv[0], stderr); exit(1); } break; case 'S': scale_im = true; break; case 'h': usage(argv[0], stdout); help(); exit(0); case 'g': usegpu = true; break; case 'p': pat_file = strdup(optarg); break; default: usage(argv[0], stderr); exit(1); } } if (argc - optind != 3) { usage(argv[0], stderr); exit(1); } int N = DIMS; long dims[N]; long img_dims[N]; long ksp_dims[N]; long sens_dims[N]; complex float* kspace_data = load_cfl(argv[optind + 0], N, ksp_dims); complex float* sens_maps = load_cfl(argv[optind + 1], N, sens_dims); assert(1 == ksp_dims[MAPS_DIM]); md_copy_dims(N, dims, ksp_dims); if (!sec) { dims[MAPS_DIM] = sens_dims[MAPS_DIM]; } else { assert(maps <= ksp_dims[COIL_DIM]); dims[MAPS_DIM] = maps; } for (int i = 0; i < 4; i++) { // sizes2[4] may be > 1 if (ksp_dims[i] != dims[i]) { fprintf(stderr, "Dimensions of kspace and sensitivities do not match!\n"); exit(1); } } complex float* pattern = NULL; long pat_dims[DIMS]; if (NULL != pat_file) { pattern = load_cfl(pat_file, DIMS, pat_dims); assert(md_check_compat(DIMS, COIL_FLAG, ksp_dims, pat_dims)); } debug_printf(DP_INFO, "%ld map(s)\n", dims[MAPS_DIM]); if (conf.l1wav) debug_printf(DP_INFO, "l1-wavelet regularization\n"); md_select_dims(N, ~COIL_FLAG, img_dims, dims); (usegpu ? num_init_gpu : num_init)(); // float scaling = estimate_scaling(ksp_dims, sens_maps, kspace_data); float scaling = estimate_scaling(ksp_dims, NULL, kspace_data); debug_printf(DP_INFO, "Scaling: %f\n", scaling); if (0. != scaling) md_zsmul(N, ksp_dims, kspace_data, kspace_data, 1. / scaling); debug_printf(DP_INFO, "Readout FFT..\n"); ifftuc(N, ksp_dims, READ_FLAG, kspace_data, kspace_data); debug_printf(DP_INFO, "Done.\n"); complex float* image = create_cfl(argv[optind + 2], N, img_dims); debug_printf(DP_INFO, "Reconstruction...\n"); struct ecalib_conf calib; if (sec) { calib = ecalib_defaults; calib.crop = ctrsh; conf.calib = &calib; } rgrecon(&conf, dims, image, sens_dims, sens_maps, pat_dims, pattern, kspace_data, usegpu); if (scale_im) md_zsmul(DIMS, img_dims, image, image, scaling); debug_printf(DP_INFO, "Done.\n"); unmap_cfl(N, img_dims, image); unmap_cfl(N, ksp_dims, kspace_data); unmap_cfl(N, sens_dims, sens_maps); exit(0); }