{
  "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.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0,
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "_cell_guid": "0f245602-1b68-4fb9-f25b-959673f80fa6",
        "_active": false,
        "collapsed": false
      },
      "outputs": [],
      "source": "import os\nimport numpy as np\nimport tifffile as tiff\nimport cv2\nimport matplotlib.pyplot as plt\n\n\ndef 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    \ndef 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\n",
      "execution_state": "idle"
    },
    {
      "metadata": {
        "_cell_guid": "e8cea06e-f7e7-1854-1268-e9e4497bd85d",
        "_active": false,
        "collapsed": false
      },
      "source": "\nimage_id = '6120_2_3'\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",
      "execution_count": 3,
      "cell_type": "code",
      "outputs": [],
      "execution_state": "idle"
    },
    {
      "metadata": {
        "_cell_guid": "f155e9c0-3ec7-4196-f467-d8a747608ab4",
        "_active": false,
        "collapsed": false
      },
      "source": null,
      "execution_count": null,
      "cell_type": "code",
      "outputs": []
    }
  ]
}