forked from jstklein/lrm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
correct-brightfield-image.py
62 lines (43 loc) · 1.48 KB
/
correct-brightfield-image.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
import numpy as np
#import matplotlib
#matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from PIL import Image
import glob
import math
#from betaprocess import Betafile
from betaimage import BetaImage
from multiprocessing.pool import ThreadPool
import skimage
import pandas as pd
from sklearn.cluster import KMeans
from sklearn.model_selection import train_test_split
from scipy.cluster.hierarchy import linkage, dendrogram
import pickle
import lz4
import os
import seaborn as sns
def load_uniformity_image():
# path to unformity measurement
pathUniformity = "/Users/jjj/Dropbox/Manuscripts/Direct beta detection/Experiments/uniformity-images-6-13-2019/bf-uniformity-lcd-6-13-2019/bf-1.j2k"
uniformity = Image.open(pathUniformity)
uni = np.array(uniformity)
uni = uni / uni.max()
return uni
# proces image files
path="/Users/jjj/Dropbox/Manuscripts/Direct beta detection/Experiments/fdg-cells-coverslip-5-16-2019/fdg-cells-coverglass-5-16-2019-combined/bf/"
prefix = ''
globDir = path + prefix + '*'
files = glob.glob(globDir)
bfTiffOut = "../bf-tiff/"
correctionImage = load_uniformity_image()
for i,f in enumerate(files):
fileName = os.path.basename(f)[:-4]
filePath = os.path.dirname(f)
print(f)
j2kImage = np.array(Image.open(f))
j2kImage = j2kImage.sum(2).astype(dtype=np.float32)
im = ( j2kImage * correctionImage)
# write file out
outFile = filePath + '/' + bfTiffOut + fileName + '.tiff'
Image.fromarray(im).save(outFile)