{"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)\n\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","collapsed":true,"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"from PIL import Image, ImageChops\nimport matplotlib.pyplot as plt\nimport multiprocessing\nimport cv2, glob\n\nfrom skimage.segmentation import mark_boundaries\n%matplotlib inline","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"bbecab43fcb9f0c473a28dd59958e13821a57dc7"},"cell_type":"code","source":"train_label = glob.glob('../input/train_label/**')\ntrain = pd.DataFrame(glob.glob('../input/train_color/**'), columns=['Path'])\ntrain['LabelPath'] = train['Path'].map(lambda x: str(x).replace('.jpg','_instanceIds.png').replace('train_color','train_label'))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6884926cd8cff8ccdd9c5f8f2bab27b305524f49","collapsed":true},"cell_type":"code","source":"from IPython.display import display\n\nim = Image.open(train.Path[0])\ntlabel = (np.asarray(Image.open(train.LabelPath[0])) / 1000).astype('uint8')\n\nplt.figure(figsize=(20,20))\nplt.subplot(151)\nplt.imshow(im)\n\nplt.subplot(152)\ntlabel[tlabel != 0] = 255\nplt.imshow(Image.blend(im, Image.fromarray(tlabel).convert('RGB'), alpha=0.5))\n\nplt.subplot(153)\nbound_img = mark_boundaries(image = im, label_img = tlabel, color = (1,0,0), background_label = 255, mode = 'thick')\nplt.imshow(bound_img)\n\nplt.subplot(154)\nxd, yd = np.where(tlabel>0)\nplt.imshow(bound_img[xd.min():xd.max(), yd.min():yd.max(),:])\n\n\n\n# display(plt.show())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"636e46ed5418e7ed7717dbae34150cb9871f7ed2"},"cell_type":"code","source":"submission = pd.DataFrame()\nsubmission['ImageId'] = 1\nsubmission['LabelId'] = 33\nsubmission['Confidence'] = 1\nsubmission['PixelCount'] = 300\nsubmission['EncodedPixels'] = 1\nsubmission.to_csv('1.csv', index=False)\nsubmission.head(5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e66cb406cccdb7162b3ba9ae3dbcf2d73a4a6c8f"},"cell_type":"code","source":"from IPython.display import FileLink\n#%cd $LESSON_HOME_DIR\nFileLink('1.csv')","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}