forked from jstklein/lrm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
betaprocess.py
40 lines (27 loc) · 1 KB
/
betaprocess.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
import lz4.frame
import numpy as np
import pickle
from fractions import Fraction
class Betafile:
fileAndPath = ''
imageInfo = {}
def __init__(self, fileAndPath=None):
if not fileAndPath == None:
self.load(fileAndPath)
def load(self, fileAndPath):
self.fileAndPath = fileAndPath
with open(fileAndPath, 'rb') as file:
imageDict = pickle.load(file)
imageLZ4 = imageDict['image-lz4']
decompressed = lz4.frame.decompress(imageLZ4)
image = np.frombuffer(decompressed, dtype=np.uint16)
self.imageInfo = imageDict['info']
resStr = self.imageInfo['resolution']
self.resolution = list(map(int, resStr.split('x')))
self.imageNp = image.reshape((self.resolution[1], self.resolution[0]))
def show(self):
plt.figure()
med = np.median(self.imageNp)
plt.imshow(self.imageNp, cmap='bone')
plt.clim(med * 0.5, med * 2)
plt.show()