{"cells":[{"metadata":{},"cell_type":"markdown","source":"### If you copy and run this notebook, the train images can be displayed in sequence as an animation.","execution_count":null},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true,"_kg_hide-input":false,"_kg_hide-output":false},"cell_type":"code","source":"!pip install imagecodecs\n!pip install tifffile","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":false,"trusted":true},"cell_type":"code","source":"import skimage.io\nimport matplotlib.pyplot as plt\nimport time\nimport numpy as np \nimport pandas as pd\nimport os","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":false,"trusted":true},"cell_type":"code","source":"df = pd.read_csv('../input/prostate-cancer-grade-assessment/train.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"num_frame = 50\ninterval = 10\nrepeat = False","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":false,"trusted":true},"cell_type":"code","source":"%matplotlib nbagg\n\nimport itertools\nimport math\n\nimport cv2\nimport numpy as np\nfrom matplotlib import pyplot as plt\nfrom matplotlib import animation\n\n\ndef _update(frame):\n    img_id = df.iloc[frame]['image_id']\n    img_path = '../input/prostate-cancer-grade-assessment/train_images/' + img_id + '.tiff'\n\n    image = skimage.io.MultiImage(img_path)[2]\n    image = np.array(image)\n    h,w,_ = image.shape\n    scale = 256/max(h,w)\n    image = cv2.resize(image, (int(w*scale),int(h*scale)))\n    plt.imshow(image)\n\nfig = plt.figure(figsize=(10, 6))\n\nparams = {\n    'fig': fig,\n    'func': _update,\n    'fargs': (),\n    'interval': interval,\n    'frames': np.arange(0, num_frame*interval, 1),\n    'repeat': repeat,\n    'blit': True,\n    'cache_frame_data': False,\n}\nanime = animation.FuncAnimation(**params)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"idx = 0","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(6,6))\nimg_id = df.iloc[idx]['image_id']\nimg_path = '../input/prostate-cancer-grade-assessment/train_images/' + img_id + '.tiff'\n\nimage = skimage.io.MultiImage(img_path)[2]\nimage = np.array(image)\nplt.imshow(image)\nidx += 1","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}