Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import (division, absolute_import, print_function, unicode_literals)
- import glob
- import os,sys
- import cv2 as cv
- import numpy as np
- from pandas import DataFrame as df
- import pandas as pd
- from matplotlib import pyplot as plt
- ########
- #Globals
- #########
- img_dir = "path_to_images/*.*"
- ###########
- #Functions
- ###########
- def white_balance(img):
- result = cv.cvtColor(img, cv.COLOR_BGR2LAB)
- avg_a = np.average(result[:, :, 1])
- avg_b = np.average(result[:, :, 2])
- result[:, :, 1] = result[:, :, 1] - ((avg_a - 128) * (result[:, :, 0] / 255.0) * 1.1)
- result[:, :, 2] = result[:, :, 2] - ((avg_b - 128) * (result[:, :, 0] / 255.0) * 1.1)
- result = cv.cvtColor(result, cv.COLOR_LAB2BGR)
- return result
- ## Get all the images in the specified dir:
- images = sorted(glob.glob(img_dir))
- #Reading images in folder
- for image in images:
- img = cv.imread(os.path.join(img_dir, image)) #Read images one by one
- ################
- #Pre-processing#
- ################
- #Performing white balancing (gray world)
- #final = np.hstack((img, white_balance(img))) #white balancing; showing Original and filtered.
- final = white_balance(img) #white balance on a single image.
- #Saving images:
- i = 0
- cv.imwrite("path_to_results/preproc%04i.jpg" %i, final) #save images in sequence (numbering)
- i += 1 #numbering variable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement