Commit 45e246f4 authored by Bryce Hepner's avatar Bryce Hepner

Works, used to test all the files

parent ad92c63a
...@@ -14,6 +14,14 @@ folder_name = "images" ...@@ -14,6 +14,14 @@ folder_name = "images"
outputlocation = "" outputlocation = ""
def file_extractor(dirname="images"): def file_extractor(dirname="images"):
"""Find all the files in the directory
Parameters:
dirname (str): the directory name
Returns:
files (list): a list of all the files in the directory
"""
files = os.listdir(dirname) files = os.listdir(dirname)
scenes = [] scenes = []
for file in files: for file in files:
...@@ -24,6 +32,13 @@ def file_extractor(dirname="images"): ...@@ -24,6 +32,13 @@ def file_extractor(dirname="images"):
return scenes return scenes
def image_extractor(scenes): def image_extractor(scenes):
"""
This function gives the list of all of the valid images
Parameters:
scenes (list): a list of all the files in the directory
Returns:
images (list): a list of all the images in the directory
"""
image_folder = [] image_folder = []
for scene in scenes: for scene in scenes:
files = os.listdir(scene) files = os.listdir(scene)
...@@ -34,29 +49,6 @@ def image_extractor(scenes): ...@@ -34,29 +49,6 @@ def image_extractor(scenes):
image_folder.append(os.path.join(scene, file)) 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 return image_folder #returns a list of file paths to .tiff files in the specified directory given in file_extractor
def im_distribution(images, num):
"""
Function that extracts tiff files from specific cameras and returns a list of all
the tiff files corresponding to that camera. i.e. all pictures labeled "_7.tiff" or otherwise
specified camera numbers.
Parameters:
images (list): list of all tiff files, regardless of classification. This is NOT a list of directories but
of specific tiff files that can be opened right away. This is the list that we iterate through and
divide.
num (str): a string designation for the camera number that we want to extract i.e. "14" for double digits
of "_1" for single digits.
Returns:
tiff (list): A list of tiff files that have the specified designation from num. They are the files extracted
from the 'images' list that correspond to the given num.
"""
tiff = []
for im in images:
if im[-7:-5] == num:
tiff.append(im)
return tiff
def predict_pix(tiff_image_path, difference = True): def predict_pix(tiff_image_path, difference = True):
""" """
...@@ -74,7 +66,7 @@ def predict_pix(tiff_image_path, difference = True): ...@@ -74,7 +66,7 @@ def predict_pix(tiff_image_path, difference = True):
Return: Return:
image ndarray(512 X 640): original image image ndarray(512 X 640): original image
predict ndarray(325380,): predicted image excluding the boundary
diff. ndarray(325380,): IF difference = TRUE, difference between the min and max of four neighbors exclude the boundary diff. ndarray(325380,): IF difference = TRUE, difference between the min and max of four neighbors exclude the boundary
ELSE: the residuals of the four nearest pixels to a fitted hyperplane ELSE: the residuals of the four nearest pixels to a fitted hyperplane
error ndarray(325380,): difference between the original image and predicted image error ndarray(325380,): difference between the original image and predicted image
...@@ -140,6 +132,7 @@ class NodeTree(object): ...@@ -140,6 +132,7 @@ class NodeTree(object):
return self.left, self.right return self.left, self.right
def __str__(self): def __str__(self):
"Technically does not return a string, cannot be used with print"
return self.left, self.right return self.left, self.right
...@@ -188,15 +181,8 @@ def make_dictionary(tiff_image_path_list, num_bins=4, difference = True): ...@@ -188,15 +181,8 @@ def make_dictionary(tiff_image_path_list, num_bins=4, difference = True):
num_bins (int): number of bins num_bins (int): number of bins
Return: Return:
huffman_encoding_list list (num_bins + 1): a list of dictionary huffman_encoding_list list (num_bins + 1): a list of dictionary, each dictionary is a huffman encoding
image_array ndarray (512, 640): original image
new_error ndarray (512, 640): error that includes the boundary
diff ndarray (510, 638): difference of min and max of the 4 neighbors
boundary ndarray (2300,): the boundary values after subtracting the very first pixel value
predict ndarray (325380,): the list of predicted values
bins list (num_bins - 1,): a list of threshold to cut the bins bins list (num_bins - 1,): a list of threshold to cut the bins
A ndarray (3 X 3): system of equation
""" """
list_of_all_vals = [] list_of_all_vals = []
huffman_encoding_list = [] huffman_encoding_list = []
...@@ -289,10 +275,6 @@ def huffman(tiff_image_path, num_bins=4, difference = True): ...@@ -289,10 +275,6 @@ def huffman(tiff_image_path, num_bins=4, difference = True):
# get the image_as_array, etc # get the image_as_array, etc
image_as_array, diff, error= predict_pix(tiff_image_path, difference) image_as_array, diff, error= predict_pix(tiff_image_path, difference)
# calculate the number of points that will go in each bin
# sort the difference and create the bins
bins = [21,32,48] bins = [21,32,48]
# get the boundary # get the boundary
boundary = np.hstack((image_as_array[0,:],image_as_array[-1,:],image_as_array[1:-1,0],image_as_array[1:-1,-1])) boundary = np.hstack((image_as_array[0,:],image_as_array[-1,:],image_as_array[1:-1,0],image_as_array[1:-1,-1]))
...@@ -530,7 +512,3 @@ for i in range(len(images)): ...@@ -530,7 +512,3 @@ for i in range(len(images)):
# encoded_string2 = bytes_to_bitstring(read_from_file(item)) # encoded_string2 = bytes_to_bitstring(read_from_file(item))
# reconstruct_image = decoder(encoded_string2, list_dic, bins, False) # reconstruct_image = decoder(encoded_string2, list_dic, bins, False)
# print(np.allclose(image, reconstruct_image)) # print(np.allclose(image, reconstruct_image))
print(np.mean(file_size_ratios))
print(np.max(file_size_ratios))
print(np.min(file_size_ratios))
print(np.argmax(file_size_ratios))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment