{"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":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n\"\"\"\"\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\"\"\"\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-06-06T13:17:09.833673Z","iopub.execute_input":"2021-06-06T13:17:09.834028Z","iopub.status.idle":"2021-06-06T13:17:09.844947Z","shell.execute_reply.started":"2021-06-06T13:17:09.834Z","shell.execute_reply":"2021-06-06T13:17:09.843855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('../input/siim-covid19-detection/train_image_level.csv')","metadata":{"execution":{"iopub.status.busy":"2021-06-06T13:18:03.547721Z","iopub.execute_input":"2021-06-06T13:18:03.548Z","iopub.status.idle":"2021-06-06T13:18:03.601669Z","shell.execute_reply.started":"2021-06-06T13:18:03.547978Z","shell.execute_reply":"2021-06-06T13:18:03.600313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2021-06-06T13:26:50.549159Z","iopub.execute_input":"2021-06-06T13:26:50.549545Z","iopub.status.idle":"2021-06-06T13:26:50.567632Z","shell.execute_reply.started":"2021-06-06T13:26:50.549517Z","shell.execute_reply":"2021-06-06T13:26:50.566331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! pip install pydicom\n","metadata":{"execution":{"iopub.status.busy":"2021-06-06T13:21:31.883543Z","iopub.execute_input":"2021-06-06T13:21:31.883816Z","iopub.status.idle":"2021-06-06T13:21:38.676271Z","shell.execute_reply.started":"2021-06-06T13:21:31.883792Z","shell.execute_reply":"2021-06-06T13:21:38.674726Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pydicom\ndataset = pydicom.dcmread('../input/siim-covid19-detection/test/00188a671292/3eb5a506ccf3/3dcdfc352a06.dcm')","metadata":{"execution":{"iopub.status.busy":"2021-06-06T13:22:22.977022Z","iopub.execute_input":"2021-06-06T13:22:22.977421Z","iopub.status.idle":"2021-06-06T13:22:23.865719Z","shell.execute_reply.started":"2021-06-06T13:22:22.97739Z","shell.execute_reply":"2021-06-06T13:22:23.864418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2021-06-06T13:30:37.596945Z","iopub.execute_input":"2021-06-06T13:30:37.597261Z","iopub.status.idle":"2021-06-06T13:30:37.605590Z","shell.execute_reply.started":"2021-06-06T13:30:37.597236Z","shell.execute_reply":"2021-06-06T13:30:37.604040Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.imshow(dataset.PixelData.reshape(im.shape[0], im.shape[1]), cmap=plt.cm.gray)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-06T13:36:41.602738Z","iopub.execute_input":"2021-06-06T13:36:41.603035Z","iopub.status.idle":"2021-06-06T13:36:41.618785Z","shell.execute_reply.started":"2021-06-06T13:36:41.603012Z","shell.execute_reply":"2021-06-06T13:36:41.616749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(dataset.PixelData)","metadata":{"execution":{"iopub.status.busy":"2021-06-06T13:37:02.238479Z","iopub.execute_input":"2021-06-06T13:37:02.238962Z","iopub.status.idle":"2021-06-06T13:37:02.246064Z","shell.execute_reply.started":"2021-06-06T13:37:02.238932Z","shell.execute_reply":"2021-06-06T13:37:02.244057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport matplotlib.pyplot as plt\nimport os, glob\nimport pydicom\nimport pylab as pl\nimport sys\nimport matplotlib.path as mplPath\n\nclass IndexTracker(object):\n    def __init__(self, ax, X):\n        self.ax = ax\n        ax.set_title('Scroll to Navigate through the DICOM Image Slices')\n\n        self.X = X\n        rows, cols, self.slices = X.shape\n        self.ind = self.slices//2\n\n        self.im = ax.imshow(self.X[:, :, self.ind])\n        self.update()\n\n    def onscroll(self, event):\n        print(\"%s %s\" % (event.button, event.step))\n        if event.button == 'up':\n            self.ind = (self.ind + 1) % self.slices\n        else:\n            self.ind = (self.ind - 1) % self.slices\n        self.update()\n\n    def update(self):\n        self.im.set_data(self.X[:, :, self.ind])\n        ax.set_ylabel('Slice Number: %s' % self.ind)\n        self.im.axes.figure.canvas.draw()\n\nfig, ax = plt.subplots(1,1)\n\nos.system(\"../input/siim-covid19-detection/train\")\n\nplots = []\n\nfor f in glob.glob(\"../input/siim-covid19-detection/train/000c9c05fd14/e555410bd2cd/51759b5579bc.dcm\"):\n    pass\n    filename = f.split(\"/\")[-1]\n    ds = dataset\n    pix = ds.pixel_array\n    pix = pix*1+(-1024)\n    plots.append(pix)\n\ny = np.dstack(plots)\n\ntracker = IndexTracker(ax, y)\n\nfig.canvas.mpl_connect('scroll_event', tracker.onscroll)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-06T13:44:11.487905Z","iopub.execute_input":"2021-06-06T13:44:11.488426Z","iopub.status.idle":"2021-06-06T13:44:13.193697Z","shell.execute_reply.started":"2021-06-06T13:44:11.488400Z","shell.execute_reply":"2021-06-06T13:44:13.192033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}