Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, glob, sys
- import numpy as np
- import cv2
- import matplotlib.pyplot as plt
- import skimage.filters as filters
- import seaborn as sns
- def brightness_and_contrast_adjustment(image, alpha=1.999, beta=-30):
- image = alpha * image + beta
- image = np.clip(image, 0, 255)
- return image.astype(np.uint8)
- def gamma_correction(image, gamma=2.2):
- image = ((image/255)**(1/gamma)) * 255
- return image.astype(np.uint8)
- clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
- def preprocess_image(image):
- image = brightness_and_contrast_adjustment(image)
- kernel = np.ones((2, 2),np.uint8)
- image = cv2.erode(image, kernel, iterations=1)
- image = clahe.apply(image)
- return image.astype(np.uint8)
- paths = glob.glob("sample/*.jpg")
- n_images = 5
- fig, ax = plt.subplots(n_images, 2, figsize=(30, 10*n_images))
- for i, path in enumerate(paths):
- image = cv2.imread(path)
- image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
- preprocessed_image = preprocess_image(image)
- ax[i, 0].imshow(image, cmap="gray")
- ax[i, 1].imshow(preprocessed_image, cmap="gray")
- if i == n_images-1:
- break
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement