-><ahref='file:///~/.local/lib/python3.8/site-packages/PIL/Image.py?line=2929'>2930</a>raiseTypeError("Cannot handle this data type: %s, %s"%typekey)frome
Conclusion : The best that I could get using the lzw compressor from PIL was 61.5%. This is worse than the other one at 40, which is likely because it is using multiple channels instead of just one.
%% Cell type:code id: tags:
``` python
deffile_extractor(dirname="images"):
files=os.listdir(dirname)
scenes=[]
forfileinfiles:
iffile=='.DS_Store':
continue
else:
scenes.append(os.path.join(dirname,file))
returnscenes
defimage_extractor(scenes):
image_folder=[]
forsceneinscenes:
files=os.listdir(scene)
forfileinfiles:
iffile[-5:]!=".tiff"orfile[-7:]=="_6.tiff":
continue
else:
image_folder.append(os.path.join(scene,file))
returnimage_folder#returns a list of file paths to .tiff files in the specified directory given in file_extractor
Conclusion:Thedocumentationwasterrible.Itadvertizescompressionbutdoesn't say how it'sdone,andthespecificsofit.Movingontosomethingelse,butstillworthashot.
%%Celltype:codeid:tags:
``` python
scenes = file_extractor()
images = image_extractor(scenes)
first_source = images[0]
picture = Image.open(first_source)
print(picture.size)
```
%% Output
<PIL.TiffImagePlugin.TiffImageFile image mode=I;16B size=640x513 at 0x7F3520192160>
(640, 513)
%% Cell type:code id: tags:
``` python
import tifffile
```
%% Cell type:code id: tags:
``` python
otherpic = tifffile.imread(first_source)
print(otherpic)
```
%% Output
[[ 2 1 54668 ... 65535 65535 65535]
[22275 22292 22292 ... 22280 22212 22270]
[22303 22301 22298 ... 22254 22248 22262]
...
[21832 21820 21844 ... 21892 21852 21845]
[21843 21821 21830 ... 21870 21865 21864]
[21836 21829 21840 ... 21858 21857 21860]]
%% Cell type:markdown id: tags:
Round 3: Trying numcompress, something that compresses numbers. Should provide an ok benchmark, and is actually documented.
Conclusion: The headline spoofed, it said I could get over 80%, I got under 30%. So that's worth looking into. Also this algorithm doesn't look into verticle changes, just horizontal, so I don't know why they advertized it to be as good as it is. No way it could be better than PNG, which doesn't advertize anything that high.
%% Cell type:code id: tags:
``` python
from numcompress import compress_ndarray, decompress_ndarray