Ejemplo n.º 1
0
channels = ['DAPI', 'GCaMP', 'mRuby', 'NeuN']
downsample_rate = 0.1

curr_folder = os.path.realpath(os.path.dirname(__file__))
os.chdir(curr_folder)

fns = [f for f in os.listdir(curr_folder) if f[-4:] == '.btf']
fns.sort()
print('\n'.join(fns))

for fn in fns:
    print('\nprocessing {} ...'.format(fn))
    big_img = tf.imread(fn)
    fname = os.path.splitext(fn)[0]
    print('shape: {}'.format(big_img.shape))
    print('dtype: {}'.format(big_img.dtype))

    # comb_img = []

    for chi, chn in enumerate(channels):
        print('\tchannel: {}'.format(chn))
        down_img_ch = ia.rigid_transform_cv2(big_img[chi],
                                             zoom=downsample_rate).astype(
                                                 np.uint16)[::-1, :]
        tf.imsave('thumbnail_{}_{:02d}_{}.tif'.format(fname, chi, chn),
                  down_img_ch)
        # comb_img.append(down_img_ch)

    # comb_img = np.array(comb_img)
    # tf.imsave('{}_downsampled.tif'.format(fname), comb_img)
Ejemplo n.º 2
0
big_region = (np.array(thumbnail_region) / thumbnail_d_rate).astype(np.uint64)
print('region in big image: {}'.format(big_region))

thumbnail_fns = [
    f for f in os.listdir(curr_folder) if base_name in f and f[-4:] == '.tif'
]
ch_lst = []
for chn in channels:
    curr_chi = [int(f.split('_')[-2]) for f in thumbnail_fns if chn in f]
    if len(curr_chi) != 1:
        raise LookupError
    ch_lst.append(curr_chi[0])

print('channel index list: {}'.format(ch_lst))

big_img = tf.imread(base_name + '.btf')
print('reading the big image: {}.btf ...'.format(base_name))

section_img = []

for ch_i in ch_lst:
    curr_img = big_img[ch_i][::-1, :][big_region[0]:big_region[1],
                                      big_region[2]:big_region[3]]
    curr_img = ia.rigid_transform_cv2(curr_img, zoom=d_rate).astype(np.uint16)
    section_img.append(curr_img)

section_img = np.array(section_img)

print('saving {} ...'.format(save_name))
tf.imsave(save_name, section_img)
Ejemplo n.º 3
0
print('planes:')
print('\n'.join(plane_ns))

for plane_n in plane_ns:
    print('\nprocessing plane: {}'.format(plane_n))

    save_folder = os.path.join(curr_folder, plane_n)
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    for ch_n in ch_ns:
        print('\n\tprocessing channel: {}'.format(ch_n))
        plane_folder = os.path.join(data_folder, plane_n, ch_n, 'corrected')

        # f_ns = [f for f in os.listdir(plane_folder) if f[-14:] == '_corrected.tif']
        f_ns= [f for f in os.listdir(plane_folder) if f[-4:] == '.tif' and identifier in f]
        f_ns.sort()
        print('\t\t'+'\n\t\t'.join(f_ns) + '\n')

        mov_d = []

        for f_n in f_ns:
            print('\t\tprocessing {} ...'.format(f_n))
            curr_mov = tf.imread(os.path.join(plane_folder, f_n))
            curr_mov_d = ia.rigid_transform_cv2(img=curr_mov, zoom=(1. / xy_downsample_rate))
            curr_mov_d = ia.z_downsample(curr_mov_d, downSampleRate=t_downsample_rate, is_verbose=False)
            mov_d.append(curr_mov_d)

        mov_d = np.concatenate(mov_d, axis=0)
        save_n = '{}_{}_{}_downsampled.tif'.format(os.path.split(data_folder)[1], plane_n, ch_n)
        tf.imsave(os.path.join(save_folder, save_n), mov_d)
import os
import numpy as np
import tifffile as tf
import NeuroAnalysisTools.MotionCorrection as mc
import NeuroAnalysisTools.core.ImageAnalysis as ia

fn = 'zstack_green_aligned.tif'
scope = 'sutter' # 'sutter' or 'deepscope' or 'scientifica'

curr_folder = os.path.dirname(os.path.realpath(__file__))
os.chdir(curr_folder)

stack = tf.imread(fn)

if scope == 'sutter':
	stack_r = stack.transpose((0, 2, 1))[:, ::-1, :]

elif scope == 'deepscope':
	h_new = int(stack.shape[1] * np.sqrt(2))
	w_new = int(stack.shape[2] * np.sqrt(2))
	stack_r = ia.rigid_transform_cv2(stack, rotation=140, outputShape=(h_new, w_new))[:, :, ::-1]

elif scope == 'scientifica':
	h_new = int(stack.shape[1] * np.sqrt(2))
	w_new = int(stack.shape[2] * np.sqrt(2))
	stack_r = ia.rigid_transform_cv2(stack[:,::-1,:], rotation=135, outputShape=(h_new, w_new))

else:
	raise LookupError("Do not understand scope type. Should be 'sutter' or 'deepscope' or 'scientifica'.")

tf.imsave(os.path.splitext(fn)[0] + '_rotated.tif', stack_r.astype(stack.dtype))