{"cells":[{"metadata":{},"cell_type":"markdown","source":"I tried to create the most easy and user friendly function to plot the picture with the relative mask"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np \nimport pandas as pd \nimport matplotlib.pyplot as plt\n\n\nimport tifffile","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def get_mask(id_):\n    train_csv = pd.read_csv('../input/hubmap-kidney-segmentation/train.csv')\n    image = tifffile.imread('../input/hubmap-kidney-segmentation/train/{}.tiff'.format(id_))\n    mask_cod  = train_csv.loc[train_csv['id'] == id_]['encoding'].values[0]\n    \n    mask = np.zeros((image.shape[0]*image.shape[1]), dtype=np.uint8)\n    \n    rle_mask = mask_cod.split()\n    positions = map(int, rle_mask[::2])\n    lengths = map(int, rle_mask[1::2])\n    for pos, le in zip(positions, lengths):\n        mask[pos-1:pos+le-1] = 1\n   \n    mask = mask.reshape((image.shape[1], image.shape[0]))\n\n    return image, mask.T","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image, mask = get_mask('2f6ecfcdf')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(15,15))\nplt.imshow(image)\nplt.imshow(mask,alpha=0.5)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"I copied the next function from https://www.kaggle.com/ihelon/hubmap-exploratory-data-analysis/notebook\nbecause it is definetly better than whatever I could ever produce "},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"def plot_grid_image_with_mask(image, mask):\n    plt.figure(figsize=(16, 16))\n    n_cols = 4\n    n_rows = 4\n    col_start = 0\n    col_w = 5000\n    row_start = 5000\n    row_w = 5000\n    for i in range(n_cols):\n        for j in range(n_rows):\n            plt.subplot(n_cols, n_rows, n_rows * i + j + 1)\n            sub_image = image[\n                col_start + i * col_w : col_start + (i + 1) * col_w, \n                row_start + j * row_w : row_start + (j + 1) * row_w, \n                :\n            ]\n            sub_mask = mask[\n                col_start + i * col_w : col_start + (i + 1) * col_w, \n                row_start + j * row_w : row_start + (j + 1) * row_w, \n            ]\n            plt.imshow(sub_image)\n            plt.imshow(sub_mask, alpha=0.5)\n            plt.axis(\"off\")\n    plt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plot_grid_image_with_mask(image,mask)","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}