{"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":"markdown","source":"Published on July 29, 2023. By Marília Prata, mpwolke","metadata":{}},{"cell_type":"markdown","source":"#Oh, what sad times are these when passing bullies can say ni at will to old ladies.\n\nI still can't say Nii with those segmentations files.\n\nKaggle team and hosts are the keepers of the sacred word, 'Nii'\n\n\"Bring me a shrubbery\"","metadata":{}},{"cell_type":"code","source":"#Ignore warnings\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2023-07-29T23:42:48.929586Z","iopub.execute_input":"2023-07-29T23:42:48.929998Z","iopub.status.idle":"2023-07-29T23:42:48.935091Z","shell.execute_reply.started":"2023-07-29T23:42:48.929956Z","shell.execute_reply":"2023-07-29T23:42:48.933842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\n\nimport glob\nimport time\nimport numpy as np\nimport random\n\nfrom matplotlib import pyplot as plt\n\nimport pydicom\nimport nibabel as nib\nfrom glob import glob\nfrom tqdm import tqdm\nfrom pydicom.pixel_data_handlers.util import apply_voi_lut\n\npydicom.__version__, nib.__version__","metadata":{"execution":{"iopub.status.busy":"2023-07-29T23:42:54.481882Z","iopub.execute_input":"2023-07-29T23:42:54.48233Z","iopub.status.idle":"2023-07-29T23:42:54.491713Z","shell.execute_reply.started":"2023-07-29T23:42:54.482299Z","shell.execute_reply":"2023-07-29T23:42:54.490511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Thank you again Kaggle Knight David Roberts:","metadata":{}},{"cell_type":"code","source":"#By David Roberts https://www.kaggle.com/competitions/rsna-2023-abdominal-trauma-detection/discussion/427795\n\nimport matplotlib.pylab as plt\nimport nibabel as nib\nimport shutil\n\n# Copy a random label file to /kaggle/working directory (without .nii file extension)\nsrc = '/kaggle/input/rsna-2023-abdominal-trauma-detection/segmentations/6130'\ndst = '/kaggle/working/1000.nii'\n\nshutil.copyfile(src, dst);\n\n# Check the shape\nimg = nib.load(dst).get_fdata()\nprint(img.shape)\n\n# Plot a single frame from the middle of the stack\nplt.imshow(img[:,:,150])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-29T23:43:01.553849Z","iopub.execute_input":"2023-07-29T23:43:01.554286Z","iopub.status.idle":"2023-07-29T23:43:04.009557Z","shell.execute_reply.started":"2023-07-29T23:43:01.554252Z","shell.execute_reply":"2023-07-29T23:43:04.008527Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#By Innat https://www.kaggle.com/code/ipythonx/cervical-spine-fracture-detection-quick-eda\n\nsegmentation_masks = sorted(\n    glob(\n        '../input/rsna-2023-abdominal-trauma-detection/segmentations/*'\n    )\n)\n\n# num of segmentation mask\nlen(segmentation_masks)","metadata":{"execution":{"iopub.status.busy":"2023-07-29T22:40:52.17349Z","iopub.execute_input":"2023-07-29T22:40:52.173971Z","iopub.status.idle":"2023-07-29T22:40:52.184013Z","shell.execute_reply.started":"2023-07-29T22:40:52.173931Z","shell.execute_reply":"2023-07-29T22:40:52.182727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Just trying another Nii since I wasn't able to \"say\" Nii subplots with Images.","metadata":{}},{"cell_type":"code","source":"# Copy a random label file to /kaggle/working directory (without .nii file extension)\nsrc = '/kaggle/input/rsna-2023-abdominal-trauma-detection/segmentations/1201'\ndst = '/kaggle/working/1201.nii'\n\nshutil.copyfile(src, dst);\n\n# Check the shape\nimg = nib.load(dst).get_fdata()\nprint(img.shape)\n\n# Plot a single frame from the middle of the stack\nplt.imshow(img[:,:,150])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-29T23:43:47.145478Z","iopub.execute_input":"2023-07-29T23:43:47.145899Z","iopub.status.idle":"2023-07-29T23:43:50.208312Z","shell.execute_reply.started":"2023-07-29T23:43:47.145864Z","shell.execute_reply":"2023-07-29T23:43:50.207007Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"seg_path = '../input/rsna-2023-abdominal-trauma-detection/segmentations/'","metadata":{"execution":{"iopub.status.busy":"2023-07-29T23:08:50.903483Z","iopub.execute_input":"2023-07-29T23:08:50.904868Z","iopub.status.idle":"2023-07-29T23:08:50.911699Z","shell.execute_reply.started":"2023-07-29T23:08:50.904718Z","shell.execute_reply":"2023-07-29T23:08:50.910412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nseg_dirs = os.listdir(seg_path)","metadata":{"execution":{"iopub.status.busy":"2023-07-29T23:09:24.237332Z","iopub.execute_input":"2023-07-29T23:09:24.2378Z","iopub.status.idle":"2023-07-29T23:09:24.243518Z","shell.execute_reply.started":"2023-07-29T23:09:24.237762Z","shell.execute_reply":"2023-07-29T23:09:24.242481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Print out the first 5 file names to verify we're in the right folder.\nprint (f'Total of {len(seg_dirs)} Segmentation masks.\\nFirst 5 filenames:' )\nseg_dirs[:5]","metadata":{"execution":{"iopub.status.busy":"2023-07-29T23:10:26.876526Z","iopub.execute_input":"2023-07-29T23:10:26.877685Z","iopub.status.idle":"2023-07-29T23:10:26.888889Z","shell.execute_reply.started":"2023-07-29T23:10:26.877628Z","shell.execute_reply":"2023-07-29T23:10:26.887051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Acknowledgements:\n\nDavid Roberts https://www.kaggle.com/competitions/rsna-2023-abdominal-trauma-detection/discussion/427795\n\nInnat https://www.kaggle.com/code/ipythonx/cervical-spine-fracture-detection-quick-eda","metadata":{}},{"cell_type":"markdown","source":"#The Knights Who Say \"Ni!\" - Monty Python and the Holy Grail\n\n<iframe width=\"702\" height=\"395\" src=\"https://www.youtube.com/embed/zIV4poUZAQo\" title=\"The Knights Who Say &quot;Ni!&quot; - Monty Python and the Holy Grail\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen></iframe>\n\nhttps://www.youtube.com/watch?v=zIV4poUZAQo","metadata":{}}]}