Commit 669a9a33 authored by Bryce Hepner's avatar Bryce Hepner
Browse files

Tests on lwz

parent 98603e37
Loading
Loading
Loading
Loading
+31 −3
Original line number Original line Diff line number Diff line
%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` python
``` python
from WorkingPyDemo import *
from WorkingPyDemo import *
from time import time
from time import time
from scipy import misc
from scipy import misc
import imageio
import imageio
import png
import png
```
```


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` python
``` python
scenes = file_extractor(folder_name)
scenes = file_extractor(folder_name)
images = image_extractor(scenes)
images = image_extractor(scenes)
print(len(images))
print(len(images))
newnamesforlater = []
newnamesforlater = []
file_sizes_new = []
file_sizes_new = []
file_sizes_old = []
file_sizes_old = []
list_dic = np.load("first_dic.npy", allow_pickle="TRUE")
list_dic = np.load("first_dic.npy", allow_pickle="TRUE")
bins = [21,32,48]
bins = [21,32,48]
for i in range(len(images)):
for i in range(len(images)):


    if images[i][-5:] == ".tiff":
    if images[i][-5:] == ".tiff":
        newname = images[i][:-5]
        newname = images[i][:-5]
    else:
    else:
        newname = images[i][:-4]
        newname = images[i][:-4]
    newnamesforlater.append(newname + "_Compressed.txt")
    newnamesforlater.append(newname + "_Compressed.txt")
    with open(newname + "_Compressed.txt", 'wb') as f:
    # with open(newname + "_Compressed.txt", 'wb') as f:
        f.write(inletters)
    #     f.write(inletters)
    file_sizes_new.append((os.path.getsize(newname + "_Compressed.txt")))
    file_sizes_new.append((os.path.getsize(newname + "_Compressed.txt")))
    file_sizes_old.append((os.path.getsize(images[i])))
    file_sizes_old.append((os.path.getsize(images[i])))
file_sizes_new.append(os.path.getsize("first_dic.npy"))
file_sizes_new.append(os.path.getsize("first_dic.npy"))
print(np.sum(file_sizes_new)/np.sum(file_sizes_old))
print(np.sum(file_sizes_new)/np.sum(file_sizes_old))
```
```


%% Output
%% Output


    262
    262
    0.39837348558217806
    0.3968581030135283


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` python
``` python
pngsizes = []
pngsizes = []
for i, filename in enumerate(images):
for i, filename in enumerate(images):
    newimage = Image.open(filename)
    newimage = Image.open(filename)
    newimage = np.array(newimage)
    newimage = np.array(newimage)
    newimage = newimage[1:]
    newimage = newimage[1:]
    with open(newnamesforlater[i][:-4] + ".png", 'wb') as f:
    with open(newnamesforlater[i][:-4] + ".png", 'wb') as f:
        writer = png.Writer(newimage.shape[1], newimage.shape[0], greyscale=True, bitdepth=16)
        writer = png.Writer(newimage.shape[1], newimage.shape[0], greyscale=True, bitdepth=16)
        writer.write(f, newimage)
        writer.write(f, newimage)
    # imageio.imwrite(newnamesforlater[i][:-4] + ".png", newimage)
    # imageio.imwrite(newnamesforlater[i][:-4] + ".png", newimage)
    # newimage.close()
    # newimage.close()
    pngsizes.append(os.path.getsize(newnamesforlater[i][:-4] + ".png"))
    pngsizes.append(os.path.getsize(newnamesforlater[i][:-4] + ".png"))
print(np.sum(pngsizes)/np.sum(file_sizes_old))
print(np.sum(pngsizes)/np.sum(file_sizes_old))
```
```


%% Output
%% Output


    0.6104417990437042
    0.6104417990437042


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` python
``` python
print(os.path.getsize("1626032610_393963_0.xcf")/os.path.getsize("images/1626032610_393963/1626032610_393963_0.tiff"))
print(os.path.getsize("1626032610_393963_0.xcf")/os.path.getsize("images/1626032610_393963/1626032610_393963_0.tiff"))
```
```


%% Output
%% Output


    0.5676821409714287
    0.5676821409714287


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` python
``` python
print(os.path.getsize("1626032610_393963_0.png")/os.path.getsize("images/1626032610_393963/1626032610_393963_0.tiff"))
print(os.path.getsize("1626032610_393963_0.png")/os.path.getsize("images/1626032610_393963/1626032610_393963_0.tiff"))
```
```


%% Output
%% Output


    0.4855910784741866
    0.4855910784741866


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` python
``` python
for i, filename in enumerate(images):
for i, filename in enumerate(images):
    original = Image.open(filename)
    original = Image.open(filename)
    compressed = Image.open(newnamesforlater[i][:-4] + ".png")
    compressed = Image.open(newnamesforlater[i][:-4] + ".png")
    original = np.array(original)[1:]
    original = np.array(original)[1:]
    compressed = np.array(compressed)
    compressed = np.array(compressed)
    if not np.allclose(original, compressed):
    if not np.allclose(original, compressed):
        print(i)
        print(i)
```
```


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` python
``` python
print((np.sum(pngsizes) - np.sum(file_sizes_new))/np.sum(pngsizes))
print((np.sum(pngsizes) - np.sum(file_sizes_new))/np.sum(pngsizes))
```
```


%% Output
%% Output


    0.34740136372336333
    0.34740136372336333


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` python
``` python
```
```

%% Cell type:code id: tags:

``` python
from PIL import TiffTags
TiffTags.LIBTIFF_CORE.add(318)
```

%% Cell type:code id: tags:

``` python
lwz_sizes = []
for i, filename in enumerate(images):
    newimage = Image.open(filename)
    newimage.save(newnamesforlater[i][:-4]+ "lzw" + ".tiff", compression='tiff_lzw', tiffinfo={317: 2})

    lwz_sizes.append(os.path.getsize(newnamesforlater[i][:-4]+ "lzw" + ".tiff"))
print(np.sum(lwz_sizes)/np.sum(file_sizes_old))
```

%% Output

    0.6185872808807661

%% Cell type:code id: tags:

``` python
```