-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_SBReadFile.py
More file actions
146 lines (112 loc) · 5.46 KB
/
test_SBReadFile.py
File metadata and controls
146 lines (112 loc) · 5.46 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
__copyright__ = "Copyright (c) 2022-2025, Intelligent Imaging Innovations, Inc. All rights reserved. All rights reserved."
__license__ = "This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree."
from SBReadFile import *
from matplotlib import pyplot as plt
import numpy as np
import sys, getopt
def test_read_image(theFileName):
theSBFileReader = SBReadFile()
theRes = theSBFileReader.Open(theFileName)
if not theRes:
#print ('Cannot open the file: ', theFileName)
sys.exit()
theCapture = 0
theChannel = 0
theThumbnail = theSBFileReader.GetThumbnail(theCapture)
theImageName = theSBFileReader.GetImageName(theCapture)
print ("*** the image name: ",theImageName)
theImageComments = theSBFileReader.GetImageComments(theCapture)
print ("*** the image comments: ",theImageComments)
theNumPositions = theSBFileReader.GetNumPositions(theCapture)
print ("*** the image num positions: ",theNumPositions)
theNumTimepoints = theSBFileReader.GetNumTimepoints(theCapture)
print ("*** the image num timepoints: ",theNumTimepoints)
theNumChannels = theSBFileReader.GetNumChannels(theCapture)
print ("*** the image num channels: ",theNumChannels)
theNumAnnotations = theSBFileReader.GetNumROIAnnotations(theCapture)
print ("*** the image num ROI annotations: ",theNumAnnotations)
for theAnnoIndex in range (0,theNumAnnotations):
theShape,theVertexes = theSBFileReader.GetROIAnnotation(theCapture,theAnnoIndex)
print ("theShape: ",theShape)
for theVertex in theVertexes:
print(" x: ",theVertex.mX," y: ",theVertex.mY)
for theTimepoint in range(0,theNumTimepoints):
theNumRegions = theSBFileReader.GetNumFRAPRegions(theCapture,theTimepoint)
if(theNumRegions == 0):
continue
print ("*** the image num FRAP Regions ",theNumRegions, " for timepoint: ",theTimepoint)
theShape,theVertexes = theSBFileReader.GetFRAPAnnotation(theCapture,theTimepoint)
print ("the FRAPP Annotation shape : ",theShape)
for theVertex in theVertexes:
print(" x: ",theVertex.mX," y: ",theVertex.mY)
for theRegionIndex in range (0,theNumRegions):
theShape,theVertexes = theSBFileReader.GetFRAPRegion(theCapture,theTimepoint,theRegionIndex)
print ("the Frap Region shape: ",theShape)
for theVertex in theVertexes:
print(" x: ",theVertex.mX," y: ",theVertex.mY)
theX,theY,theZ = theSBFileReader.GetVoxelSize(theCapture)
print ("*** the the voxel x,y,z size is: ",theX,theY,theZ)
theY,theM,theD,theH,theMn,theS = theSBFileReader.GetCaptureDate(theCapture)
print ("*** the the date yr/mn/day/hr/min/sec is: ",theY,theM,theD,theH,theMn,theS)
theXmlDescriptor = theSBFileReader.GetAuxDataXMLDescriptor(theCapture,theChannel)
print ("*** theXmlDescriptor is " ,theXmlDescriptor)
theLen,theType = theSBFileReader.GetAuxDataNumElements(theCapture,theChannel)
print ("*** theLen,theType ",theLen,theType)
theXmlData = theSBFileReader.GetAuxSerializedData(theCapture,theChannel,0)
print ("*** theXmlData is " ,theXmlData)
theNumRows = theSBFileReader.GetNumYRows(theCapture)
theNumColumns = theSBFileReader.GetNumXColumns(theCapture)
theNumPlanes = theSBFileReader.GetNumZPlanes(theCapture)
theZplane = int(theNumPlanes/2)
for theTimepoint in range(0,theNumTimepoints):
image = theSBFileReader.ReadImagePlaneBuf(theCapture,0,theTimepoint,theZplane,0,True) #captureid,position,timepoint,zplane,channel,as 2d
print ("*** The read buffer len is: " , len(image))
#plot the slice
plt.figure(theTimepoint+1)
plt.imshow(image)
plt.pause(100)
data = input("Please hit Enter to exit:\n")
print("Done")
def test_read_mask(theFileName):
theSBFileReader = SBReadFile()
theRes = theSBFileReader.Open(theFileName,True,False) # all the metadata, dubug print
if not theRes:
#print ('Cannot open the file: ', theFileName)
sys.exit()
theCapture = 0
theNumRows = theSBFileReader.GetNumYRows(theCapture)
theNumColumns = theSBFileReader.GetNumXColumns(theCapture)
theNumPlanes = theSBFileReader.GetNumZPlanes(theCapture)
mask_names = theSBFileReader.GetMaskNames(theCapture)
print("Mask Names")
print(mask_names)
theTimepoint = 0
mask = theSBFileReader.ReadMaskBuf(theCapture,0,theTimepoint,True) #captureid,mask index,timepoint,as3d
plt.figure(theTimepoint+1)
plt.imshow(mask[0,:,:])
plt.pause(1)
data = input("Please hit Enter to exit:\n")
print("Done")
def main(argv):
# change it to use your file
#theSBFileReader.Open("/media/sf_E_DRI VE/Data/Slides/Format 7/SlideBook BCG test data/Slide1.sld")
if len(sys.argv) < 3:
print ('usage: python test_SBReadFile.py -i <inputfile>')
sys.exit(2)
theFileName = ''
try:
opts, args = getopt.getopt(argv,"hi:",["ifile="])
except getopt.GetoptError:
print ('usage: python test_SBReadFile.py -i <inputfile>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print ('usage: python test_SBReadFile.py -i <inputfile>')
sys.exit()
elif opt in ("-i", "--ifile"):
theFileName = arg
print ('Input file is ', theFileName)
#test_read_image(theFileName)
test_read_mask(theFileName)
if __name__ == "__main__":
main(sys.argv[1:])