Created
March 4, 2020 23:40
-
-
Save QApolo/0b640f4c21732bd2aacb28c6d7a95d69 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
import cv2 as cv | |
import numpy as np | |
from matplotlib import pyplot as plt | |
class ImageProcessor: | |
def __init__(self, pathImg): | |
self.img = cv.imread(pathImg, 0) | |
self.img = cv.medianBlur(self.img, 5) | |
def GaussianTransform(self): | |
self.imgTrans = cv.adaptiveThreshold(self.img, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C,\ | |
cv.THRESH_BINARY, 23, 2) | |
bgr = cv.split(self.imgTrans) # get b,g,r | |
rgb_img = cv.merge(bgr) # switch it to rgb | |
# Denoising | |
self.imgTrans = cv.cvtColor(self.imgTrans, cv.COLOR_GRAY2BGR) | |
dst = cv.fastNlMeansDenoising(self.imgTrans,10,10,13,21) | |
b,g,r = cv.split(dst) # get b,g,r | |
rgb_dst = cv.merge([r,g,b]) | |
self.imgTrans = rgb_dst | |
def saveImage(self, name): | |
cv.imwrite(name, self.imgTrans) | |
def comparisonPlot(self): | |
titles = ['Original Image','Threshold'] | |
images = [self.img, self.imgTrans] | |
for i in range(0, 2): | |
plt.subplot(2,1,i+1),plt.imshow(images[i],'gray') | |
plt.title(titles[i]) | |
plt.xticks([]),plt.yticks([]) | |
plt.show() | |
if __name__ == '__main__': | |
ip = ImageProcessor("image.jpg") | |
ip.GaussianTransform() | |
ip.saveImage('transformada.jpg') | |
#ip.comparisonPlot() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment