{"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 cv2\nimport numpy as np\nimport os\n\nimport pandas as pd\n\nrle_list = []\nid_list = []\nimport matplotlib.pyplot as plt\n\ndef rle_encode(img):\n    img = img.T\n    pixels = img.flatten()\n    pixels = np.concatenate([[0], pixels, [0]])\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 1\n    runs[1::2] -= runs[::2]\n    return ' '.join(str(x) for x in runs)\n\n\nfor i in os.listdir(\"../input/hubmap-organ-segmentation/test_images/\"):\n    image = cv2.imread(f\"../input/hubmap-organ-segmentation/test_images/{i}\")\n    img_name = i.split(\".\")[0]\n    h, w, c = image.shape\n    \n    mask = np.ones((h, w), np.uint8) * 255\n    rle = rle_encode(mask)\n    \n    rle_list.append(rle)\n    id_list.append(img_name)\n    \n\ndf = pd.DataFrame()\ndf['id'] = id_list\ndf['rle'] = rle_list\nprint(df)\ndf.to_csv(\"submission.csv\", index=False)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-10T08:15:56.557944Z","iopub.execute_input":"2022-08-10T08:15:56.558752Z","iopub.status.idle":"2022-08-10T08:15:57.129345Z","shell.execute_reply.started":"2022-08-10T08:15:56.558627Z","shell.execute_reply":"2022-08-10T08:15:57.127669Z"},"trusted":true},"execution_count":null,"outputs":[]}]}