{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "b39ef270-04b0-75ae-fd77-5132f6dda79a"
      },
      "outputs": [],
      "source": [
        "%matplotlib inline\n",
        "\n",
        "import os\n",
        "import numpy as np\n",
        "import tensorflow as tf\n",
        "import matplotlib.pyplot as plt\n",
        "from PIL import Image\n",
        "\n",
        "train_dir = '../input/train/'\n",
        "test_dir = '../input/test/'\n",
        "\n",
        "len(os.listdir(test_dir))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "722b90a5-b35e-a22c-695b-92c5e5b68ee7"
      },
      "outputs": [],
      "source": [
        "# Extract images\n",
        "img_size = 64\n",
        "channels_num = 1\n",
        "\n",
        "def extract_images(dr):\n",
        "    num_images = len(os.listdir(dr))\n",
        "    data = np.ndarray([num_images, img_size, img_size, channels_num], np.float32)\n",
        "    \n",
        "    for i, img in enumerate(os.listdir(dr)):\n",
        "        img = Image.open(dr + img)\n",
        "        img_gray = img.convert('L')\n",
        "        img_resized = img_gray.resize((img_size, img_size), Image.ANTIALIAS)\n",
        "        img_np = np.array(img_resized)\n",
        "        img_normal = (img_np - (255.0 / 2.0)) / 255.0\n",
        "        data[i,:,:,:] = img_normal.reshape((img_size, img_size, channels_num))\n",
        "        \n",
        "    return data\n",
        "    \n",
        "#train_images = extract_images(train_dir)\n",
        "test_images = extract_images(test_dir)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "55cb2df1-9edf-fc69-eab6-37360eb03697"
      },
      "outputs": [],
      "source": [
        "%matplotlib inline\n",
        "plt.show(plt.imshow(test_images[0].reshape(img_size, img_size), cmap=plt.cm.Greys))"
      ]
    }
  ],
  "metadata": {
    "_change_revision": 0,
    "_is_fork": false,
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.5.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}