{"cells":[{"metadata":{"_uuid":"85ffacc5c47dbaf0f2ea65fea6a1cdd8397ed72c"},"cell_type":"markdown","source":"I noticed some of the edge masks were just lines so I wanted to exclude these from my dataset. I used the following script to flag all masks that are 1 px wide (or empty). There turns out to be about 19 masks in the training set that are flagged.","outputs":[],"execution_count":null},{"metadata":{"_cell_guid":"52560a89-1705-4c09-bbdf-fa1e1915d020","_kg_hide-input":false,"_kg_hide-output":true,"_uuid":"b130b8f4f79eee8e7e4670f72b656e4f3478823b","trusted":true},"cell_type":"code","source":"import os\nimport numpy as np\nfrom skimage.io import imread\n\nTRAIN_PATH = \"../input/stage1_train/\"\n\nfor image in os.listdir(TRAIN_PATH):\n    mask_list = os.listdir(\"%s%s/masks\" % (TRAIN_PATH, image))\n    for mask in mask_list:\n        full_path = \"%s%s/masks/%s\" % (TRAIN_PATH, image, mask)\n        inp_mask = imread(full_path)\n        if (np.count_nonzero(inp_mask) != 0):\n            x_mask, y_mask = np.nonzero(inp_mask)\n            size_x = max(x_mask) - min(x_mask) + 1\n            size_y = max(y_mask) - min(y_mask) + 1\n            if size_x < 2 or size_y < 2: # Flag Mask\n                print(full_path)\n        else:\n            print(\"Empty mask: %s\" % (full_path))","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.6.4"}},"nbformat":4,"nbformat_minor":1}