Created
December 12, 2021 17:19
-
-
Save night-crawlr/bb2e38c2d0fafcae8de836a7020faa88 to your computer and use it in GitHub Desktop.
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 | |
# Pushing r,c,d to encode into image_data list | |
temp_list = self.im.flatten() | |
temp_list = np.append(temp_list, self.r) | |
temp_list = np.append(temp_list, self.c) | |
temp_list = np.append(temp_list, self.d) | |
self.image_data = temp_list | |
# Creating historgram from image_data to create frequencies. | |
self.hist = np.bincount( | |
self.image_data, minlength=max(256, self.r, self.c, self.d)) | |
total = np.sum(self.hist) | |
# Extracting the non-zero frequencies | |
self.freqs = [i for i, e in enumerate(self.hist) if e != 0] | |
self.freqs = np.array(self.freqs) | |
# Creatn=ing a dict of propabilities , with keys are intensities and value as propabilities | |
for i, e in enumerate(self.freqs): | |
self.prob_dict[e] = self.hist[e]/total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment