forked from AllenNeuralDynamics/lightsheet-compression-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_trunc_filter.py
33 lines (30 loc) · 1.15 KB
/
plot_trunc_filter.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
import matplotlib.pyplot as plt
import numcodecs
import zarr
import tifffile
import numpy as np
import compress_zarr
filepath = "/allen/scratch/aindtemp/data/anatomy/2020-12-01-training-data/2020-12-01-stack-15/images/BrainSlice1_MMStack_Pos33_15_shift.tif"
slice = 438
# bounding box coordinates for ROI
minx = 2088
maxx = 2194
miny = 1505
maxy = 1598
with tifffile.TiffFile(filepath) as f:
z = zarr.open(f.aszarr(), 'r')
# Extract ROI
data = z[slice, miny:maxy, minx:maxx]
trunc_bits = [0, 2, 4, 6, 8, 10]
row = 2
col = 3
fig, ax = plt.subplots(row, col, figsize=(16, 16))
for i, tb in enumerate(trunc_bits):
filt = numcodecs.fixedscaleoffset.FixedScaleOffset(offset=0, scale=1.0 / (2 ** tb), dtype=np.uint16)
filtered = np.reshape(filt.decode(filt.encode(data)), data.shape)
metrics = compress_zarr.eval_quality(data, filtered, ['mse', 'ssim', 'psnr'])
idx = np.unravel_index(i, (row, col))
ax[idx].imshow(filtered, cmap='gray')
ax[idx].set_title(f"trunc_bits={tb}, mse={round(metrics['mse'], 2)}, ssim={round(metrics['ssim'], 4)}")
fig.savefig('./trunc_filters.png', dpi=500)
plt.show()