int main_ecaltwo(int argc, char* argv[])
{
	long maps = 2; // channels;
	struct ecalib_conf conf = ecalib_defaults;

	int c;
	while (-1 != (c = getopt(argc, argv, "OSc:m:gh"))) {

		switch (c) {

		case 'S':
			conf.softcrop = true;
			break;

		case 'O':
			conf.orthiter = false;
			break;

		case 'c':
			conf.crop = atof(optarg);
			break;

		case 'm':
			maps = atoi(optarg);
			break;

		case 'g':
			conf.usegpu = true;
			break;
			
		case 'h':
			usage(argv[0], stdout);
			help();
			exit(0);

		default:
			usage(argv[0], stderr);
			exit(1);
		}
	}

	if ((argc - optind != 5) && (argc - optind != 6)) {

		usage(argv[0], stderr);
		exit(1);
	}

	long in_dims[DIMS];

	complex float* in_data = load_cfl(argv[optind + 3], DIMS, in_dims);

	int channels = 0;

	while (in_dims[3] != (channels * (channels + 1) / 2))
		channels++;

	printf("Channels: %d\n", channels);

	assert(maps <= channels);


	long out_dims[DIMS] = { [0 ... DIMS - 1] = 1 };
	long map_dims[DIMS] = { [0 ... DIMS - 1] = 1 };
	
	out_dims[0] = atoi(argv[optind + 0]);
	out_dims[1] = atoi(argv[optind + 1]);
	out_dims[2] = atoi(argv[optind + 2]);
	out_dims[3] = channels;
	out_dims[4] = maps;

	assert((out_dims[0] >= in_dims[0]));
	assert((out_dims[1] >= in_dims[1]));
	assert((out_dims[2] >= in_dims[2]));


	for (int i = 0; i < 3; i++)
		map_dims[i] = out_dims[i];

	map_dims[3] = 1;
	map_dims[4] = maps;


	complex float* out_data = create_cfl(argv[optind + 4], DIMS, out_dims);
	complex float* emaps;

	if (6 == argc - optind)
		emaps = create_cfl(argv[optind + 5], DIMS, map_dims);
	else
		emaps = md_alloc(DIMS, map_dims, CFL_SIZE);

	caltwo(&conf, out_dims, out_data, emaps, in_dims, in_data, NULL, NULL);

	if (conf.intensity) {

		debug_printf(DP_DEBUG1, "Normalize...\n");

		normalizel1(DIMS, COIL_FLAG, out_dims, out_data);
	}

	debug_printf(DP_DEBUG1, "Crop maps... (%.2f)\n", conf.crop);

	crop_sens(out_dims, out_data, conf.softcrop, conf.crop, emaps);

	debug_printf(DP_DEBUG1, "Fix phase...\n");

	fixphase(DIMS, out_dims, COIL_DIM, out_data, out_data);

	printf("Done.\n");

	unmap_cfl(DIMS, in_dims, in_data);
	unmap_cfl(DIMS, out_dims, out_data);

	if (6 == argc - optind)
		unmap_cfl(DIMS, map_dims, emaps);
	else
		md_free(emaps);

	exit(0);
}
示例#2
0
文件: grecon.c 项目: andruw17/bart
void grecon(struct grecon_conf* param,  const long dims1[DIMS], complex float* out1, 
	const long cov1_dims[DIMS], complex float* cov1,
	const long w1_dims[DIMS], const complex float* weights,
	complex float* kspace1, bool usegpu)
{
	struct sense_conf* conf = param->sense_conf;

	long ksp1_dims[DIMS];
	md_select_dims(DIMS, ~MAPS_FLAG, ksp1_dims, dims1);

	long pat1_dims[DIMS];
	const complex float* pattern;

	if (NULL == weights) {

		md_select_dims(DIMS, ~(COIL_FLAG | MAPS_FLAG), pat1_dims, dims1);
		complex float* tpattern = md_alloc(DIMS, pat1_dims, CFL_SIZE);
		estimate_pattern(DIMS, ksp1_dims, COIL_DIM, tpattern, kspace1);
		pattern = tpattern;

	} else {

		md_copy_dims(DIMS, pat1_dims, w1_dims);
		pattern = weights;
	}

	complex float* sens1;

	if (NULL != param->calib) {

		long img1_dims[DIMS];
		md_select_dims(DIMS, ~COIL_FLAG, img1_dims, dims1);

		complex float* maps1 = md_alloc(DIMS, img1_dims, CFL_SIZE);

		sens1 = md_alloc(DIMS, dims1, CFL_SIZE);
	
		caltwo(param->calib, dims1, sens1, maps1, cov1_dims, cov1, NULL, NULL);

		crop_sens(dims1, sens1, param->calib->softcrop, param->calib->crop, maps1);

		fixphase(DIMS, dims1, COIL_DIM, sens1, sens1);

		md_free(maps1);

	} else {

		sens1 = cov1;
	}

	if (NOIR == param->algo) {

		assert(NULL == param->calib);
		assert(1 == dims1[MAPS_DIM]);

		sens1 = md_alloc(DIMS, dims1, CFL_SIZE);
		md_clear(DIMS, dims1, sens1, CFL_SIZE);
		fftmod(DIMS, ksp1_dims, FFT_FLAGS, kspace1, kspace1);
	}

	fftmod(DIMS, dims1, FFT_FLAGS, sens1, sens1);
	fftmod(DIMS, ksp1_dims, FFT_FLAGS, kspace1, kspace1);

	complex float* image1 = NULL;

	long img1_dims[DIMS];
	md_select_dims(DIMS, ~COIL_FLAG, img1_dims, dims1);

	if (param->ksp && (POCS != param->algo)) {

		image1 = md_alloc(DIMS, img1_dims, CFL_SIZE);
		md_clear(DIMS, img1_dims, image1, CFL_SIZE);

	} else {

		image1 = out1;
	}


#ifdef  USE_CUDA
	int gpun = 0;

	if (usegpu) {

		int nr_cuda_devices = MIN(cuda_devices(), MAX_CUDA_DEVICES);
		gpun = omp_get_thread_num() % nr_cuda_devices;
		cuda_init(gpun);
	}
#endif

	const struct operator_p_s* thresh_op = NULL;

	if (param->l1wav) {

		long minsize[DIMS] = { [0 ... DIMS - 1] = 1 };
		minsize[0] = MIN(img1_dims[0], 16);
		minsize[1] = MIN(img1_dims[1], 16);
		minsize[2] = MIN(img1_dims[2], 16);
#ifndef W3
		thresh_op = prox_wavethresh_create(DIMS, img1_dims, FFT_FLAGS, minsize, param->lambda, param->randshift, usegpu);
#else
		unsigned int wflags = 0;
		for (unsigned int i = 0; i < 3; i++)
			if (1 < img1_dims[i])
				wflags = MD_SET(wflags, i);

		thresh_op = prox_wavelet3_thresh_create(DIMS, img1_dims, wflags, minsize, param->lambda, param->randshift);
#endif
	}
示例#3
0
int main_ecaltwo(int argc, char* argv[])
{
	long maps = 2; // channels;
	struct ecalib_conf conf = ecalib_defaults;


	const struct opt_s opts[] = {

		OPT_FLOAT('c', &conf.crop, "crop_value", "Crop the sensitivities if the eigenvalue is smaller than {crop_value}."),
		OPT_LONG('m', &maps, "maps", "Number of maps to compute."),
		OPT_SET('S', &conf.softcrop, "()"),
		OPT_CLEAR('O', &conf.orthiter, "()"),
		OPT_SET('g', &conf.usegpu, "()"),
	};

	cmdline(&argc, argv, 5, 6, usage_str, help_str, ARRAY_SIZE(opts), opts);


	long in_dims[DIMS];

	complex float* in_data = load_cfl(argv[4], DIMS, in_dims);

	int channels = 0;

	while (in_dims[3] != (channels * (channels + 1) / 2))
		channels++;

	debug_printf(DP_INFO, "Channels: %d\n", channels);

	assert(maps <= channels);


	long out_dims[DIMS] = { [0 ... DIMS - 1] = 1 };
	long map_dims[DIMS] = { [0 ... DIMS - 1] = 1 };
	
	out_dims[0] = atoi(argv[1]);
	out_dims[1] = atoi(argv[2]);
	out_dims[2] = atoi(argv[3]);
	out_dims[3] = channels;
	out_dims[4] = maps;

	assert((out_dims[0] >= in_dims[0]));
	assert((out_dims[1] >= in_dims[1]));
	assert((out_dims[2] >= in_dims[2]));


	for (int i = 0; i < 3; i++)
		map_dims[i] = out_dims[i];

	map_dims[3] = 1;
	map_dims[4] = maps;


	complex float* out_data = create_cfl(argv[5], DIMS, out_dims);
	complex float* emaps;

	if (7 == argc)
		emaps = create_cfl(argv[6], DIMS, map_dims);
	else
		emaps = md_alloc(DIMS, map_dims, CFL_SIZE);

	caltwo(&conf, out_dims, out_data, emaps, in_dims, in_data, NULL, NULL);

	if (conf.intensity) {

		debug_printf(DP_DEBUG1, "Normalize...\n");

		normalizel1(DIMS, COIL_FLAG, out_dims, out_data);
	}

	debug_printf(DP_DEBUG1, "Crop maps... (%.2f)\n", conf.crop);

	crop_sens(out_dims, out_data, conf.softcrop, conf.crop, emaps);

	debug_printf(DP_DEBUG1, "Fix phase...\n");

	fixphase(DIMS, out_dims, COIL_DIM, out_data, out_data);

	debug_printf(DP_INFO, "Done.\n");

	unmap_cfl(DIMS, in_dims, in_data);
	unmap_cfl(DIMS, out_dims, out_data);

	if (7 == argc)
		unmap_cfl(DIMS, map_dims, emaps);
	else
		md_free(emaps);

	exit(0);
}
示例#4
0
文件: calib.c 项目: thisiscam/bart
void calib2(const struct ecalib_conf* conf, const long out_dims[DIMS], complex float* out_data, complex float* eptr, unsigned int SN, float svals[SN], const long calreg_dims[DIMS], const complex float* data, const long msk_dims[3], const bool* msk)
{
	long channels = calreg_dims[3];
	long maps = out_dims[4];

	assert(calreg_dims[3] == out_dims[3]);
	assert(maps <= channels);

	assert(1 == md_calc_size(DIMS - 5, out_dims + 5));
	assert(1 == md_calc_size(DIMS - 5, calreg_dims + 5));

	complex float rot[channels][channels];

	if (conf->rotphase) {

		long scc_dims[DIMS] = MD_INIT_ARRAY(DIMS, 1);
		scc_dims[COIL_DIM] = channels;
		scc_dims[MAPS_DIM] = channels;
		scc(scc_dims, &rot[0][0], calreg_dims, data);

	} else {

		for (unsigned int i = 0; i < channels; i++)
			for (unsigned int j = 0; j < channels; j++)
				rot[i][j] = (i == j) ? 1. : 0.;
	}


	long cov_dims[4];

	calone_dims(conf, cov_dims, channels);

	complex float* imgcov = md_alloc(4, cov_dims, CFL_SIZE);

	calone(conf, cov_dims, imgcov, SN, svals, calreg_dims, data);

	caltwo(conf, out_dims, out_data, eptr, cov_dims, imgcov, msk_dims, msk);

	/* Intensity and phase normalization similar as proposed
	 * for adaptive combine (Walsh's method) in
	 * Griswold et al., ISMRM 10:2410 (2002)
	 */

	if (conf->intensity) {

		debug_printf(DP_DEBUG1, "Normalize...\n");

		/* I think the reason this works is because inhomogeneity usually
		 * comes from only a few coil elements which are close. The l1-norm
		 * is more resilient against such outliers. -- Martin
		 */

		normalizel1(DIMS, COIL_FLAG, out_dims, out_data);
		md_zsmul(DIMS, out_dims, out_data, out_data, sqrtf((float)channels));
	}

	debug_printf(DP_DEBUG1, "Crop maps... (%.2f)\n", conf->crop);

	crop_sens(out_dims, out_data, conf->softcrop, conf->crop, eptr);

	debug_printf(DP_DEBUG1, "Fix phase...\n");


	// rotate the the phase with respect to the first principle component
	fixphase2(DIMS, out_dims, COIL_DIM, rot[0], out_data, out_data);

	md_free(imgcov);
}