{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"44467348-62f7-9500-a63a-1a2e3389de3a"},"outputs":[],"source":"import os\nimport numpy as np\nimport tifffile as tiff\nimport cv2\nimport matplotlib.pyplot as plt"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"5adfaa05-6a55-bd9e-afb8-7ce030b021b3"},"outputs":[],"source":"def stretch_8bit(bands, lower_percent=2, higher_percent=98):\n    out = np.zeros_like(bands)\n    for i in range(3):\n        a = 0 \n        b = 255 \n        c = np.percentile(bands[:,:,i], lower_percent)\n        d = np.percentile(bands[:,:,i], higher_percent)        \n        t = a + (bands[:,:,i] - c) * (b - a) / (d - c)    \n        t[t<a] = a\n        t[t>b] = b\n        out[:,:,i] =t\n    return out.astype(np.uint8)    \n    "},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"7120a96e-69c6-81ba-32da-61134f47aada"},"outputs":[],"source":"def M(image_id):\n    filename = os.path.join('..', 'input', 'sixteen_band', '{}_M.tif'.format(image_id))\n    img = tiff.imread(filename)    \n    img = np.rollaxis(img, 0, 3)\n    return img"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"baefa13f-f632-e937-d83c-71ba0c7d3bfb"},"outputs":[],"source":"image_id='6120_2_2'\nfilename = os.path.join('..', 'input', 'sixteen_band', '{}_M.tif'.format(image_id))\nimg = tiff.imread(filename)\nprint (np.shape(img))\nimg = np.rollaxis(img, 0, 3)\nprint (np.shape(img))"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"0f245602-1b68-4fb9-f25b-959673f80fa6"},"outputs":[],"source":"image_id = '6120_2_2'\nm = M(image_id)\nimg = np.zeros((837,851,3))\nimg[:,:,0] = m[:,:,4] #red\nimg[:,:,1] = m[:,:,2] #green\nimg[:,:,2] = m[:,:,1] #blue\nplt.imshow(stretch_8bit(img))\n"}],"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.5.2"}},"nbformat":4,"nbformat_minor":0}