{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"67f0bbbb-e38a-834e-86e0-345b7ed896db"},"outputs":[],"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\nimport matplotlib.pyplot as plt\nimport tifffile as tiff\nimport skimage\nfrom skimage import measure\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\nfrom subprocess import check_output\nprint(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n\n# Any results you write to the current directory are saved as output."},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"1a60538b-ae60-6903-0b09-2e4a3c9351d6"},"outputs":[],"source":"x, y = np.ogrid[-np.pi:np.pi:100j, -np.pi:np.pi:100j]\nr = np.sin(np.exp((np.sin(x)**3 + np.cos(y)**2)))\n"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"cb7eab6a-15f7-7c26-f3fe-e681176605db"},"outputs":[],"source":"print(r.shape)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"62ee2db8-1039-6639-d0a8-9b1c1634946a"},"outputs":[],"source":"contours = measure.find_contours(r, 0.8)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"402f75e1-a382-3a13-b8a5-496bac3b6e75"},"outputs":[],"source":"print(contours[0])"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"f6bcac2c-864a-2388-a9fd-8616e0fa7ef1"},"outputs":[],"source":"print(len(contours))"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"7729142e-026c-d134-1c57-e8bba75b1d59"},"outputs":[],"source":"contours[0].shape"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"ff24f2bf-f496-a9d4-1194-7cfa7ac14498"},"outputs":[],"source":"contours[1].shape\n"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"bb116b3c-6a59-f33b-3861-bf740cb88b0f"},"outputs":[],"source":"for i in range(len(contours)):\n    print (i, contours[i].shape)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"72c8fb4c-a6bd-e5b4-f9dc-20e4f6bbcfc1"},"outputs":[],"source":"import PIL\nimport PIL.Image as Image\nimport glob\n"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"209043b6-f809-1819-1983-6670704325ae"},"outputs":[],"source":"imnames = glob.glob(\"../input/three_band/*.tif\")"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"6a21dddd-7b73-f4bd-0b5b-886d6589d3f9"},"outputs":[],"source":"print(imnames[0])"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"d40aa487-05c6-4895-e020-4a4375ae10f7"},"outputs":[],"source":"len(imnames)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"18e38a20-ddc7-169e-8963-3ad6fac5ec86"},"outputs":[],"source":"im = tiff.imread(imnames[30])"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"ba5ff807-2d24-193f-da8e-f8e44cbe0bb8"},"outputs":[],"source":"im.shape"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"9a7ce7cb-3586-cf93-69a9-4448ecc7585c"},"outputs":[],"source":"#plt.imshow(im[0])\n#plt.imshow(im[1])\n#plt.imshow(im[2])\nax = tiff.imshow(im)\n"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"ffb7e3d6-d28e-1ae6-9bb9-ca3a189a400f"},"outputs":[],"source":"contim = measure.find_contours(im[0], 350)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"d16c0b66-ff5a-7360-1fd4-38e01e6b4260"},"outputs":[],"source":"len(contim)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"fe04ec4a-da18-461d-fa0a-9baa9e834375"},"outputs":[],"source":"contim[0]"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"3031f765-6da1-5a02-c477-718c526e5ea3"},"outputs":[],"source":"fig, ax = plt.subplots()\nax.imshow(im[0], interpolation='nearest', cmap=plt.cm.gray)\n#for n, contour in enumerate(contim):\n#    ax.plot(contim[:, 1], contim[:, 0], linewidth=2)\nfor single in contim:\n    ax.plot(single[:,1],single[:,0],linewidth = 2, color = 'blue')\nplt.show()    "},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"4e6b9d83-85c5-6d84-2ff8-f28f845bfc30"},"outputs":[],"source":"def cfind(iname,clevel,band = 0):\n    img = tiff.imread(iname)\n    contim = measure.find_contours(img[band], clevel)\n    print(len(contim))\n    fig, ax = plt.subplots()\n    tiff.imshow(img, figure=fig, subplot=ax)\n    \n    for single in contim:\n        ax.plot(single[:,1],single[:,0],linewidth = 2, color = 'blue')\n    ax.autoscale_view()\n    ax.set_title(iname)\n    ax.set_xticks([])\n    ax.set_yticks([])    \n    plt.show()\n    return ax\n    \n    "},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"1fbd67b7-70c6-eb08-7ec3-11e75189f567"},"outputs":[],"source":"cfind(imnames[120],300)\nplt.show()"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"b99ef904-025a-352a-280b-be23c4d7d755"},"outputs":[],"source":"cfind(imnames[120],600,band = 1)\nplt.show()"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"4f6a6b3f-870a-c1e7-704d-e3612c075f68"},"outputs":[],"source":"cfind(imnames[120],600,band = 2)\nplt.show()"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"c9dd09d6-e612-a42f-e64b-5499fa44c219"},"outputs":[],"source":"fin = glob.glob(\"../input/three_band/6070_2_3*.tif\")"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"b5cd3960-093c-7135-2a58-fb6e89208155"},"outputs":[],"source":"fin"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"d9663e17-a9fa-b63b-f8c6-6cf3ba17b48d"},"outputs":[],"source":"cfind(fin[0],300)\nplt.show()\n"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"4ba93aa8-5c48-b0b8-1732-bfa6bbc6babd"},"outputs":[],"source":"cfind(fin[0],600,band = 1)\nplt.show()\n"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"2e43a3f8-530f-d74c-c535-d628752de50d"},"outputs":[],"source":"cfind(fin[0],600,band = 2)\nplt.show()"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"178bd66c-6723-a141-d6cd-c5b61864e559"},"outputs":[],"source":""}],"metadata":{"_change_revision":0,"_is_fork":false,"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.0"}},"nbformat":4,"nbformat_minor":0}