This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
from copy import deepcopy as cp | |
class Node: | |
def __init__(self, f, p, isLeaf=0): | |
self.freq = f # For storing intensity | |
self.prob = p # For storing Probability | |
self.word = "" # For coded word ex : '100101' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def readImage(self, path): | |
self.path_in = path | |
try: | |
self.im = cv2.imread(path) | |
except: | |
print("Error in reading image") | |
def initialise(self): | |
self.r, self.c, self.d = self.im.shape |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Creating Nodes for intensities | |
def buildNodes(self): | |
for key in self.prob_dict: | |
leaf = Node(key, self.prob_dict[key], 1) | |
self.allNodes.append(leaf) | |
# comparator function for sorting | |
def prob_key(self, e): | |
return e.prob |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sendBinaryData(self, path): | |
# Our self.encodedString is just list of strigs with characters char('0') & char('1') | |
# but we should not directly write char('0') and char('1') , because each of them take 1byte = 8bits, so we are converting the char('0') and char('1') to binary(0) & binary(1) | |
# To do the above work we are using bitstring from BitArray library | |
from bitstring import BitArray | |
file = open(path, 'wb') | |
obj = BitArray(bin=self.encodedString) | |
obj.tofile(file) | |
file.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
from copy import deepcopy as cp | |
class Node: | |
def __init__(self, f, p, isLeaf=0): | |
self.freq = f # For storing intensity | |
self.prob = p # For storing Probability | |
self.word = "" # For coded word ex : '100101' |