{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "d24fe055-5f60-b137-6297-bce3530d29b0"
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\n",
        "%matplotlib inline\n",
        "import numpy as np\n",
        "import pandas as pd\n",
        "import cv2\n",
        "import math\n",
        "from sklearn import mixture\n",
        "from sklearn.utils import shuffle\n",
        "from skimage import measure\n",
        "from glob import glob\n",
        "import os\n",
        "from multiprocessing import Pool, cpu_count\n",
        "from functools import partial\n",
        "from subprocess import check_output\n",
        "print(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n",
        "\n",
        "TRAIN_DATA = \"../input/train\"\n",
        "ADDITIONAL_DATA_TYPE_1 = \"../input/additional_Type_1\"\n",
        "\n",
        "types = ['Type_1','Type_2','Type_3']\n",
        "type_ids = []\n",
        "additional_ids = []\n",
        "\n",
        "for type in enumerate(types):\n",
        "    type_i_files = glob(os.path.join(TRAIN_DATA, type[1], \"*.jpg\"))\n",
        "    type_i_ids = np.array([s[len(TRAIN_DATA)+8:-4] for s in type_i_files])\n",
        "    type_ids.append(type_i_ids)\n",
        "    \n",
        "    additional_files = glob(os.path.join(ADDITIONAL_DATA_TYPE_1, \"*.jpg\"))\n",
        "    additional_i_ids = np.array([s[len(ADDITIONAL_DATA_TYPE_1)+8:-4] for s in additional_files])\n",
        "    additional_ids.append(additional_i_ids)\n",
        "\n",
        "def get_filename(image_id, image_type):\n",
        "    \"\"\"\n",
        "    Method to get image file path from its id and type   \n",
        "    \"\"\"\n",
        "    if image_type == \"Type_1\" or \\\n",
        "        image_type == \"Type_2\" or \\\n",
        "        image_type == \"Type_3\":\n",
        "        data_path = os.path.join(TRAIN_DATA, image_type)\n",
        "    elif image_type == \"Test\":\n",
        "        data_path = TEST_DATA\n",
        "    elif image_type == \"AType_1\" or \\\n",
        "          image_type == \"AType_2\" or \\\n",
        "          image_type == \"AType_3\":\n",
        "        data_path = os.path.join(ADDITIONAL_DATA, image_type)\n",
        "    else:\n",
        "        raise Exception(\"Image type '%s' is not recognized\" % image_type)\n",
        "\n",
        "    ext = 'jpg'\n",
        "    path = os.path.join(data_path, \"{}.{}\".format(image_id, ext))\n",
        "    print(path)\n",
        "    return os.path.join(data_path, \"{}.{}\".format(image_id, ext))\n",
        "\n",
        "def get_image_data(image_id, image_type):\n",
        "    \"\"\"\n",
        "    Method to get image data as np.array specifying image id and type\n",
        "    \"\"\"\n",
        "    fname = get_filename(image_id, image_type)\n",
        "    img = cv2.imread(fname)\n",
        "    assert img is not None, \"Failed to read image : %s, %s\" % (image_id, image_type)\n",
        "    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n",
        "    plt.imshow(img)\n",
        "\n",
        "def show_additional_data(image_id):\n",
        "    print(\"Additional Ids:\")\n",
        "    print(additional_ids)\n",
        "    ext = 'jpg'\n",
        "    path = os.path.join(ADDITIONAL_DATA_TYPE_1, \"{}.{}\".format(image_id, ext))\n",
        "    print(path)\n",
        "    img = cv2.imread(path)\n",
        "    assert img is not None, \"Failed to read image : %s\" % (image_id)\n",
        "    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n",
        "    plt.imshow(img)\n",
        " \n",
        "get_image_data(170, type[1])\n",
        "\n",
        "#3show_additional_data(1790)"
      ]
    }
  ],
  "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.6.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}