{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"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# source https://colab.research.google.com/github/tensorflow/io/blob/master/docs/tutorials/dicom.ipynb#scrollTo=WodUv8O1VKmr","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"list(os.listdir(\"../input/rsna-str-pulmonary-embolism-detection\"))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%%time\nDATA_PATH = \"../input/rsna-str-pulmonary-embolism-detection\"\n\ntrain = pd.read_csv(f\"{DATA_PATH}/train.csv\")\ntest = pd.read_csv(f\"{DATA_PATH}/test.csv\")\nsample_submission = pd.read_csv(f\"{DATA_PATH}/sample_submission.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.head(10)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"!ls /kaggle/input/rsna-str-pulmonary-embolism-detection/train/6897fa9de148/2bfbb7fd2e8b","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# %%time\n# files = folders = 0\n\n# for _, dirnames, filenames in os.walk(f\"{DATA_PATH}/train\"):\n#     files += len(filenames)\n#     folders += len(dirnames)\n# print(\"Total number of folders in train:{} and files in it:{}\".format(folders,files))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Total number of folders in train:14558 and files in it:1790594  \nCPU times: user 4.38 s, sys: 10.7 s, total: 15.1 s  \nWall time: 3min 37s  "},{"metadata":{"trusted":true},"cell_type":"code","source":"# len(train.StudyInstanceUID.unique()),len(train.SeriesInstanceUID.unique()),len(train.SOPInstanceUID.unique())\n# (7279, 7279, 1790594)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"!pip install tensorflow-io","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import tensorflow as tf\nimport tensorflow_io as tfio\nfrom pathlib import Path\nimport matplotlib.pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"DATA_PATH = Path(DATA_PATH)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image_bytes = tf.io.read_file('/kaggle/input/rsna-str-pulmonary-embolism-detection/train/6897fa9de148/2bfbb7fd2e8b/031618cba689.dcm')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image       = tfio.image.decode_dicom_image(image_bytes, dtype=tf.uint16)\nskipped     = tfio.image.decode_dicom_image(image_bytes, on_error='skip', dtype=tf.uint8)\nlossy_image = tfio.image.decode_dicom_image(image_bytes, scale='auto', on_error='lossy', dtype=tf.uint8)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"type(skipped), type(skipped.numpy()), skipped.numpy() ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image.numpy().shape, lossy_image.numpy().shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, axes = plt.subplots(1,3, figsize=(10,10))\n\naxes[0].imshow(np.squeeze(image.numpy()), cmap='gray')\naxes[0].set_title('image')\naxes[1].imshow(np.squeeze(lossy_image.numpy()), cmap='gray')\naxes[1].set_title('lossy image');\naxes[2].imshow(np.squeeze(lossy_image.numpy() - image.numpy()), cmap='gray')\naxes[2].set_title('diff b/w images');","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, axes = plt.subplots(3,1, figsize=(20,20))\n\naxes[0].imshow(np.squeeze(image.numpy()), cmap='gray')\naxes[0].set_title('image')\naxes[1].imshow(np.squeeze(lossy_image.numpy()), cmap='gray')\naxes[1].set_title('lossy image');","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"np.sum(image.numpy() - lossy_image.numpy())","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## if you found this beneficial please consider upvoting"}],"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}