This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
forked from Sloth1427/10x_analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_random_collection_ims.py
68 lines (46 loc) · 2.05 KB
/
sort_random_collection_ims.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
from os.path import isfile, join
import image_analysis_module2 as IA # my custom module
import matplotlib.pyplot as plt
import numpy as np
import PIL
from tkinter import filedialog
from tkinter import *
import cv2 as cv
# set working dir as parent dir that contains all the dirs for different time points and channels
#working_dir = '/home/jacob/Documents/Chubb_lab/notebook/why_beome_a_stalk_cell/imaging_dediff_cell_and_measuring_CryS_/analysis'
#os.chdir(working_dir)
## go through each dir and stitch images within based on x and y coordinates ##
# set dir that contains all the dirs for different time points and channels
#data_dir = '/home/jacob/Documents/Chubb_lab/notebook/why_beome_a_stalk_cell/imaging_dediff_cell_and_measuring_CryS_/analysis/100419_JR3_testing'
# or let user select dir from dialog
root = Tk()
data_dir = filedialog.askdirectory(parent=root, initialdir="/media/jacob/data/Chubb_lab/notebook/why_become_a_stalk_cell/imaging_dediff_cell_and_measuring_CryS_/cont_for_manual_tracking/10x/131119_JR6_10x_bottom_testing", title='Please select directory containing all directories with unstitched images')
flist = [f for f in os.listdir(data_dir) if isfile(join(data_dir + '/', f))]
flist = [os.path.join(data_dir, f) for f in flist] # add path to each file
# sort flist based ion modification time
flist.sort(key=lambda x: os.path.getmtime(x))
# split into channels
# w470_list = []
#
# w572_list = []
#
# for f in flist:
# if '572_bottom' in f:
# w572_list = w572_list + [f]
# elif '470_bottom' in f:
# w470_list = w470_list + [f]
w572_frame_counter = 1
w470_frame_counter = 1
for i in range(0, len(flist), 9):
collection = flist[i: i + 9]
if '572_bottom' in collection[0]:
new_dir = 'w572_' + str(w572_frame_counter)
w572_frame_counter += 1
else:
new_dir = 'w470_' + str(w470_frame_counter)
w470_frame_counter += 1
os.mkdir(data_dir + '/' + new_dir)
for f in collection:
fname = os.path.basename(f)
os.rename(f, data_dir + '/' + new_dir + '/' + fname)