{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"2af45431-9592-fd1c-415e-eef025497fab"},"outputs":[],"source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nfrom subprocess import check_output\nprint(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n\n\n# Any results you write to the current directory are saved as output."},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"84877548-462f-2bb9-29bd-a735c52e62ef"},"outputs":[],"source":"trainLabels = pd.read_csv(\"../input/trainLabels.csv\")\ntrainLabels.head()\n"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"1ac4c08f-5abf-cff6-6309-52f0c808e2f2"},"outputs":[],"source":"import os\n\nlisting = os.listdir(\"../input\") \nlisting.remove(\"trainLabels.csv\")\nnp.size(listing)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"ad6f4bf5-fbd9-2fd8-7494-6c0e1326cbb3"},"outputs":[],"source":"from PIL import Image\n\n# input image dimensions\nimg_rows, img_cols = 256, 256\n\nimmatrix = []\nimlabel = []\n\nfor file in listing:\n    base = os.path.basename(\"../input/\" + file)\n    fileName = os.path.splitext(base)[0]\n    imlabel.append(trainLabels.loc[trainLabels.image==fileName, 'level'].values[0])\n    im = Image.open(\"../input/\" + file)   \n    img = im.resize((img_rows,img_cols))\n    gray = img.convert('L')\n    immatrix.append(np.array(gray).flatten())\n    "},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"8d3bad75-efdf-d611-4e71-0e1c32060ce7"},"outputs":[],"source":"immatrix = np.asarray(immatrix)\nimlabel = np.asarray(imlabel)"}],"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}