{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Blood Vessel Mask Slide Show ","metadata":{}},{"cell_type":"markdown","source":"https://www.kaggle.com/stpeteishii/blood-vessel-image-slide-show<br/>\nhttps://www.kaggle.com/stpeteishii/blood-vessel-mask-slide-show","metadata":{}},{"cell_type":"code","source":"import os\nimport cv2\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom matplotlib import animation, rc\nrc('animation', html='jshtml')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-11-09T14:04:59.061044Z","iopub.execute_input":"2023-11-09T14:04:59.062605Z","iopub.status.idle":"2023-11-09T14:04:59.07058Z","shell.execute_reply.started":"2023-11-09T14:04:59.062559Z","shell.execute_reply":"2023-11-09T14:04:59.068914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def create_animation(ims):\n    fig=plt.figure(figsize=(15,6))\n    plt.axis('off')\n    im=plt.imshow(ims[0])\n    #im=plt.imshow(cv2.cvtColor(ims[0],cv2.COLOR_BGR2RGB))\n    plt.close()\n    def animate_func(i):\n        im.set_array(ims[i])\n        #im.set_array(cv2.cvtColor(ims[i],cv2.COLOR_BGR2RGB))\n        return [im]\n    return animation.FuncAnimation(fig, animate_func, frames=len(ims), interval=1000/20)    ","metadata":{"execution":{"iopub.status.busy":"2023-11-09T14:04:59.073153Z","iopub.execute_input":"2023-11-09T14:04:59.073534Z","iopub.status.idle":"2023-11-09T14:04:59.095033Z","shell.execute_reply.started":"2023-11-09T14:04:59.073501Z","shell.execute_reply":"2023-11-09T14:04:59.093516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# kidney_1_dense","metadata":{}},{"cell_type":"code","source":"ipaths=[]\nlpaths=[]\nfor dirname, _, filenames in os.walk('/kaggle/input/blood-vessel-segmentation/train/kidney_1_dense'):\n    for filename in filenames:\n        if dirname.split('/')[-1]=='images':\n            ipaths+=[(os.path.join(dirname, filename))]\n        elif dirname.split('/')[-1]=='labels':\n            lpaths+=[(os.path.join(dirname, filename))]\nipaths.sort()\nlpaths.sort()\n\nimages=[]\nfor i in range(len(lpaths)):\n    #img1 = cv2.imread(lpaths[i],cv2.IMREAD_ANYDEPTH)\n    #img1 = cv2.imread(lpaths[i], cv2.IMREAD_UNCHANGED)\n    img1 = cv2.imread(lpaths[i])\n    img1=np.rot90(img1)\n    img1=cv2.resize(img1,dsize=None,fx=0.2,fy=0.2)\n    images+=[img1]\n    \ncreate_animation(images)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# kidney_1_voi","metadata":{}},{"cell_type":"code","source":"ipaths=[]\nlpaths=[]\nfor dirname, _, filenames in os.walk('/kaggle/input/blood-vessel-segmentation/train/kidney_1_voi'):\n    for filename in filenames:\n        if dirname.split('/')[-1]=='images':\n            ipaths+=[(os.path.join(dirname, filename))]\n        elif dirname.split('/')[-1]=='labels':\n            lpaths+=[(os.path.join(dirname, filename))]\nipaths.sort()\nlpaths.sort()\n\nimages=[]\nfor i in range(len(lpaths)):\n    #img1 = cv2.imread(lpaths[i],cv2.IMREAD_ANYDEPTH)\n    #img1 = cv2.imread(lpaths[i], cv2.IMREAD_UNCHANGED)\n    img1 = cv2.imread(lpaths[i])    \n    img1 = np.rot90(img1)\n    img1 = cv2.resize(img1,dsize=None,fx=0.2,fy=0.2)\n    images+=[img1]\n    \ncreate_animation(images)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# kidney_2","metadata":{}},{"cell_type":"code","source":"ipaths=[]\nlpaths=[]\nfor dirname, _, filenames in os.walk('/kaggle/input/blood-vessel-segmentation/train/kidney_2'):\n    for filename in filenames:\n        if dirname.split('/')[-1]=='images':\n            ipaths+=[(os.path.join(dirname, filename))]\n        elif dirname.split('/')[-1]=='labels':\n            lpaths+=[(os.path.join(dirname, filename))]\nipaths.sort()\nlpaths.sort()\n\nimages=[]\nfor i in range(len(lpaths)):\n    #img1 = cv2.imread(lpaths[i],cv2.IMREAD_ANYDEPTH)\n    #img1 = cv2.imread(lpaths[i], cv2.IMREAD_UNCHANGED)\n    img1 = cv2.imread(lpaths[i])        \n    #img1=np.rot90(img1)\n    img1=cv2.resize(img1,dsize=None,fx=0.2,fy=0.2)\n    images+=[img1]\n    \ncreate_animation(images)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# kidney_3_dense","metadata":{}},{"cell_type":"code","source":"ipaths=[]\nlpaths=[]\nfor dirname, _, filenames in os.walk('/kaggle/input/blood-vessel-segmentation/train/kidney_3_dense'):\n    for filename in filenames:\n        if dirname.split('/')[-1]=='images':\n            ipaths+=[(os.path.join(dirname, filename))]\n        elif dirname.split('/')[-1]=='labels':\n            lpaths+=[(os.path.join(dirname, filename))]\nipaths.sort()\nlpaths.sort()\n\nimages=[]\nfor i in range(len(lpaths)):\n    #img1 = cv2.imread(lpaths[i],cv2.IMREAD_ANYDEPTH)\n    #img1 = cv2.imread(lpaths[i], cv2.IMREAD_UNCHANGED)\n    img1 = cv2.imread(lpaths[i])    \n    img1 = np.rot90(img1)\n    img1 = cv2.resize(img1,dsize=None,fx=0.2,fy=0.2)\n    images+=[img1]\n    \ncreate_animation(images)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# kidney_3_sparse","metadata":{}},{"cell_type":"code","source":"ipaths=[]\nlpaths=[]\nfor dirname, _, filenames in os.walk('/kaggle/input/blood-vessel-segmentation/train/kidney_3_sparse'):\n    for filename in filenames:\n        if dirname.split('/')[-1]=='images':\n            ipaths+=[(os.path.join(dirname, filename))]\n        elif dirname.split('/')[-1]=='labels':\n            lpaths+=[(os.path.join(dirname, filename))]\nipaths.sort()\nlpaths.sort()\n\nimages=[]\nfor i in range(len(lpaths)):\n    #img1 = cv2.imread(lpaths[i],cv2.IMREAD_ANYDEPTH)\n    #img1 = cv2.imread(lpaths[i], cv2.IMREAD_UNCHANGED)\n    img1 = cv2.imread(lpaths[i])        \n    img1 = np.rot90(img1)\n    img1 = cv2.resize(img1,dsize=None,fx=0.2,fy=0.2)\n    images+=[img1]\n    \ncreate_animation(images)","metadata":{},"execution_count":null,"outputs":[]}]}