Commit d02069f0 authored by Bryce Hepner's avatar Bryce Hepner
Browse files

bryce first commit

parent f9be30e7
Loading
Loading
Loading
Loading
+171 −0
Original line number Diff line number Diff line
%% Cell type:code id: tags:

``` python
import numpy as np
from matplotlib import pyplot as plt
from itertools import product
import os
import sys
from PIL import Image
from scipy.optimize import minimize,linprog
import time
import seaborn as sns
from sklearn.neighbors import KernelDensity
import pandas as pd
from collections import Counter
import time
import numpy.linalg as la
```

%% Cell type:markdown id: tags:

Round 1 : Using PIL to compress the tiff file.
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
def file_extractor(dirname="images"):
    files = os.listdir(dirname)
    scenes = []
    for file in files:
        if file == '.DS_Store':
            continue
        else:
            scenes.append(os.path.join(dirname, file))
    return scenes

def image_extractor(scenes):
    image_folder = []
    for scene in scenes:
        files = os.listdir(scene)
        for file in files:
            if file[-5:] != ".tiff" or file[-7:] == "_6.tiff":
                continue
            else:
                image_folder.append(os.path.join(scene, file))
    return image_folder #returns a list of file paths to .tiff files in the specified directory given in file_extractor
```

%% Cell type:code id: tags:

``` python
scenes = file_extractor()
images = image_extractor(scenes)
```

%% Cell type:code id: tags:

``` python
first_example = images[0]
picture = Image.open(first_example)
print(picture.size)
```

%% Output

    (640, 513)

%% Cell type:code id: tags:

``` python
picture.save("Compressed_Test.tiff",compression='tiff_lzw')
```

%% Cell type:code id: tags:

``` python
compressed_location = "Compressed_Test.tiff"
```

%% Cell type:code id: tags:

``` python
compressed_image = Image.open(compressed_location)
```

%% Cell type:code id: tags:

``` python
print(compressed_image.size)
```

%% Output

    (640, 513)

%% Cell type:code id: tags:

``` python
from PIL import features
print(features.check('libtiff'))
```

%% Output

    True

%% Cell type:code id: tags:

``` python
size = os.path.getsize(compressed_location)
```

%% Cell type:code id: tags:

``` python
print(size)
```

%% Output

    473404

%% Cell type:code id: tags:

``` python
oldsize = os.path.getsize(first_example)
```

%% Cell type:code id: tags:

``` python
print(size/oldsize)
```

%% Output

    0.7203380417135197

%% Cell type:code id: tags:

``` python
from PIL import TiffTags
TiffTags.LIBTIFF_CORE.add(317)
picture.save('round_2.tiff', compression='tiff_lzw', tiffinfo={317: 2})
```

%% Cell type:code id: tags:

``` python
print(os.path.getsize('round_2.tiff'))
```

%% Output

    404176

%% Cell type:code id: tags:

``` python
print(404176/oldsize)
```

%% Output

    0.6149997641498668

%% Cell type:code id: tags:

``` python
```