Skip to content

Instantly share code, notes, and snippets.

View night-crawlr's full-sized avatar

Narain Sreehith Manubolu night-crawlr

View GitHub Profile
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'
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()
# 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
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
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'