{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"10d7ce78-cede-c6e2-b2af-1f5253558daa"},"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 pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\\\nimport matplotlib.pyplot as plt\nfrom PIL import Image\nimport cv2\nimport numpy as np\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# Any results you write to the current directory are saved as output."},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"f6af0c93-0ede-74b7-1b6e-c5f641dc755d"},"outputs":[],"source":"from glob import glob\nbasepath = '../input/train/'\n\nall_cervix_images = []\n\nfor path in sorted(glob(basepath + \"*\")):\n    cervix_type = path.split(\"/\")[-1]\n    cervix_images = sorted(glob(basepath + cervix_type + \"/*\"))\n    all_cervix_images = all_cervix_images + cervix_images\n\nall_cervix_images = pd.DataFrame({'imagepath': all_cervix_images})\nall_cervix_images['filetype'] = all_cervix_images.apply(lambda row: row.imagepath.split(\".\")[-1], axis=1)\nall_cervix_images['type'] = all_cervix_images.apply(lambda row: row.imagepath.split(\"/\")[-2], axis=1)\nall_cervix_images.head()"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"bcd1119b-7dee-e190-3eb9-0ac9a754e656"},"outputs":[],"source":"fig = plt.figure(figsize=(12,8))\n\ni = 1\nfor t in all_cervix_images['type'].unique():\n    ax = fig.add_subplot(1,3,i)\n    i+=1\n    f = all_cervix_images[all_cervix_images['type'] == t]['imagepath'].values[15]\n    #plt.imshow(plt.imread(f))\n    #plt.title('sample for cervix {}'.format(t))\\\n    \n    #image = Image.open(f).convert(\"L\")\n    #arr = np.asarray(image)\n    #plt.imshow(arr, cmap='gray')\n    #plt.show()\n\n    img = cv2.imread(f,0)\n    ret,thresh_img = cv2.threshold(img,127,255,cv2.THRESH_BINARY)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"034b2faa-3051-ac5e-cd19-260db7de6ce0"},"outputs":[],"source":"\n"}],"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}