Skip to content

Instantly share code, notes, and snippets.

@night-crawlr
Last active December 12, 2021 17:14
Show Gist options
  • Save night-crawlr/ff0193ec2cbb65dbaef0207ddb29b679 to your computer and use it in GitHub Desktop.
Save night-crawlr/ff0193ec2cbb65dbaef0207ddb29b679 to your computer and use it in GitHub Desktop.
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'
# Pointers for children, C[0] for left child, c[1] for right child
self.c = [None, None]
self.isLeaf = isLeaf # Flag for Leaf-Nodes
class Image:
def __init__(self):
self.path_in = "" # Input file Location
self.path_out = "" # Output file Location
self.im = np.zeros(1) # Input Image
self.out = np.zeros(1) # Output Image
self.image_data = np.zeros(1) # List of Intensities and dimensions
self.r = 0 # Rows
self.c = 0 # Coloums
self.d = 0 # Depth / channels
# histogram, ie frequency count of each data value
self.hist = np.zeros(1)
self.freqs = np.zeros(1) # For Non-zero frequency
# Dictionary with key as freqs and values as Probailities
self.prob_dict = {}
self.allNodes = [] # Container for All created Nodes
self.leafNodes = {} # Container for Leaf Nodes
self.root = Node(-1, -1) # Root Node with Probability = 1
# Encoded String of Image,form: "01001010101011......", interpretation : [r,c,d,[..pxls]]
self.encodedString = ""
# Decoded List of integers when read from .bin file, form : [456,342,3,34,2,120,44, ...... ], interpretation : [r,c,d,[..pxls]]
self.decodeList = []
# Binary from file in for of integers ie [0,1,0,0,1,0,1,0,1,0,1,0,1,1,......]
self.binaryFromFile = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment