Skip to content

Commit

Permalink
add HistEq
Browse files Browse the repository at this point in the history
  • Loading branch information
yyvettey committed Jun 14, 2018
1 parent c309f09 commit bc7ad64
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions HistEq/process.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
import sys
import shutil
from tqdm import tqdm
from PIL import Image
from skimage import exposure
from keras.preprocessing import image

# To run:
# Format: python HistEq/process.py path/to/input/ path/to/output
# Example: python HistEq/process.py sample/evaluation-images sample/evaluation-images-histeq

input_path = os.path.abspath(sys.argv[1])
output_path = os.path.abspath(sys.argv[2])


def histogram_equalization(img):
img = img / 255.
img = exposure.equalize_adapthist(img)
img = img * 255.
return img


def processImg(img_in, img_out):
img = image.load_img(img_in)
img = image.img_to_array(img)
img = histogram_equalization(img)
img = Image.fromarray(img.astype('uint8'))
img.save(img_out)


def processDir(dir_in, dir_out):
if not os.path.exists(dir_out):
os.makedirs(dir_out)

for img in os.listdir(dir_in):
processImg(os.path.join(dir_in, img), os.path.join(dir_out, img))


print("input_path: ", input_path)
print("output_path: ", output_path)

if input_path.endswith("jpg") or input_path.endswith("png"):
processImg(input_path, output_path)
else:
processDir(input_path, output_path)

0 comments on commit bc7ad64

Please sign in to comment.