{"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 pydicom\nimport matplotlib.pyplot as plt\nimport plotly.express as px\nimport cv2 \nimport os \nfrom pathlib import Path\nimport seaborn as sns","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-09-25T10:27:48.758137Z","iopub.execute_input":"2021-09-25T10:27:48.758485Z","iopub.status.idle":"2021-09-25T10:27:50.206174Z","shell.execute_reply.started":"2021-09-25T10:27:48.758453Z","shell.execute_reply":"2021-09-25T10:27:50.205316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_folder = Path('../input/rsna-miccai-brain-tumor-radiogenomic-classification/test')\ntrain_folder = Path('../input/rsna-miccai-brain-tumor-radiogenomic-classification/train')\ntrain_data = pd.read_csv('../input/rsna-miccai-brain-tumor-radiogenomic-classification/train_labels.csv')","metadata":{"execution":{"iopub.status.busy":"2021-09-25T10:28:38.254396Z","iopub.execute_input":"2021-09-25T10:28:38.254693Z","iopub.status.idle":"2021-09-25T10:28:38.262411Z","shell.execute_reply.started":"2021-09-25T10:28:38.254638Z","shell.execute_reply":"2021-09-25T10:28:38.261337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.info()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T10:29:30.976788Z","iopub.execute_input":"2021-09-25T10:29:30.977081Z","iopub.status.idle":"2021-09-25T10:29:30.988408Z","shell.execute_reply.started":"2021-09-25T10:29:30.977052Z","shell.execute_reply":"2021-09-25T10:29:30.987175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T10:29:24.096172Z","iopub.execute_input":"2021-09-25T10:29:24.096935Z","iopub.status.idle":"2021-09-25T10:29:24.106288Z","shell.execute_reply.started":"2021-09-25T10:29:24.096890Z","shell.execute_reply":"2021-09-25T10:29:24.105409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x=\"MGMT_value\", data=train_data)","metadata":{"execution":{"iopub.status.busy":"2021-09-25T10:29:51.482287Z","iopub.execute_input":"2021-09-25T10:29:51.482621Z","iopub.status.idle":"2021-09-25T10:29:51.716487Z","shell.execute_reply.started":"2021-09-25T10:29:51.482579Z","shell.execute_reply":"2021-09-25T10:29:51.715657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"px.histogram(train_data, x=\"MGMT_value\", color=\"MGMT_value\")","metadata":{"execution":{"iopub.status.busy":"2021-09-25T10:30:17.271403Z","iopub.execute_input":"2021-09-25T10:30:17.271734Z","iopub.status.idle":"2021-09-25T10:30:18.516389Z","shell.execute_reply.started":"2021-09-25T10:30:17.271700Z","shell.execute_reply":"2021-09-25T10:30:18.515419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_list = os.listdir(train_folder)\ntrain_data['im_folder'] = sorted(train_list)","metadata":{"execution":{"iopub.status.busy":"2021-09-25T10:30:48.152010Z","iopub.execute_input":"2021-09-25T10:30:48.152345Z","iopub.status.idle":"2021-09-25T10:30:48.192621Z","shell.execute_reply.started":"2021-09-25T10:30:48.152309Z","shell.execute_reply":"2021-09-25T10:30:48.191925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['im_path'] = [os.path.join(train_folder,data) for data in train_data[\"im_folder\"]]","metadata":{"execution":{"iopub.status.busy":"2021-09-25T10:30:58.084578Z","iopub.execute_input":"2021-09-25T10:30:58.084914Z","iopub.status.idle":"2021-09-25T10:30:58.093345Z","shell.execute_reply.started":"2021-09-25T10:30:58.084882Z","shell.execute_reply":"2021-09-25T10:30:58.092383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classes = [\"FLAIR\",\"T1w\",\"T1wCE\",\"T2w\"]","metadata":{"execution":{"iopub.status.busy":"2021-09-25T10:31:11.157120Z","iopub.execute_input":"2021-09-25T10:31:11.157424Z","iopub.status.idle":"2021-09-25T10:31:11.161981Z","shell.execute_reply.started":"2021-09-25T10:31:11.157391Z","shell.execute_reply":"2021-09-25T10:31:11.161082Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_count = []\n\nfor index, data in train_data.iterrows():\n    for c in classes:\n        img_count = len(os.listdir(os.path.join(data[\"im_path\"],c)))\n        \n        new = {'type': c,\n              'img_count': img_count,\n              'id': data['im_folder']}\n\n        data_count.append(new)","metadata":{"execution":{"iopub.status.busy":"2021-09-25T10:31:36.092788Z","iopub.execute_input":"2021-09-25T10:31:36.093113Z","iopub.status.idle":"2021-09-25T10:32:31.381946Z","shell.execute_reply.started":"2021-09-25T10:31:36.093081Z","shell.execute_reply":"2021-09-25T10:32:31.380896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_count_df = pd.DataFrame.from_dict(data_count)","metadata":{"execution":{"iopub.status.busy":"2021-09-25T10:32:31.396719Z","iopub.execute_input":"2021-09-25T10:32:31.397316Z","iopub.status.idle":"2021-09-25T10:32:31.409482Z","shell.execute_reply.started":"2021-09-25T10:32:31.397278Z","shell.execute_reply":"2021-09-25T10:32:31.408788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.bar(data_count_df.iloc[:56], x=\"id\", y=\"img_count\", color =\"type\" )\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T10:32:31.410845Z","iopub.execute_input":"2021-09-25T10:32:31.411690Z","iopub.status.idle":"2021-09-25T10:32:31.515994Z","shell.execute_reply.started":"2021-09-25T10:32:31.411656Z","shell.execute_reply":"2021-09-25T10:32:31.514923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image = pydicom.dcmread('../input/rsna-miccai-brain-tumor-radiogenomic-classification/train/00216/T1wCE/Image-98.dcm')\nraw_pixels = image.pixel_array\n\n# Plot the image\nplt.figure(figsize= (6,6))\nplt.imshow(raw_pixels, cmap='gray');","metadata":{"execution":{"iopub.status.busy":"2021-09-25T10:39:30.820317Z","iopub.execute_input":"2021-09-25T10:39:30.820780Z","iopub.status.idle":"2021-09-25T10:39:31.100259Z","shell.execute_reply.started":"2021-09-25T10:39:30.820739Z","shell.execute_reply":"2021-09-25T10:39:31.099408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, axes = plt.subplots(nrows=1, ncols=1,sharex=False, sharey=False, figsize=(10,4))\nplt.title('Pixel Range of raw pixels: ' + str(np.min(raw_pixels)) + '-' + str(np.max(raw_pixels)))\nplt.hist(raw_pixels.ravel(), np.max(raw_pixels), (1, np.max(raw_pixels)))\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T10:39:51.425537Z","iopub.execute_input":"2021-09-25T10:39:51.426398Z","iopub.status.idle":"2021-09-25T10:39:53.189094Z","shell.execute_reply.started":"2021-09-25T10:39:51.426357Z","shell.execute_reply":"2021-09-25T10:39:53.188018Z"},"trusted":true},"execution_count":null,"outputs":[]}]}