text_plain_output_1.png
from skimage import io, color, exposure, transform

import cv2

import cv2

import numpy as np # linear algebra

import os

import os

def preprocess_img(img):
    # Histogram normalization in y
    hsv = color.rgb2hsv(img)
    hsv[:,:,2] = exposure.equalize_hist(hsv[:,:,2])
    img = color.hsv2rgb(hsv)

    # central scrop
    min_side = min(img.shape[:-1])
    centre = img.shape[0]//2, img.shape[1]//2
    img = img[centre[0]-min_side//2:centre[0]+min_side//2,
              centre[1]-min_side//2:centre[1]+min_side//2,
              :]

    # rescale to standard size
    img = transform.resize(img, (IMG_SIZE, IMG_SIZE))

    # roll color axis to axis 0
    img = np.rollaxis(img,-1)

    return img

import cv2
DATA_DIR_TRAIN = '../input/dataset/dataset/train'
CATEGORIES = ['left', 'right']
x_train = []
y_train = []
img_data_train = []
for category in CATEGORIES:
    path = os.path.join(DATA_DIR_TRAIN, category)
    class_num = CATEGORIES.index(category)
    for img_path in os.listdir(path):
        img = cv2.imread(os.path.join(path, img_path))
        img_data_train.append(img)
        new_img = preprocess_img(img)
        x_train.append(new_img)
        y_train.append(class_num)

import cv2
DATA_DIR_TEST = '../input/dataset/dataset/test'
CATEGORIES = ['left', 'right']
x_test = []
y_test = []
img_data_test = []
for category in CATEGORIES:
    path = os.path.join(DATA_DIR_TEST, category)
    class_num = CATEGORIES.index(category)
    for img_path in os.listdir(path):
        img = cv2.imread(os.path.join(path, img_path))
        img_data_test.append(img)
        new_img = preprocess_img(img)
        x_test.append(new_img)
        y_test.append(class_num)

x_train_np = np.array(x_train, dtype='float32')
y_train_np = np.eye(NUM_CLASSES, dtype='uint8')[y_train]
x_test_np = np.array(x_test, dtype='float32')
y_test_np = np.eye(NUM_CLASSES, dtype='uint8')[y_test]

random_array = np.random.randint(len(x_train), size=25)
random_array

random_array = np.random.randint(len(x_test), size=25)
random_array