Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from PIL import Image
- import os.path as osp
- import glob
- import fnmatch, re, os, sys
- import yaml
- import matplotlib.mlab as mlab
- import matplotlib.pyplot as plt
- import cv2 as cv
- from copy import deepcopy
- import scipy.misc
- base_dir = 'png_keeping_filename'
- dst_dir = 'dataset/png_saved'
- count = 1
- gamma = 2.0
- invGamma = 1.0 / gamma
- def gamma_correction(img, correction):
- img = img/255.0
- img = cv.pow(img, correction)
- return np.uint8(img*255.0)
- for root, dirnames, filenames in os.walk(base_dir):
- for filename in fnmatch.filter(filenames, '*.tiff'):
- path = os.path.join(root, filename)
- img = cv.imread(path)
- print(filename, path, os.path.exists(path))
- filename = filename.replace('.tiff', '.png')
- small = scipy.misc.imresize(img, 0.15)
- cv.imwrite(osp.join(dst_dir, filename), small)
- image = gamma_correction(small, 0.5)
- cv.imwrite(osp.join(dst_dir, 'gamma-' + filename), image)
- # print(filename)
- count += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement