-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateSegmentedImages.py
More file actions
61 lines (51 loc) · 2.1 KB
/
createSegmentedImages.py
File metadata and controls
61 lines (51 loc) · 2.1 KB
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
import sys, random
import numpy as np
import ndio.convert.png
import ndio.remote.OCP as OCP
import cutImageNAnnotations as cutImg
def getConfig():
"""Returns x-min,x-max,y-min,y-max in tuple form in respective order"""
try:
import config
return (config.X_MIN, config.X_MAX, config.Y_MIN, config.Y_MAX)
except ImportError:
maxes = cutImg.getCutValues()
cutImg.writeConfig(maxes) #creates config.py
return maxes
def getRaw(db = False):
# Careful of hardcoded filepath
if db == False:
vol = np.array([])
data = ndio.convert.png.import_png_collection('newdata/mito_data_*')
for img in data:
vol = np.dstack([vol, img]) if vol.size else img
return vol
else:
boundaries = getConfig()
oo = OCP()
#added +12 because first 10 images in stack aren't even annotated
return oo.get_cutout('kasthuri11cc', 'image', 694 + boundaries[0], 694 + boundaries[1], 1750 + boundaries[2], 1750 + boundaries[3], 1004, 1154, resolution = 3)
def getTruth(db = False):
# Careful of hardcoded filepath
if db == False:
vol = np.array([])
data = ndio.convert.png.import_png_collection('newdata/mito_anno_*')
for img in data:
vol = np.dstack([vol, img]) if vol.size else img
return vol
else:
boundaries = getConfig()
oo = OCP()
#added +12 because first 10 images in stack aren't even annotated
return oo.get_cutout('kasthuri2015_ramon_v1', 'mitochondria', 694 + boundaries[0], 694 + boundaries[1], 1750 + boundaries[2], 1750 + boundaries[3], 1004, 1154, resolution = 3)
def main():
print("Retrieving data")
mito_img = getRaw(db=True)
mito_anno = getTruth(db=True)
mito_anno = cutImg.convertToType(mito_anno, 'uint8') #uncomment/comment if you want to visually threshold the annotated mitochondr images
mito_anno = cutImg.visualThreshold(mito_anno, 255) #uncomment/comment if you want to visually threshold the annotated mitochondr images
print('Converting to png...')
cutImg.convertToPNG(mito_anno,'bestdata/mito_anno_*')
cutImg.convertToPNG(mito_img, 'bestdata/mito_data_*')
if __name__ == '__main__':
main()