Beispiel #1
0
def cml_open_proj(stack, ir, ou, lf, hf, dpsi=1):
    from projection import cml_sinogram
    from utilities import model_circle, get_params_proj, model_blank, get_im
    from fundamentals import fftip
    from filter import filt_tanh

    # number of projections
    if type(stack) == type(""): nprj = EMUtil.get_image_count(stack)
    else: nprj = len(stack)
    Prj = []  # list of projections
    Ori = [
        -1
    ] * 4 * nprj  # orientation intial (phi, theta, psi, index) for each projection

    for i in xrange(nprj):
        image = get_im(stack, i)

        # read initial angles if given
        try:
            Ori[4 * i], Ori[4 * i +
                            1], Ori[4 * i +
                                    2], s2x, s2y = get_params_proj(image)
        except:
            pass

        if (i == 0):
            nx = image.get_xsize()
            if (ou < 1): ou = nx // 2 - 1
            diameter = int(2 * ou)
            mask2D = model_circle(ou, nx, nx)
            if ir > 0: mask2D -= model_circle(ir, nx, nx)

        # normalize under the mask
        [mean_a, sigma, imin, imax] = Util.infomask(image, mask2D, True)
        image -= mean_a
        Util.mul_scalar(image, 1.0 / sigma)
        Util.mul_img(image, mask2D)

        # sinogram
        sino = cml_sinogram(image, diameter, dpsi)

        # prepare the cut positions in order to filter (lf: low freq; hf: high freq)
        ihf = min(int(2 * hf * diameter), diameter + (diameter + 1) % 2)
        ihf = ihf + (ihf + 1) % 2  # index ihf must be odd to take the img part
        ilf = max(int(2 * lf * diameter), 0)
        ilf = ilf + ilf % 2  # index ilf must be even to fall in the real part
        bdf = ihf - ilf + 1

        # process lines
        nxe = sino.get_xsize()
        nye = sino.get_ysize()
        prj = model_blank(bdf, 2 * nye)
        pp = model_blank(nxe, 2 * nye)
        for li in xrange(nye):
            # get the line li
            line = Util.window(sino, nxe, 1, 1, 0, li - nye // 2, 0)
            # u2 (not improve the results)
            #line = filt_tanh(line, ou / float(nx), ou / float(nx))
            # normalize this line
            [mean_l, sigma_l, imin, imax] = Util.infomask(line, None, True)
            line = (line - mean_l) / sigma_l
            # fft
            fftip(line)
            # filter (cut part of coef) and create mirror line
            Util.cml_prepare_line(prj, line, ilf, ihf, li, nye)

        # store the projection
        Prj.append(prj)

    return Prj, Ori
Beispiel #2
0
def cml_open_proj(stack, ir, ou, lf, hf, dpsi = 1):
	from projection   import cml_sinogram
	from utilities    import model_circle, get_params_proj, model_blank, get_im
	from fundamentals import fftip
	from filter       import filt_tanh

	# number of projections
	if  type(stack) == type(""): nprj = EMUtil.get_image_count(stack)
	else:                       nprj = len(stack)
	Prj  = []                                          # list of projections
	Ori  = [-1] * 4 * nprj                             # orientation intial (phi, theta, psi, index) for each projection

	for i in xrange(nprj):
		image = get_im(stack, i)

		# read initial angles if given
		try:	Ori[4*i], Ori[4*i+1], Ori[4*i+2], s2x, s2y = get_params_proj(image)
		except:	pass
		
		if(i == 0):
			nx = image.get_xsize()
			if(ou < 1): ou = nx // 2 - 1
			diameter = int(2 * ou)
			mask2D   = model_circle(ou, nx, nx)
			if ir > 0:  mask2D -= model_circle(ir, nx, nx)

		# normalize under the mask
		[mean_a, sigma, imin, imax] = Util.infomask(image, mask2D, True)
		image -= mean_a
		Util.mul_scalar(image, 1.0/sigma)
		Util.mul_img(image, mask2D)

		# sinogram
		sino = cml_sinogram(image, diameter, dpsi)

		# prepare the cut positions in order to filter (lf: low freq; hf: high freq)
		ihf = min(int(2 * hf * diameter), diameter + (diameter + 1) % 2)
		ihf = ihf + (ihf + 1) % 2    # index ihf must be odd to take the img part
		ilf = max(int(2 * lf * diameter), 0)
		ilf = ilf + ilf % 2          # index ilf must be even to fall in the real part
		bdf = ihf - ilf + 1

		# process lines
		nxe = sino.get_xsize()
		nye = sino.get_ysize()
		prj = model_blank(bdf, 2*nye)
		pp = model_blank(nxe, 2*nye)
		for li in xrange(nye):
			# get the line li
			line = Util.window(sino, nxe, 1, 1, 0, li-nye//2, 0)
			# u2 (not improve the results)
			#line = filt_tanh(line, ou / float(nx), ou / float(nx))
			# normalize this line
			[mean_l, sigma_l, imin, imax] = Util.infomask(line, None, True)
			line = (line - mean_l) / sigma_l
			# fft
			fftip(line)
			# filter (cut part of coef) and create mirror line
			Util.cml_prepare_line(prj, line, ilf, ihf, li, nye)

		# store the projection
		Prj.append(prj)

	return Prj, Ori