{"cells":[{"metadata":{"_uuid":"98d3c44385443aa26e8e853847cfaa1ed0e84aac"},"cell_type":"markdown","source":"> Haven't seen a kernel exploring neuclei and possible ways to segment the dataset into workable patches. Might as well be the guy to post this!\n\n## Table of contents\n- [Motivation / objective](#Motivation)\n- [EDA](#EDA)\n- [Suggestions](#Suggestions)\n\nBut before any of that, let's fetch the images and masks shall we?","outputs":[],"execution_count":null},{"metadata":{"_uuid":"2825dbd3713f78dcf1f45d73e0bd6a7c35ae7e00","_cell_guid":"fdd1c0c2-17ec-4464-9d9b-d61dd8b67eef","trusted":true,"_kg_hide-output":false,"_kg_hide-input":true,"collapsed":true},"cell_type":"code","source":"import os\nfrom functools import reduce\n\nfrom tqdm import tqdm\n\nimport numpy as np\nimport pandas as pd\nfrom PIL import Image\n\nimport matplotlib.pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d468407ddf84892819b937a4f9293e4cbf482ef6","_cell_guid":"aa857cb3-5887-466c-a9d6-03b259e7e004","trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"# first get the images and the relavent masks\ntrain_folder = '../input/stage1_train/'\nimage_ids = os.listdir(train_folder)\ndata = []\n\nfor i_id in tqdm(image_ids, desc='Getting images and masks'):\n    img_files = [train_folder + i_id + '/images/' + f for f in os.listdir(train_folder + i_id + '/images/')]\n    mask_files = [train_folder + i_id + '/masks/' + f for f in os.listdir(train_folder + i_id + '/masks/')]\n    \n    assert len(img_files) == 1, 'Is this an error? There should only be 1 img to each id'\n    \n    new_data = {\n        'img': np.array(Image.open(img_files[0])),\n        'masks': [np.array(Image.open(m)) for m in mask_files]\n    }\n    \n    data.append(new_data)\n\nnb_masks = reduce(lambda x, y: x + len(y['masks']), data, 0)\n\nprint('Fetching of data complete')\nprint('Total of {} images and {} masks'.format(len(data), nb_masks))","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"974dc757578e702bfd66b64d2cc4c3a5594203ce"},"cell_type":"markdown","source":"A very decently sized dataset! 670 labelled images is a **lot** and there are over 2000 labelled neucleis.","outputs":[],"execution_count":null},{"metadata":{"_uuid":"498abf7251839f26859d7f856866897f96e93fd3"},"cell_type":"markdown","source":"---\n\n## Motivations\n\nThe idea behind patching is to turn images from looking like this","outputs":[],"execution_count":null},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"90d82a128e8b462e8e1ce82bc6d85d465af1e026"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}