Last active
July 23, 2017 21:36
-
-
Save dnkirill/ef5da7b77bf25ef1af62f948bfd4034d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage import exposure | |
def grayscale_exposure_equalize(batch_x_y): | |
"""Processes a batch with images by grayscaling, normalization and | |
histogram equalization. | |
Args: | |
batch_x_y: a single batch of data containing a numpy array of images | |
and a list of corresponding labels. | |
Returns: | |
Numpy array of processed images and a list of labels (unchanged). | |
""" | |
x_sub, y_sub = batch_x_y[0], batch_x_y[1] | |
x_processed_sub = numpy.zeros(x_sub.shape[:-1]) | |
for x in range(len(x_sub)): | |
# Grayscale | |
img_gray = numpy.dot(x_sub[x][...,:3], [0.299, 0.587, 0.114]) | |
# Normalization | |
img_gray_norm = img_gray / (img_gray.max() + 1) | |
# CLAHE. num_bins will be initialized in ipyparallel client | |
img_gray_norm = exposure.equalize_adapthist(img_gray_norm, nbins=num_bins) | |
x_processed_sub[x,...] = img_gray_norm | |
return (x_processed_sub, y_sub) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment