forked from mfenner1/py_coloc_utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplyExpertThresholds.py
executable file
·61 lines (46 loc) · 1.86 KB
/
applyExpertThresholds.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
#!/usr/bin/env python
# system imports
import Image
from scipy.misc import fromimage
import numpy as np
# user defined imports
from DefinitionsAndUtils import *
from ImageProcessing import thresholdNDArray
# from GraphAndHistogramUtilities import samplePoints
threshPath = "/home/mfenner/scipy_prep/data/input/"
threshFile = threshPath + "manual-thresholds-all-conditions.csv"
# threshFile = threshPath + "manual-thresholds-sampleof-conditions.csv"
threshDicts = readThresholdFileAsDictionaries(threshFile)
cndKeys = ["Organelle", "Stain", "Time"] # , "Series"]
allPixelCt = 0
nonZeroPixelCt = 0
#
# takes threshold file as "canonical" list of experiments and files
#
# for thisStack in breakIntoStacks(threshDicts):
# for threshes in thisStack:
for thisCndSet in breakByConditions(threshDicts):
cnd = tuple((k, thisCndSet[0][k]) for k in cndKeys)
print cnd
stackArray = np.empty((0,3), np.uint8)
for threshes in thisCndSet:
print threshes["Slice"],
expertThresholds = dict(((c, threshes[c]) for c in colorNames))
#
# get file->image and thresholds together
# apply threshold
#
exampleFilename = fileNameFormat[threshes["Organelle"]] % threshes
currentImage = Image.open(imageDataPath+exampleFilename)
asArray2 = fromimage(currentImage).reshape((numImagePoints,3))
thresholdNDArray(asArray2, expertThresholds)
stackArray = np.concatenate((stackArray, asArray2))
# zero removal
currAllPixelCt = stackArray.shape[0]
stackArray = stackArray[np.any(stackArray, 1)]
currNonZeroPixelCt = stackArray.shape[0]
print "(%d --> %d)" % (currAllPixelCt, currNonZeroPixelCt)
allPixelCt += currAllPixelCt
nonZeroPixelCt += currNonZeroPixelCt
print "%15s: %12s" % ("with [0,0,0]", allPixelCt)
print "%15s: %12s" % ("removed [0,0,0]", nonZeroPixelCt)