forked from jstklein/lrm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lrm_process.py
41 lines (27 loc) · 1 KB
/
lrm_process.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
import lz4.frame
import numpy as np
import pickle
from fractions import Fraction
class Betafile:
def __init__(self, fileAndPath=None):
self.fileAndPath = fileAndPath
self.imageInfo = {}
if fileAndPath is not 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):
fig, ax = plt.subplots()
med = np.median(self.imageNp)
ax.imshow(self.imageNp, cmap='bone')
plt.clim(med * 0.5, med * 2)
plt.show()