{"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":"import sys\nimport numpy as np\n#np.set_printoptions(threshold=sys.maxsize)\nimport pandas as pd\n\nfrom PIL import Image\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-11-06T19:04:08.648059Z","iopub.execute_input":"2021-11-06T19:04:08.648665Z","iopub.status.idle":"2021-11-06T19:04:08.671369Z","shell.execute_reply.started":"2021-11-06T19:04:08.648542Z","shell.execute_reply":"2021-11-06T19:04:08.670737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(\"../input/sartorius-cell-instance-segmentation/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2021-11-06T19:04:08.672777Z","iopub.execute_input":"2021-11-06T19:04:08.673192Z","iopub.status.idle":"2021-11-06T19:04:09.215932Z","shell.execute_reply.started":"2021-11-06T19:04:08.673162Z","shell.execute_reply":"2021-11-06T19:04:09.214837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_images(id_):\n    shape=(520, 704)\n    db_annotations = train[train['id'] == id_]\n    db_annotations = db_annotations.reset_index()\n    cell_photo = Image.open(\"../input/sartorius-cell-instance-segmentation/train/{}.png\".format(id_))\n    list_img= []\n    for i in range(0,len(db_annotations)):\n        annotation = db_annotations['annotation'][i].split()\n        starts, lengths = [np.asarray(x, dtype=int) for x in (annotation[0:][::2], annotation[1:][::2])]\n        starts -= 1\n        ends = starts + lengths\n        img = np.zeros(db_annotations['width'][0]*db_annotations['height'][0], dtype=np.uint8)\n        img = np.where(img==0, np.nan, img)\n        for lo, hi in zip(starts, ends):\n            img[lo:hi] = 1\n            \n        img = img.reshape(shape)\n        list_img.append(img)\n        \n    \n    plt.figure(figsize = (12,9))\n    plt.imshow(cell_photo,cmap='gray',aspect='auto')\n    for i in range(0,len(list_img)):\n        plt.imshow(list_img[i])\n    ","metadata":{"execution":{"iopub.status.busy":"2021-11-06T19:04:09.217531Z","iopub.execute_input":"2021-11-06T19:04:09.217801Z","iopub.status.idle":"2021-11-06T19:04:09.229517Z","shell.execute_reply.started":"2021-11-06T19:04:09.217767Z","shell.execute_reply":"2021-11-06T19:04:09.228617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_images('ffdb3cc02eef')","metadata":{"execution":{"iopub.status.busy":"2021-11-06T19:04:09.230599Z","iopub.execute_input":"2021-11-06T19:04:09.230821Z","iopub.status.idle":"2021-11-06T19:04:20.490917Z","shell.execute_reply.started":"2021-11-06T19:04:09.230795Z","shell.execute_reply":"2021-11-06T19:04:20.490280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in train['id'].unique()[1:5]:\n    plot_images(i)","metadata":{"execution":{"iopub.status.busy":"2021-11-06T19:04:20.492152Z","iopub.execute_input":"2021-11-06T19:04:20.492882Z","iopub.status.idle":"2021-11-06T19:04:47.190277Z","shell.execute_reply.started":"2021-11-06T19:04:20.492838Z","shell.execute_reply":"2021-11-06T19:04:47.189367Z"},"trusted":true},"execution_count":null,"outputs":[]}]}