application_vnd.jupyter.stderr_output_1.png
from pathlib import Path

import matplotlib

import matplotlib.pyplot as plt

import numpy as np

from pathlib import Path
import numpy as np
import cv2
import pydicom
import matplotlib
matplotlib.rcParams['animation.html'] = 'jshtml'
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from tqdm import tqdm

def load_voxel(study_id, scan_type='FLAIR', split='train', sz=256):
    assert sz in (64, 128, 256)
    data_root = Path(f'../input/rsna-miccai-voxel-{sz}-dataset')
    npy_path = Path(data_root).joinpath('voxel', split, study_id, f'{scan_type}.npy')
    voxel = np.load(str(npy_path))
    return voxel

def show_animation(images: list):
    '''
    Displays an animation from the list of images.
    
    set: matplotlib.rcParams['animation.html'] = 'jshtml'
    
    '''
    fig = plt.figure(figsize=(6, 6))
    plt.axis('off')
    im = plt.imshow(images[0], cmap='gray')
    
    def animate_func(i):
        im.set_array(images[i])
        return [im]
    
    return matplotlib.animation.FuncAnimation(fig, animate_func, frames = len(images), interval = 20)

flair_animation = show_animation(voxel)
flair_animation