{"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":"import numpy as np\nimport pandas as pd\nimport os as os\nimport matplotlib.pyplot as plt\nimport pydicom\nfrom pydicom.pixel_data_handlers.util import apply_voi_lut","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-09-09T04:01:55.061724Z","iopub.execute_input":"2021-09-09T04:01:55.062243Z","iopub.status.idle":"2021-09-09T04:01:55.504760Z","shell.execute_reply.started":"2021-09-09T04:01:55.062139Z","shell.execute_reply":"2021-09-09T04:01:55.503631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.getcwd()","metadata":{"execution":{"iopub.status.busy":"2021-09-09T04:01:58.838184Z","iopub.execute_input":"2021-09-09T04:01:58.838624Z","iopub.status.idle":"2021-09-09T04:01:58.850323Z","shell.execute_reply.started":"2021-09-09T04:01:58.838584Z","shell.execute_reply":"2021-09-09T04:01:58.848884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.listdir('../input/siim-covid19-detection')","metadata":{"execution":{"iopub.status.busy":"2021-09-09T04:01:59.494880Z","iopub.execute_input":"2021-09-09T04:01:59.495264Z","iopub.status.idle":"2021-09-09T04:01:59.501634Z","shell.execute_reply.started":"2021-09-09T04:01:59.495230Z","shell.execute_reply":"2021-09-09T04:01:59.500839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('../input/siim-covid19-detection/train_study_level.csv')","metadata":{"execution":{"iopub.status.busy":"2021-09-09T04:02:00.255260Z","iopub.execute_input":"2021-09-09T04:02:00.255824Z","iopub.status.idle":"2021-09-09T04:02:00.278269Z","shell.execute_reply.started":"2021-09-09T04:02:00.255766Z","shell.execute_reply":"2021-09-09T04:02:00.277146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2021-09-09T04:02:02.343148Z","iopub.execute_input":"2021-09-09T04:02:02.343646Z","iopub.status.idle":"2021-09-09T04:02:02.372548Z","shell.execute_reply.started":"2021-09-09T04:02:02.343613Z","shell.execute_reply":"2021-09-09T04:02:02.371142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2021-09-09T04:02:02.698408Z","iopub.execute_input":"2021-09-09T04:02:02.698777Z","iopub.status.idle":"2021-09-09T04:02:02.706600Z","shell.execute_reply.started":"2021-09-09T04:02:02.698741Z","shell.execute_reply":"2021-09-09T04:02:02.705260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2021-09-07T05:02:37.372994Z","iopub.execute_input":"2021-09-07T05:02:37.373413Z","iopub.status.idle":"2021-09-07T05:02:37.383367Z","shell.execute_reply.started":"2021-09-07T05:02:37.373377Z","shell.execute_reply":"2021-09-07T05:02:37.381749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"col_ls = list(df.columns)\ncol_ls","metadata":{"execution":{"iopub.status.busy":"2021-09-07T05:03:01.648865Z","iopub.execute_input":"2021-09-07T05:03:01.649466Z","iopub.status.idle":"2021-09-07T05:03:01.656977Z","shell.execute_reply.started":"2021-09-07T05:03:01.649419Z","shell.execute_reply":"2021-09-07T05:03:01.656162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del col_ls[0]\n\ncol_ls","metadata":{"execution":{"iopub.status.busy":"2021-09-07T05:03:24.098124Z","iopub.execute_input":"2021-09-07T05:03:24.098846Z","iopub.status.idle":"2021-09-07T05:03:24.107109Z","shell.execute_reply.started":"2021-09-07T05:03:24.098782Z","shell.execute_reply":"2021-09-07T05:03:24.105796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[col_ls].sum()","metadata":{"execution":{"iopub.status.busy":"2021-09-07T05:03:53.314264Z","iopub.execute_input":"2021-09-07T05:03:53.31464Z","iopub.status.idle":"2021-09-07T05:03:53.327096Z","shell.execute_reply.started":"2021-09-07T05:03:53.314609Z","shell.execute_reply":"2021-09-07T05:03:53.325775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2021-09-07T04:53:35.311797Z","iopub.execute_input":"2021-09-07T04:53:35.31234Z","iopub.status.idle":"2021-09-07T04:53:35.318237Z","shell.execute_reply.started":"2021-09-07T04:53:35.312306Z","shell.execute_reply":"2021-09-07T04:53:35.31703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Data graph","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize = (10, 8))\n\nplt.bar(col_ls, df[col_ls].sum())\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-07T05:06:56.501814Z","iopub.execute_input":"2021-09-07T05:06:56.502274Z","iopub.status.idle":"2021-09-07T05:06:56.660915Z","shell.execute_reply.started":"2021-09-07T05:06:56.50224Z","shell.execute_reply":"2021-09-07T05:06:56.66003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_img = pd.read_csv('../input/siim-covid19-detection/train_image_level.csv')","metadata":{"execution":{"iopub.status.busy":"2021-09-07T05:09:14.044419Z","iopub.execute_input":"2021-09-07T05:09:14.044853Z","iopub.status.idle":"2021-09-07T05:09:14.100362Z","shell.execute_reply.started":"2021-09-07T05:09:14.04482Z","shell.execute_reply":"2021-09-07T05:09:14.099346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_img.head()","metadata":{"execution":{"iopub.status.busy":"2021-09-07T05:09:20.741906Z","iopub.execute_input":"2021-09-07T05:09:20.742328Z","iopub.status.idle":"2021-09-07T05:09:20.755742Z","shell.execute_reply.started":"2021-09-07T05:09:20.742293Z","shell.execute_reply":"2021-09-07T05:09:20.754422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"## Image ","metadata":{}},{"cell_type":"code","source":"# https://www.kaggle.com/tanlikesmath/siim-covid-19-detection-a-simple-eda 참고 \n\ndef dicom2array(path, voi_lut=True, fix_monochrome=True):\n    dicom = pydicom.read_file(path)\n    # VOI LUT (if available by DICOM device) is used to\n    # transform raw DICOM data to \"human-friendly\" view\n    if voi_lut:\n        data = apply_voi_lut(dicom.pixel_array, dicom)\n    else:\n        data = dicom.pixel_array\n    # depending on this value, X-ray may look inverted - fix that:\n    if fix_monochrome and dicom.PhotometricInterpretation == \"MONOCHROME1\":\n        data = np.amax(data) - data\n    data = data - np.min(data)\n    data = data / np.max(data)\n    data = (data * 255).astype(np.uint8)\n    return data\n        \n    \ndef plot_img(img, size=(7, 7), is_rgb=True, title=\"\", cmap='gray'):\n    plt.figure(figsize=size)\n    plt.imshow(img, cmap=cmap)\n    plt.suptitle(title)\n    plt.show()\n\n\ndef plot_imgs(imgs, cols=4, size=7, is_rgb=True, title=\"\", cmap='gray', img_size=(500,500)):\n    rows = len(imgs)//cols + 1\n    fig = plt.figure(figsize=(cols*size, rows*size))\n    for i, img in enumerate(imgs):\n        if img_size is not None:\n            img = cv2.resize(img, img_size)\n        fig.add_subplot(rows, cols, i+1)\n        plt.imshow(img, cmap=cmap)\n    plt.suptitle(title)\n\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-07T05:14:28.32191Z","iopub.execute_input":"2021-09-07T05:14:28.322299Z","iopub.status.idle":"2021-09-07T05:14:28.335555Z","shell.execute_reply.started":"2021-09-07T05:14:28.322266Z","shell.execute_reply":"2021-09-07T05:14:28.334573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dicom = pydicom.read_file('../input/siim-covid19-detection/train/00086460a852/9e8302230c91/65761e66de9f.dcm')","metadata":{"execution":{"iopub.status.busy":"2021-09-09T04:02:15.933349Z","iopub.execute_input":"2021-09-09T04:02:15.934235Z","iopub.status.idle":"2021-09-09T04:02:16.448996Z","shell.execute_reply.started":"2021-09-09T04:02:15.934180Z","shell.execute_reply":"2021-09-09T04:02:16.447678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = apply_voi_lut(dicom.pixel_array, dicom)","metadata":{"execution":{"iopub.status.busy":"2021-09-09T04:02:24.928722Z","iopub.execute_input":"2021-09-09T04:02:24.929134Z","iopub.status.idle":"2021-09-09T04:02:24.941024Z","shell.execute_reply.started":"2021-09-09T04:02:24.929102Z","shell.execute_reply":"2021-09-09T04:02:24.939657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = data - np.min(data)\ndata = data / np.max(data)\ndata = (data * 255).astype(np.uint8)","metadata":{"execution":{"iopub.status.busy":"2021-09-09T04:07:09.813427Z","iopub.execute_input":"2021-09-09T04:07:09.813924Z","iopub.status.idle":"2021-09-09T04:07:09.880180Z","shell.execute_reply.started":"2021-09-09T04:07:09.813881Z","shell.execute_reply":"2021-09-09T04:07:09.879155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8, 8))\nplt.imshow(data)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-09T04:08:55.744494Z","iopub.execute_input":"2021-09-09T04:08:55.744965Z","iopub.status.idle":"2021-09-09T04:08:56.631619Z","shell.execute_reply.started":"2021-09-09T04:08:55.744923Z","shell.execute_reply":"2021-09-09T04:08:56.630175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}