{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"from pathlib import Path\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom skimage.io import imread\nimport numpy as np\n\n\nrc = {\"axes.spines.left\" : False,\n      \"axes.spines.right\" : False,\n      \"axes.spines.bottom\" : False,\n      \"axes.spines.top\" : False,\n      \"xtick.bottom\" : False,\n      \"xtick.labelbottom\" : False,\n      \"ytick.labelleft\" : False,\n      \"ytick.left\" : False,\n     \"figure.figsize\": [20, 15]}\n\nplt.rcParams.update(rc)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-20T09:23:49.004217Z","iopub.execute_input":"2022-07-20T09:23:49.005420Z","iopub.status.idle":"2022-07-20T09:23:49.013013Z","shell.execute_reply.started":"2022-07-20T09:23:49.005359Z","shell.execute_reply":"2022-07-20T09:23:49.011882Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ROOT = Path(\"../input/hubmap-organ-segmentation\")\ntrain_df = pd.read_csv(ROOT/ \"train.csv\")\ntrain_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T09:23:20.607937Z","iopub.execute_input":"2022-07-20T09:23:20.608297Z","iopub.status.idle":"2022-07-20T09:23:20.772076Z","shell.execute_reply.started":"2022-07-20T09:23:20.608269Z","shell.execute_reply":"2022-07-20T09:23:20.771197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T09:23:20.774526Z","iopub.execute_input":"2022-07-20T09:23:20.775049Z","iopub.status.idle":"2022-07-20T09:23:20.791732Z","shell.execute_reply.started":"2022-07-20T09:23:20.775018Z","shell.execute_reply":"2022-07-20T09:23:20.790511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# First Image\nlbl_path = ROOT/ \"train_images\" / \"10044.tiff\"\nlbl = imread(lbl_path); plt.imshow(lbl)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T09:23:21.031667Z","iopub.execute_input":"2022-07-20T09:23:21.032606Z","iopub.status.idle":"2022-07-20T09:23:22.485006Z","shell.execute_reply.started":"2022-07-20T09:23:21.032561Z","shell.execute_reply":"2022-07-20T09:23:22.483828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# https://www.kaggle.com/paulorzp/rle-functions-run-lenght-encode-decode\ndef rle2mask(mask_rle, shape=(1600,256)):\n    '''\n    mask_rle: run-length as string formated (start length)\n    shape: (width,height) of array to return \n    Returns numpy array, 1 - mask, 0 - background\n\n    '''\n    s = mask_rle.split()\n    starts, lengths = [np.asarray(x, dtype=int) for x in (s[0:][::2], s[1:][::2])]\n    starts -= 1\n    ends = starts + lengths\n    img = np.zeros(shape[0]*shape[1], dtype=np.uint8)\n    for lo, hi in zip(starts, ends):\n        img[lo:hi] = 1\n    return img.reshape(shape).T","metadata":{"execution":{"iopub.status.busy":"2022-07-20T09:23:22.486766Z","iopub.execute_input":"2022-07-20T09:23:22.487143Z","iopub.status.idle":"2022-07-20T09:23:22.493693Z","shell.execute_reply.started":"2022-07-20T09:23:22.487113Z","shell.execute_reply":"2022-07-20T09:23:22.492960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_rle = train_df[train_df.id == 10044].rle[0]\ntarget = rle2mask(target_rle, lbl.shape[0:2])\nplt.imshow(target)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T09:23:22.494985Z","iopub.execute_input":"2022-07-20T09:23:22.495281Z","iopub.status.idle":"2022-07-20T09:23:23.699439Z","shell.execute_reply.started":"2022-07-20T09:23:22.495248Z","shell.execute_reply":"2022-07-20T09:23:23.698360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(lbl);plt.imshow(target, cmap=\"hot\", alpha=0.3); ","metadata":{"execution":{"iopub.status.busy":"2022-07-20T09:23:23.701416Z","iopub.execute_input":"2022-07-20T09:23:23.701752Z","iopub.status.idle":"2022-07-20T09:23:26.265541Z","shell.execute_reply.started":"2022-07-20T09:23:23.701717Z","shell.execute_reply":"2022-07-20T09:23:26.264114Z"},"trusted":true},"execution_count":null,"outputs":[]}]}