def main(): h = HuffmanCoding() c = Convolutional() input = "negarmirgati" print('input', input) hEncoded = h.encode(input) print('huffman coded', hEncoded) cEncoded = c.encode(hEncoded) print('Convolutional encoded', cEncoded) inputWithNoise = noise(cEncoded) print('noise added', inputWithNoise) cDecoded = c.decode(inputWithNoise) print('convolutional decode', cDecoded) hDecoded = h.decode(cDecoded) print('huffman decode', hDecoded)
def executeHuffman(original_file, complexity): # HUFFMAN CODE # ORIGINAL SIZE, COMPRESSED SIZE, DURATION, COMPLEXITY huffman_compressed = complexity + "_huffman_compressed.bin" hc = HuffmanCoding(original_file) start_compressing = time.time() hc.compress() print("Huffman compression for", complexity, "successful") end_compressing = time.time() compressed_size = getSize(huffman_compressed) start_decompressing = time.time() hc.decompress(huffman_compressed) print("Huffman decompression for", complexity, "successful") end_decompressing = time.time() original_size = getSize(original_file) efficiency = (original_size - compressed_size) / original_size * 100 decompressed_size = original_size algorithm = "Huffman" compression_duration = end_compressing - start_compressing decompression_duration = end_decompressing - start_decompressing if compression_duration != 0: angle = math.degrees( math.atan((original_size - compressed_size) / (compression_duration * 1000))) else: angle = 90 data = myData(algorithm, complexity, original_size, compressed_size, compression_duration, decompressed_size, decompression_duration, efficiency, angle) data_arr.append(data)
def compress(path, fun): h = HuffmanCoding() h.compress(path, fun)
def decompress(path, fun): h = HuffmanCoding() h.decompress(path, fun)
from Huffman import HuffmanCoding import os, time start_time = time.time() path = "sample1.txt" h = HuffmanCoding(path) print("Before Huffman Compression the file size is", os.stat(path).st_size, "bytes") output_path = h.compress() print("After Huffman Compression the file size is", os.stat(output_path).st_size, "bytes") try: print("Compression Ratio is", os.stat(path).st_size/os.stat(output_path).st_size) except: print("Compression Ratio is undefined, output size is 0 bytes.") print("This program took", time.time() - start_time, "to compress.\n") start_time = time.time() h.decompress(output_path) #Just used to decompress the file print("This program took", time.time() - start_time, "to decompress.")
from Huffman import HuffmanCoding #input file path path = "D:/Nguyen Thai Son/Freshman/Infor/lab 6/Lab_06/text1.txt" # D:/Nguyen Thai Son/Freshman/Infor/lab 6/Lab_06/text1.txt h = HuffmanCoding(path) output_path = h.compress() h.decompress(output_path)
from Huffman import HuffmanCoding from time import time from memory_profiler import profile path = "Proyecto/Código/Sin pérdida/Ensayo/00000004_66324407_ver1.csv" image = HuffmanCoding(path) inicio1 = time() compressed = image.compress(path) fin1 = time() total1 = fin1 - inicio1 print("Compressed:", total1) '''inicio2 = time() decompressed = image.decompress(compressed) fin2 = time() total2 = fin2-inicio2 print("Decompressed:", total2) ''' #image.showImage(decompressed)