Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import numpy as np
  2. from PIL import Image
  3.  
  4. import os.path as osp
  5. import glob
  6. import fnmatch, re, os, sys
  7. import yaml
  8. import matplotlib.mlab as mlab
  9. import matplotlib.pyplot as plt
  10. import cv2 as cv
  11. from copy import deepcopy
  12. import scipy.misc
  13.  
  14. base_dir = 'png_keeping_filename'
  15. dst_dir = 'dataset/png_saved'
  16. count = 1
  17.  
  18. gamma = 2.0
  19. invGamma = 1.0 / gamma
  20.  
  21. def gamma_correction(img, correction):
  22. img = img/255.0
  23. img = cv.pow(img, correction)
  24. return np.uint8(img*255.0)
  25.  
  26. for root, dirnames, filenames in os.walk(base_dir):
  27. for filename in fnmatch.filter(filenames, '*.tiff'):
  28. path = os.path.join(root, filename)
  29. img = cv.imread(path)
  30. print(filename, path, os.path.exists(path))
  31.  
  32. filename = filename.replace('.tiff', '.png')
  33. small = scipy.misc.imresize(img, 0.15)
  34. cv.imwrite(osp.join(dst_dir, filename), small)
  35.  
  36. image = gamma_correction(small, 0.5)
  37. cv.imwrite(osp.join(dst_dir, 'gamma-' + filename), image)
  38.  
  39. # print(filename)
  40. count += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement