Skip to content

Image processing algorithms added #616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 28 15:22:29 2018

@author: Binish125
"""
import copy
import os

import numpy as np

import cv2
import matplotlib.pyplot as plt


class contrastStretch:
def __init__(self):
self.img = ""
self.original_image = ""
self.last_list = []
self.rem = 0
self.L = 256
self.sk = 0
self.k = 0
self.number_of_rows = 0
self.number_of_cols = 0

def stretch(self, input_image):
self.img = cv2.imread(input_image, 0)
self.original_image = copy.deepcopy(self.img)
x, _, _ = plt.hist(self.img.ravel(), 256, [0, 256], label="x")
self.k = np.sum(x)
for i in range(len(x)):
prk = x[i] / self.k
self.sk += prk
last = (self.L - 1) * self.sk
if self.rem != 0:
self.rem = int(last % last)
last = int(last + 1 if self.rem >= 0.5 else last)
self.last_list.append(last)
self.number_of_rows = int(np.ma.count(self.img) / self.img[1].size)
self.number_of_cols = self.img[1].size
for i in range(self.number_of_cols):
for j in range(self.number_of_rows):
num = self.img[j][i]
if num != self.last_list[num]:
self.img[j][i] = self.last_list[num]
cv2.imwrite("output_data/output.jpg", self.img)

def plotHistogram(self):
plt.hist(self.img.ravel(), 256, [0, 256])

def showImage(self):
cv2.imshow("Output-Image", self.img)
cv2.imshow("Input-Image", self.original_image)
cv2.waitKey(5000)
cv2.destroyAllWindows()


if __name__ == "__main__":
file_path = os.path.join(os.path.basename(__file__), "image_data/input.jpg")
stretcher = contrastStretch()
stretcher.stretch(file_path)
stretcher.plotHistogram()
stretcher.showImage()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.