int main_conv(int argc, char* argv[]) { cmdline(&argc, argv, 4, 4, usage_str, help_str, 0, NULL); num_init(); unsigned int flags = atoi(argv[1]); unsigned int N = DIMS; long dims[N]; const complex float* in = load_cfl(argv[2], N, dims); long krn_dims[N]; const complex float* krn = load_cfl(argv[3], N, krn_dims); complex float* out = create_cfl(argv[4], N, dims); struct conv_plan* plan = conv_plan(N, flags, CONV_CYCLIC, CONV_SYMMETRIC, dims, dims, krn_dims, krn); conv_exec(plan, out, in); conv_free(plan); unmap_cfl(N, dims, out); unmap_cfl(N, krn_dims, krn); unmap_cfl(N, dims, in); exit(0); }
int main_copy(int argc, char* argv[]) { const struct opt_s opts[] = { }; cmdline(&argc, argv, 2, 1000, usage_str, help_str, ARRAY_SIZE(opts), opts); num_init(); unsigned int N = DIMS; int count = argc - 3; assert((count >= 0) && (count % 2 == 0)); long in_dims[N]; long out_dims[N]; void* in_data = load_cfl(argv[argc - 2], N, in_dims); if (count > 0) { // get dimensions void* out_data = load_cfl(argv[argc - 1], N, out_dims); unmap_cfl(N, out_dims, out_data); } else { md_copy_dims(N, out_dims, in_dims); } void* out_data = create_cfl(argv[argc - 1], N, out_dims); long position[N]; for (unsigned int i = 0; i < N; i++) position[i] = 0; for (int i = 0; i < count; i += 2) { unsigned int dim = atoi(argv[i + 1]); long pos = atol(argv[i + 2]); assert(dim < N); assert((0 <= pos) && (pos < out_dims[dim])); position[dim] = pos; } md_copy_block(N, position, out_dims, out_data, in_dims, in_data, CFL_SIZE); unmap_cfl(N, in_dims, in_data); unmap_cfl(N, out_dims, out_data); return 0; }
int main_relnorm(int argc, char* argv[]) { if (0 == strcmp(basename(argv[0]), "relnorm")) debug_printf(DP_WARN, "The \'relnorm\' command is deprecated. Use \'nrmse\' instead.\n"); int c; while (-1 != (c = getopt(argc, argv, "h"))) { switch (c) { case 'h': usage(argv[0], stdout); printf( "Compute relative l2 norm of two images: norm(x1 - x2) / norm(x2) \n" "\t-h\thelp\n" ); exit(0); default: usage(argv[0], stderr); exit(1); } } if (argc - optind != 2) { usage(argv[0], stderr); exit(1); } int N = DIMS; long in1_dims[N]; long in2_dims[N]; complex float* in1_data = load_cfl(argv[optind + 0], N, in1_dims); complex float* in2_data = load_cfl(argv[optind + 1], N, in2_dims); for (int i = 0; i < N; i++) assert(in1_dims[i] == in2_dims[i]); float value = md_zrnorme(DIMS, in1_dims, in1_data, in2_data); printf("%+e\n", value); unmap_cfl(N, in1_dims, in1_data); unmap_cfl(N, in2_dims, in2_data); exit(0); }
int main_slice(int argc, char* argv[]) { mini_cmdline(&argc, argv, 4, usage_str, help_str); num_init(); long in_dims[DIMS]; long out_dims[DIMS]; complex float* in_data = load_cfl(argv[3], DIMS, in_dims); int dim = atoi(argv[1]); int pos = atoi(argv[2]); assert(dim < DIMS); assert(pos >= 0); assert(pos < in_dims[dim]); for (int i = 0; i < DIMS; i++) out_dims[i] = in_dims[i]; out_dims[dim] = 1; complex float* out_data = create_cfl(argv[4], DIMS, out_dims); long pos2[DIMS] = { [0 ... DIMS - 1] = 0 }; pos2[dim] = pos; md_slice(DIMS, MD_BIT(dim), pos2, in_dims, out_data, in_data, CFL_SIZE); unmap_cfl(DIMS, out_dims, out_data); unmap_cfl(DIMS, in_dims, in_data); return 0; }
int main_transpose(int argc, char* argv[]) { mini_cmdline(argc, argv, 4, usage_str, help_str); int N = DIMS; long idims[N]; int dim1 = atoi(argv[1]); int dim2 = atoi(argv[2]); assert((0 <= dim1) && (dim1 < N)); assert((0 <= dim2) && (dim2 < N)); complex float* idata = load_cfl(argv[3], N, idims); long odims[N]; md_transpose_dims(N, dim1, dim2, odims, idims); complex float* odata = create_cfl(argv[4], N, odims); md_transpose(N, dim1, dim2, odims, odata, idims, idata, sizeof(complex float)); unmap_cfl(N, idims, idata); unmap_cfl(N, odims, odata); exit(0); }
int main_fft(int argc, char* argv[]) { bool unitary = false; bool inv = false; const struct opt_s opts[] = { OPT_SET('u', &unitary, "unitary"), OPT_SET('i', &inv, "inverse"), }; cmdline(&argc, argv, 3, 3, usage_str, help_str, ARRAY_SIZE(opts), opts); long dims[DIMS]; complex float* idata = load_cfl(argv[2], DIMS, dims); complex float* data = create_cfl(argv[3], DIMS, dims); unsigned long flags = labs(atol(argv[1])); md_copy(DIMS, dims, data, idata, sizeof(complex float)); unmap_cfl(DIMS, dims, idata); if (unitary) fftscale(DIMS, dims, flags, data, data); (inv ? ifftc : fftc)(DIMS, dims, flags, data, data); unmap_cfl(DIMS, dims, data); exit(0); }
int main_estvar(int argc, char* argv[]) { long calsize_dims[3] = { 24, 24, 24}; long kernel_dims[3] = { 6, 6, 6}; const struct opt_s opts[] = { { 'k', true, opt_vec3, &kernel_dims, " ksize\tkernel size" }, { 'K', true, opt_vec3, &kernel_dims, NULL }, { 'r', true, opt_vec3, &calsize_dims, " cal_size\tLimits the size of the calibration region." }, { 'R', true, opt_vec3, &calsize_dims, NULL }, }; cmdline(&argc, argv, 1, 1, usage_str, help_str, ARRAY_SIZE(opts), opts); int N = DIMS; long kspace_dims[N]; complex float* kspace = load_cfl(argv[1], N, kspace_dims); for (int idx = 0; idx < 3; idx++) { kernel_dims[idx] = (kspace_dims[idx] == 1) ? 1 : kernel_dims[idx]; calsize_dims[idx] = (kspace_dims[idx] == 1) ? 1 : calsize_dims[idx]; } float variance = estvar_kspace(N, kernel_dims, calsize_dims, kspace_dims, kspace); unmap_cfl(N, kspace_dims, kspace); printf("Estimated noise variance: %f\n", variance); exit(0); }
int main_repmat(int argc, char* argv[]) { mini_cmdline(argc, argv, 4, usage_str, help_str); long in_dims[DIMS]; long out_dims[DIMS]; complex float* in_data = load_cfl(argv[3], DIMS, in_dims); int dim = atoi(argv[1]); int rep = atoi(argv[2]); assert(dim < DIMS); assert(rep >= 0); assert(1 == in_dims[dim]); md_copy_dims(DIMS, out_dims, in_dims); out_dims[dim] = rep; complex float* out_data = create_cfl(argv[4], DIMS, out_dims); long in_strs[DIMS]; long out_strs[DIMS]; md_calc_strides(DIMS, in_strs, in_dims, CFL_SIZE); md_calc_strides(DIMS, out_strs, out_dims, CFL_SIZE); md_copy2(DIMS, out_dims, out_strs, out_data, in_strs, in_data, CFL_SIZE); unmap_cfl(DIMS, out_dims, out_data); unmap_cfl(DIMS, in_dims, in_data); exit(0); }
int main_estdelay(int argc, char* argv[]) { bool ring = false; int pad_factor = 100; unsigned int no_intersec_sp = 1; float size = 1.5; const struct opt_s opts[] = { OPT_SET('R', &ring, "RING method"), OPT_INT('p', &pad_factor, "p", "[RING] Padding"), OPT_UINT('n', &no_intersec_sp, "n", "[RING] Number of intersecting spokes"), OPT_FLOAT('r', &size, "r", "[RING] Central region size"), }; cmdline(&argc, argv, 2, 2, usage_str, help_str, ARRAY_SIZE(opts), opts); num_init(); if (pad_factor % 2 != 0) error("Pad_factor -p should be even\n"); long tdims[DIMS]; const complex float* traj = load_cfl(argv[1], DIMS, tdims); 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);
int main_threshold(int argc, char* argv[]) { unsigned int flags = 0; enum th_type { NONE, WAV, LLR, DFW, MPDFW, HARD } th_type = NONE; int llrblk = 8; const struct opt_s opts[] = { OPT_SELECT('H', enum th_type, &th_type, HARD, "hard thresholding"), OPT_SELECT('W', enum th_type, &th_type, WAV, "daubechies wavelet soft-thresholding"), OPT_SELECT('L', enum th_type, &th_type, LLR, "locally low rank soft-thresholding"), OPT_SELECT('D', enum th_type, &th_type, DFW, "divergence-free wavelet soft-thresholding"), OPT_UINT('j', &flags, "bitmask", "joint soft-thresholding"), OPT_INT('b', &llrblk, "blocksize", "locally low rank block size"), }; cmdline(&argc, argv, 3, 3, usage_str, help_str, ARRAY_SIZE(opts), opts); num_init(); const int N = DIMS; long dims[N]; complex float* idata = load_cfl(argv[2], N, dims); complex float* odata = create_cfl(argv[3], N, dims); float lambda = atof(argv[1]); switch (th_type) { case WAV: wthresh(N, dims, lambda, flags, odata, idata); break; case LLR: lrthresh(N, dims, llrblk, lambda, flags, odata, idata); break; case DFW: dfthresh(N, dims, lambda, odata, idata); break; case HARD: hard_thresh(N, dims, lambda, odata, idata); break; default: md_zsoftthresh(N, dims, lambda, flags, odata, idata); } unmap_cfl(N, dims, idata); unmap_cfl(N, dims, odata); return 0; }
int main_conv(int argc, char* argv[]) { int c; while (-1 != (c = getopt(argc, argv, "ah"))) { switch (c) { case 'h': usage(argv[0], stdout); help(); exit(0); default: usage(argv[0], stderr); exit(1); } } if (argc - optind != 4) { usage(argv[0], stderr); exit(1); } unsigned int flags = atoi(argv[optind + 0]); unsigned int N = DIMS; long dims[N]; const complex float* in = load_cfl(argv[optind + 1], N, dims); long krn_dims[N]; const complex float* krn = load_cfl(argv[optind + 2], N, krn_dims); complex float* out = create_cfl(argv[optind + 3], N, dims); struct conv_plan* plan = conv_plan(N, flags, CONV_CYCLIC, CONV_SYMMETRIC, dims, dims, krn_dims, krn); conv_exec(plan, out, in); conv_free(plan); unmap_cfl(N, dims, out); unmap_cfl(N, krn_dims, krn); unmap_cfl(N, dims, in); exit(0); }
int main_estdelay(int argc, char* argv[]) { mini_cmdline(&argc, argv, 2, usage_str, help_str); long tdims[DIMS]; const complex float* traj = load_cfl(argv[1], DIMS, tdims); 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);
int main_cdf97(int argc, char* argv[]) { int c; _Bool inv = false; while (-1 != (c = getopt(argc, argv, "ih"))) { switch (c) { case 'i': inv = true; break; case 'h': usage(argv[0], stdout); help(); exit(0); default: usage(argv[0], stderr); exit(1); } } if (argc - optind != 3) { usage(argv[0], stderr); exit(1); } unsigned int flags = atoi(argv[optind + 0]); long dims[DIMS]; complex float* idata = load_cfl(argv[optind + 1], DIMS, dims); complex float* odata = create_cfl(argv[optind + 2], DIMS, dims); md_copy(DIMS, dims, odata, idata, CFL_SIZE); unmap_cfl(DIMS, dims, idata); if (inv) { md_iresortz(DIMS, dims, flags, odata); md_icdf97z(DIMS, dims, flags, odata); } else { md_cdf97z(DIMS, dims, flags, odata); md_resortz(DIMS, dims, flags, odata); } unmap_cfl(DIMS, dims, odata); exit(0); }
int main_itsense(int argc, char* argv[]) { mini_cmdline(argc, argv, 5, usage_str, help_str); struct sense_data data; data.alpha = atof(argv[1]); complex float* kspace = load_cfl(argv[3], DIMS, data.data_dims); data.sens = load_cfl(argv[2], DIMS, data.sens_dims); data.pattern = load_cfl(argv[4], DIMS, data.mask_dims); // 1 2 4 8 md_select_dims(DIMS, ~COIL_FLAG, data.imgs_dims, data.sens_dims); assert(check_dimensions(&data)); complex float* image = create_cfl(argv[5], DIMS, data.imgs_dims); md_calc_strides(DIMS, data.sens_strs, data.sens_dims, CFL_SIZE); md_calc_strides(DIMS, data.imgs_strs, data.imgs_dims, CFL_SIZE); md_calc_strides(DIMS, data.data_strs, data.data_dims, CFL_SIZE); md_calc_strides(DIMS, data.mask_strs, data.mask_dims, CFL_SIZE); data.tmp = md_alloc(DIMS, data.data_dims, CFL_SIZE); num_init(); sense_reco(&data, image, kspace); unmap_cfl(DIMS, data.imgs_dims, image); unmap_cfl(DIMS, data.mask_dims, data.pattern); unmap_cfl(DIMS, data.sens_dims, data.sens); unmap_cfl(DIMS, data.data_dims, data.sens); md_free(data.tmp); exit(0); }
int main_sdot(int argc, char* argv[]) { cmdline(&argc, argv, 2, 2, usage_str, help_str, 0, NULL); int N = DIMS; long in1_dims[N]; long in2_dims[N]; complex float* in1_data = load_cfl(argv[1], N, in1_dims); complex float* in2_data = load_cfl(argv[2], N, in2_dims); for (int i = 0; i < N; i++) assert(in1_dims[i] == in2_dims[i]); // compute scalar product complex float value = md_zscalar(N, in1_dims, in1_data, in2_data); printf("%+e%+ei\n", crealf(value), cimagf(value)); unmap_cfl(N, in1_dims, in1_data); unmap_cfl(N, in2_dims, in2_data); exit(0); }
int main_carg(int argc, char* argv[]) { mini_cmdline(argc, argv, 2, usage_str, help_str); long dims[DIMS]; complex float* in_data = load_cfl(argv[1], DIMS, dims); complex float* out_data = create_cfl(argv[2], DIMS, dims); md_zarg(DIMS, dims, out_data, in_data); unmap_cfl(DIMS, dims, out_data); unmap_cfl(DIMS, dims, in_data); exit(0); }
int main_conj(int argc, char* argv[]) { mini_cmdline(argc, argv, 2, usage_str, help_str); const int N = 16; long dims[N]; complex float* idata = load_cfl(argv[1], N, dims); complex float* odata = create_cfl(argv[2], N, dims); md_zconj(N, dims, odata, idata); unmap_cfl(N, dims, idata); unmap_cfl(N, dims, odata); exit(0); }
int main_mip(int argc, char* argv[argc]) { bool mIP = false; const struct opt_s opts[] = { OPT_SET('m', &mIP, "minimum" ), }; cmdline(&argc, argv, 3, 3, usage_str, help_str, ARRAY_SIZE(opts), opts); unsigned int flags = atoi(argv[1]); long idims[DIMS]; complex float* in = load_cfl(argv[2], DIMS, idims); long odims[DIMS]; md_select_dims(DIMS, ~flags, odims, idims); complex float* out = create_cfl(argv[3], DIMS, odims); complex float* tmp = md_alloc(DIMS, idims, CFL_SIZE); md_zabs(DIMS, idims, tmp, in); long istr[DIMS]; long ostr[DIMS]; md_calc_strides(DIMS, istr, idims, CFL_SIZE); md_calc_strides(DIMS, ostr, odims, CFL_SIZE); md_clear(DIMS, odims, out, CFL_SIZE); md_max2(DIMS, idims, ostr, (float*)out, ostr, (const float*)out, istr, (const float*)tmp); if (mIP) { // need result of max in output md_min2(DIMS, idims, ostr, (float*)out, ostr, (const float*)out, istr, (const float*)tmp); } md_free(tmp); unmap_cfl(DIMS, idims, in); unmap_cfl(DIMS, odims, out); exit(0); }
int main_reshape(int argc, char* argv[]) { cmdline(&argc, argv, 3, 100, usage_str, help_str, 0, NULL); num_init(); unsigned int flags = atoi(argv[1]); unsigned int n = bitcount(flags); assert((int)n + 3 == argc - 1); long in_dims[DIMS]; long in_strs[DIMS]; long out_dims[DIMS]; long out_strs[DIMS]; complex float* in_data = load_cfl(argv[n + 2], DIMS, in_dims); md_calc_strides(DIMS, in_strs, in_dims, CFL_SIZE); md_copy_dims(DIMS, out_dims, in_dims); unsigned int j = 0; for (unsigned int i = 0; i < DIMS; i++) if (MD_IS_SET(flags, i)) out_dims[i] = atoi(argv[j++ + 2]); assert(j == n); assert(md_calc_size(DIMS, in_dims) == md_calc_size(DIMS, out_dims)); md_calc_strides(DIMS, out_strs, out_dims, CFL_SIZE); for (unsigned int i = 0; i < DIMS; i++) if (!(MD_IS_SET(flags, i) || (in_strs[i] == out_strs[i]))) error("Dimensions are not consistent at index %d.\n"); complex float* out_data = create_cfl(argv[n + 3], DIMS, out_dims); md_copy(DIMS, in_dims, out_data, in_data, CFL_SIZE); unmap_cfl(DIMS, in_dims, in_data); unmap_cfl(DIMS, out_dims, out_data); exit(0); }
int main_resize(int argc, char* argv[]) { bool center = false; const struct opt_s opts[] = { OPT_SET('c', ¢er, "center"), }; cmdline(&argc, argv, 4, 1000, usage_str, help_str, ARRAY_SIZE(opts), opts); num_init(); unsigned int N = DIMS; int count = argc - 3; assert((count > 0) && (count % 2 == 0)); long in_dims[N]; long out_dims[N]; void* in_data = load_cfl(argv[argc - 2], N, in_dims); md_copy_dims(N, out_dims, in_dims); for (int i = 0; i < count; i += 2) { unsigned int dim = atoi(argv[i + 1]); unsigned int size = atoi(argv[i + 2]); assert(dim < N); assert(size >= 1); out_dims[dim] = size; } void* out_data = create_cfl(argv[argc - 1], N, out_dims); (center ? md_resize_center : md_resize)(N, out_dims, out_data, in_dims, in_data, CFL_SIZE); unmap_cfl(N, in_dims, in_data); unmap_cfl(N, out_dims, out_data); return 0; }
int main_flip(int argc, char* argv[]) { mini_cmdline(argc, argv, 3, usage_str, help_str); int N = DIMS; long dims[N]; complex float* idata = load_cfl(argv[2], N, dims); complex float* odata = create_cfl(argv[3], N, dims); unsigned long flags = atoi(argv[1]); md_flip(N, dims, flags, odata, idata, sizeof(complex float)); unmap_cfl(N, dims, idata); unmap_cfl(N, dims, odata); exit(0); }
int main_walsh(int argc, char* argv[]) { long bsize[3] = { 20, 20, 20 }; long calsize[3] = { 24, 24, 24 }; const struct opt_s opts[] = { { 'r', true, opt_vec3, &calsize, " cal_size\tLimits the size of the calibration region." }, { 'R', true, opt_vec3, &calsize, NULL }, { 'b', true, opt_vec3, &bsize, " block_size\tBlock size." }, { 'B', true, opt_vec3, &bsize, NULL }, }; cmdline(&argc, argv, 2, 2, usage_str, help_str, ARRAY_SIZE(opts), opts); long dims[DIMS]; complex float* in_data = load_cfl(argv[1], DIMS, dims); assert((dims[0] == 1) || (calsize[0] < dims[0])); assert((dims[1] == 1) || (calsize[1] < dims[1])); assert((dims[2] == 1) || (calsize[2] < dims[2])); assert(1 == dims[MAPS_DIM]); long caldims[DIMS]; complex float* cal_data = extract_calib(caldims, calsize, dims, in_data, false); unmap_cfl(DIMS, dims, in_data); debug_printf(DP_INFO, "Calibration region %ldx%ldx%ld\n", caldims[0], caldims[1], caldims[2]); dims[COIL_DIM] = dims[COIL_DIM] * (dims[COIL_DIM] + 1) / 2; complex float* out_data = create_cfl(argv[2], DIMS, dims); walsh(bsize, dims, out_data, caldims, cal_data); debug_printf(DP_INFO, "Done.\n"); md_free(cal_data); unmap_cfl(DIMS, dims, out_data); exit(0); }
int main_invert(int argc, char* argv[]) { mini_cmdline(&argc, argv, 2, usage_str, help_str); num_init(); long dims[DIMS]; complex float* idata = load_cfl(argv[1], DIMS, dims); complex float* odata = create_cfl(argv[2], 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]; unmap_cfl(DIMS, dims, idata); unmap_cfl(DIMS, dims, odata); return 0; }
int main_normalize(int argc, char* argv[]) { bool l1 = false; l1 = mini_cmdline_bool(argc, argv, 'b', 3, usage_str, help_str); int N = DIMS; long dims[N]; complex float* data = load_cfl(argv[2], N, dims); int flags = atoi(argv[1]); assert(flags >= 0); complex float* out = create_cfl(argv[3], N, dims); md_copy(N, dims, out, data, CFL_SIZE); (l1 ? normalizel1 : normalize)(N, flags, dims, out); unmap_cfl(N, dims, out); exit(0); }
int main_wavg(int argc, char* argv[argc]) { cmdline(&argc, argv, 3, 3, usage_str, help_str, 0, NULL); int N = DIMS; unsigned int flags = atoi(argv[1]); long idims[N]; complex float* data = load_cfl(argv[2], N, idims); long odims[N]; md_select_dims(N, ~flags, odims, idims); complex float* out = create_cfl(argv[3], N, odims); md_zwavg(N, idims, flags, out, data); unmap_cfl(N, idims, data); unmap_cfl(N, odims, out); exit(0); }
int main_spow(int argc, char* argv[argc]) { mini_cmdline(argc, argv, 3, usage_str, help_str); complex float expo; if (0 != parse_cfl(&expo, argv[1])) { fprintf(stderr, "ERROR: exponent %s is not a number.\n", argv[1]); exit(1); } const int N = DIMS; long dims[N]; complex float* idata = load_cfl(argv[2], N, dims); complex float* odata = create_cfl(argv[3], N, dims); md_zspow(N, dims, odata, idata, expo); unmap_cfl(N, dims, idata); unmap_cfl(N, dims, odata); exit(0); }
int main_rss(int argc, char* argv[argc]) { mini_cmdline(argc, argv, 3, usage_str, help_str); long dims[DIMS]; complex float* data = load_cfl(argv[2], DIMS, dims); int flags = atoi(argv[1]); assert(0 <= flags); long odims[DIMS]; md_select_dims(DIMS, ~flags, odims, dims); complex float* out = create_cfl(argv[3], DIMS, odims); md_zrss(DIMS, dims, flags, out, data); unmap_cfl(DIMS, dims, data); unmap_cfl(DIMS, odims, out); exit(0); }
int main_extract(int argc, char* argv[]) { mini_cmdline(argc, argv, 5, usage_str, help_str); num_init(); long in_dims[DIMS]; long out_dims[DIMS]; complex float* in_data = load_cfl(argv[4], DIMS, in_dims); int dim = atoi(argv[1]); int start = atoi(argv[2]); int end = atoi(argv[3]); assert((0 <= dim) && (dim < DIMS)); assert(start >= 0); assert(start <= end); assert(end < in_dims[dim]); for (int i = 0; i < DIMS; i++) out_dims[i] = in_dims[i]; out_dims[dim] = end - start + 1; complex float* out_data = create_cfl(argv[5], DIMS, out_dims); long pos2[DIMS] = { [0 ... DIMS - 1] = 0 }; pos2[dim] = start; md_copy_block(DIMS, pos2, out_dims, out_data, in_dims, in_data, sizeof(complex float)); unmap_cfl(DIMS, in_dims, in_data); unmap_cfl(DIMS, out_dims, out_data); exit(0); }
int main_bpsense(int argc, char* argv[]) { // ----------------------------------------------------------- // set up conf and option parser struct bpsense_conf conf = bpsense_defaults; struct iter_admm_conf iconf = iter_admm_defaults; conf.iconf = &iconf; conf.iconf->rho = 10; // more sensibile default bool usegpu = false; const char* psf = NULL; const char* image_truth_fname = NULL; bool im_truth = false; bool use_tvnorm = false; double start_time = timestamp(); const struct opt_s opts[] = { OPT_FLOAT('e', &conf.eps, "eps", "data consistency error"), OPT_FLOAT('r', &conf.lambda, "lambda", "l2 regularization parameter"), OPT_FLOAT('u', &conf.iconf->rho, "rho", "ADMM penalty parameter"), OPT_SET('c', &conf.rvc, "real-value constraint"), OPT_SET('t', &use_tvnorm, "use TV norm"), OPT_STRING('T', &image_truth_fname, "file", "compare to truth image"), OPT_UINT('i', &conf.iconf->maxiter, "iter", "max. iterations"), OPT_SET('g', &usegpu, "(use gpu)"), OPT_STRING('p', &psf, "file", "point-spread function"), }; cmdline(&argc, argv, 3, 3, usage_str, help_str, ARRAY_SIZE(opts), opts); if (NULL != image_truth_fname) im_truth = true; // ----------------------------------------------------------- // load data and print some info about the recon int N = DIMS; long dims[N]; long dims1[N]; long img_dims[N]; long ksp_dims[N]; complex float* kspace_data = load_cfl(argv[1], N, ksp_dims); complex float* sens_maps = load_cfl(argv[2], N, dims); for (int i = 0; i < 4; i++) // sizes2[4] may be > 1 if (ksp_dims[i] != dims[i]) error("Dimensions of kspace and sensitivities do not match!\n"); assert(1 == ksp_dims[MAPS_DIM]); (usegpu ? num_init_gpu : num_init)(); if (dims[MAPS_DIM] > 1) debug_printf(DP_INFO, "%ld maps.\nESPIRiT reconstruction.\n", dims[4]); if (conf.lambda > 0.) debug_printf(DP_INFO, "l2 regularization: %f\n", conf.lambda); if (use_tvnorm) debug_printf(DP_INFO, "use Total Variation\n"); else debug_printf(DP_INFO, "use Wavelets\n"); if (im_truth) debug_printf(DP_INFO, "Compare to truth\n"); md_select_dims(N, ~(COIL_FLAG | MAPS_FLAG), dims1, dims); md_select_dims(N, ~COIL_FLAG, img_dims, dims); // ----------------------------------------------------------- // initialize sampling pattern complex float* pattern = NULL; long pat_dims[N]; if (NULL != psf) { pattern = load_cfl(psf, N, pat_dims); // FIXME: check compatibility } else { pattern = md_alloc(N, dims1, CFL_SIZE); estimate_pattern(N, ksp_dims, COIL_DIM, pattern, kspace_data); } // ----------------------------------------------------------- // print some statistics size_t T = md_calc_size(N, dims1); long samples = (long)pow(md_znorm(N, dims1, pattern), 2.); debug_printf(DP_INFO, "Size: %ld Samples: %ld Acc: %.2f\n", T, samples, (float)T/(float)samples); // ----------------------------------------------------------- // fftmod to un-center data fftmod(N, ksp_dims, FFT_FLAGS, kspace_data, kspace_data); fftmod(N, dims, FFT_FLAGS, sens_maps, sens_maps); // ----------------------------------------------------------- // apply scaling float scaling = estimate_scaling(ksp_dims, NULL, kspace_data); debug_printf(DP_INFO, "Scaling: %f\n", scaling); if (scaling != 0.) md_zsmul(N, ksp_dims, kspace_data, kspace_data, 1. / scaling); // ----------------------------------------------------------- // create l1 prox operator and transform long minsize[DIMS] = { [0 ... DIMS - 1] = 1 }; minsize[0] = MIN(img_dims[0], 16); minsize[1] = MIN(img_dims[1], 16); minsize[2] = MIN(img_dims[2], 16); const struct linop_s* l1op = NULL; const struct operator_p_s* l1prox = NULL; if (use_tvnorm) { l1op = grad_init(DIMS, img_dims, FFT_FLAGS); l1prox = prox_thresh_create(DIMS + 1, linop_codomain(l1op)->dims, 1., 0u, usegpu); conf.l1op_obj = l1op; } else { bool randshift = true; l1op = linop_identity_create(DIMS, img_dims); conf.l1op_obj = wavelet_create(DIMS, img_dims, FFT_FLAGS, minsize, false, usegpu); l1prox = prox_wavethresh_create(DIMS, img_dims, FFT_FLAGS, minsize, 1., randshift, usegpu); } // ----------------------------------------------------------- // create image and load truth image complex float* image = create_cfl(argv[3], N, img_dims); md_clear(N, img_dims, image, CFL_SIZE); long img_truth_dims[DIMS]; complex float* image_truth = NULL; if (im_truth) image_truth = load_cfl(image_truth_fname, DIMS, img_truth_dims); // ----------------------------------------------------------- // call recon if (usegpu) #ifdef USE_CUDA bpsense_recon_gpu(&conf, dims, image, sens_maps, dims1, pattern, l1op, l1prox, ksp_dims, kspace_data, image_truth); #else assert(0); #endif else
int main_pocsense(int argc, char* argv[]) { float alpha = 0.; int maxiter = 50; bool l1wav = false; float lambda = -1.; bool use_gpu = false; bool use_admm = false; float admm_rho = -1.; int l1type = 2; const struct opt_s opts[] = { { 'i', true, opt_int, &maxiter, NULL }, { 'r', true, opt_float, &alpha, " alpha\tregularization parameter" }, { 'l', true, opt_int, &l1type, "1/-l2\t\ttoggle l1-wavelet or l2 regularization" }, { 'g', false, opt_set, &use_gpu, NULL }, { 'o', true, opt_float, &lambda, NULL }, { 'm', true, opt_float, &admm_rho, NULL }, }; cmdline(&argc, argv, 3, 3, usage_str, help_str, ARRAY_SIZE(opts), opts); if (1 == l1type) l1wav = true; else if (2 == l1type) l1wav = false; else error("Unknown regularization type."); unsigned int N = DIMS; long dims[N]; long ksp_dims[N]; complex float* kspace_data = load_cfl(argv[1], N, ksp_dims); complex float* sens_maps = load_cfl(argv[2], N, dims); for (int i = 0; i < 4; i++) // sizes2[4] may be > 1 if (ksp_dims[i] != dims[i]) error("Dimensions of kspace and sensitivities do not match!\n"); assert(1 == ksp_dims[MAPS_DIM]); num_init(); long dims1[N]; md_select_dims(N, ~(COIL_FLAG|MAPS_FLAG), dims1, dims); // ----------------------------------------------------------- // memory allocation complex float* result = create_cfl(argv[3], N, ksp_dims); complex float* pattern = md_alloc(N, dims1, CFL_SIZE); // ----------------------------------------------------------- // pre-process data float scaling = estimate_scaling(ksp_dims, NULL, kspace_data); md_zsmul(N, ksp_dims, kspace_data, kspace_data, 1. / scaling); estimate_pattern(N, ksp_dims, COIL_DIM, pattern, kspace_data); // ----------------------------------------------------------- // l1-norm threshold operator const struct operator_p_s* thresh_op = NULL; const struct linop_s* wave_op = NULL; if (l1wav) { long minsize[DIMS] = { [0 ... DIMS - 1] = 1 }; minsize[0] = MIN(ksp_dims[0], 16); minsize[1] = MIN(ksp_dims[1], 16); minsize[2] = MIN(ksp_dims[2], 16); wave_op = wavelet_create(DIMS, ksp_dims, FFT_FLAGS, minsize, true, use_gpu); thresh_op = prox_unithresh_create(DIMS, wave_op, alpha, COIL_FLAG, use_gpu); } #if 0 else {