{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport cv2\nfrom skimage.data import imread\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"df_train_gt = pd.read_csv('../input/train_ship_segmentations.csv')\ndf_train_gt[(df_train_gt.EncodedPixels.isna() == False)].head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"769123a88941dd24336d817c906b0d77339b53e7"},"cell_type":"code","source":"pixels = df_train_gt[df_train_gt.ImageId == '000155de5.jpg'].EncodedPixels\nimg = cv2.imread('../input/train/' + '000155de5.jpg')\nimg_ = img.copy()\nplt.figure()\nplt.imshow(img)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"940aac5158c2f83f8c2ca9f1141457a567a0e3f4"},"cell_type":"code","source":"def show_segmentation(img, pixels):\n    img_seg = np.zeros(img.shape[:-1])\n    for pixel_ in pixels:\n        pixels_ = pixel_.split()\n        pixels_ = np.array(pixels_ ,dtype=int)\n        for i in range(0, len(pixels_), 2):\n            y = int(pixels_[i]/img.shape[0])\n            x = int(pixels_[i]%img.shape[0])\n            step = int(pixels_[i+1])\n            img[x:x+step,y] = 255\n            img_seg[x:x+step,y] = 255\n    plt.subplots(1, 2, figsize=(15, 40))\n    plt.subplot(121)\n    plt.imshow(img)\n    plt.subplot(122)\n    plt.imshow(img_seg)\n    plt.show()\n    return img_seg","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9f3f6cd59517a9fc0f55046f3b5a0d90c1fa1c17"},"cell_type":"code","source":"show_segmentation(img, pixels)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"bcea09712680911f1b02b1f53ff2644d180da0bd"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}