gsplat
gsplat copied to clipboard
16bit png compression
imageio supports 16bit png format through the freeimage plugin. this should be easier to use than 2 pngs?
diff --git a/gsplat/compression/png_compression.py b/gsplat/compression/png_compression.py
index 0c5010c..5a0025e 100644
--- a/gsplat/compression/png_compression.py
+++ b/gsplat/compression/png_compression.py
@@ -242,14 +242,7 @@ def _compress_png_16bit(
img_norm = grid_norm.detach().cpu().numpy()
img = (img_norm * (2**16 - 1)).round().astype(np.uint16)
- img_l = img & 0xFF
- img_u = (img >> 8) & 0xFF
- imageio.imwrite(
- os.path.join(compress_dir, f"{param_name}_l.png"), img_l.astype(np.uint8)
- )
- imageio.imwrite(
- os.path.join(compress_dir, f"{param_name}_u.png"), img_u.astype(np.uint8)
- )
+ imageio.imwrite(os.path.join(compress_dir, f"{param_name}.png"), img, format='PNG-FI')
meta = {
"shape": list(params.shape),
@@ -279,10 +272,7 @@ def _decompress_png_16bit(
params = torch.zeros(meta["shape"], dtype=getattr(torch, meta["dtype"]))
return meta
- img_l = imageio.imread(os.path.join(compress_dir, f"{param_name}_l.png"))
- img_u = imageio.imread(os.path.join(compress_dir, f"{param_name}_u.png"))
- img_u = img_u.astype(np.uint16)
- img = (img_u << 8) + img_l
+ img = imageio.imread(os.path.join(compress_dir, f"{param_name}.png"), format='PNG-FI')
img_norm = img / (2**16 - 1)
grid_norm = torch.tensor(img_norm)