{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":99552,"databundleVersionId":13190393,"sourceType":"competition"}],"dockerImageVersionId":31089,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Intracranial Aneurysm Image View","metadata":{}},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np \nimport pandas as pd \nimport os\nimport pydicom\nimport matplotlib.pyplot as plt\nimport cv2\nimport random","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-07T14:15:03.405065Z","iopub.execute_input":"2025-08-07T14:15:03.405422Z","iopub.status.idle":"2025-08-07T14:15:03.421144Z","shell.execute_reply.started":"2025-08-07T14:15:03.405397Z","shell.execute_reply":"2025-08-07T14:15:03.419936Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=pd.read_csv('/kaggle/input/rsna-intracranial-aneurysm-detection/train.csv')\ntrain_loc=pd.read_csv('/kaggle/input/rsna-intracranial-aneurysm-detection/train_localizers.csv')\ndisplay(train[0:3])\ndisplay(train_loc[0:3])\nprint(len(train_loc))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-07T14:15:03.42232Z","iopub.execute_input":"2025-08-07T14:15:03.422765Z","iopub.status.idle":"2025-08-07T14:15:03.482948Z","shell.execute_reply.started":"2025-08-07T14:15:03.422699Z","shell.execute_reply":"2025-08-07T14:15:03.481881Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_loc[train_loc['SeriesInstanceUID']==train.iloc[4404,0]]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-07T14:15:03.485051Z","iopub.execute_input":"2025-08-07T14:15:03.485413Z","iopub.status.idle":"2025-08-07T14:15:03.496999Z","shell.execute_reply.started":"2025-08-07T14:15:03.48539Z","shell.execute_reply":"2025-08-07T14:15:03.496054Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import ast\ncoord_str = train_loc.iloc[2285, 2]\ncoord = ast.literal_eval(coord_str) \nprint(coord)\n\ndcm_path=f\"/kaggle/input/rsna-intracranial-aneurysm-detection/series/{train_loc.iloc[2285,0]}/{train_loc.iloc[2285,1]}.dcm\"\nprint(dcm_path)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-07T14:15:03.498018Z","iopub.execute_input":"2025-08-07T14:15:03.498366Z","iopub.status.idle":"2025-08-07T14:15:03.517825Z","shell.execute_reply.started":"2025-08-07T14:15:03.498336Z","shell.execute_reply":"2025-08-07T14:15:03.516189Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"i=2285\n\ndcm_path=f\"/kaggle/input/rsna-intracranial-aneurysm-detection/series/{train_loc.iloc[i,0]}/{train_loc.iloc[i,1]}.dcm\"\nds = pydicom.dcmread(dcm_path)\nsite=train_loc.iloc[i,3]\nimage = ds.pixel_array\ncoord = coord_str = train_loc.iloc[i, 2]\ncoord = ast.literal_eval(coord_str) \nplt.imshow(image, cmap='gray')\nplt.scatter(coord['x'], coord['y'], color='yellow', alpha=0.1, s=500)  \nplt.title(f\"{site} with IA\")\nplt.axis('off')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-07T14:15:03.518931Z","iopub.execute_input":"2025-08-07T14:15:03.519367Z","iopub.status.idle":"2025-08-07T14:15:03.724545Z","shell.execute_reply.started":"2025-08-07T14:15:03.519337Z","shell.execute_reply":"2025-08-07T14:15:03.723523Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def show(i):\n    dcm_path = f\"/kaggle/input/rsna-intracranial-aneurysm-detection/series/{train_loc.iloc[i, 0]}/{train_loc.iloc[i, 1]}.dcm\"\n    ds = pydicom.dcmread(dcm_path)\n    site = train_loc.iloc[i, 3]\n    image = ds.pixel_array\n\n    if image.ndim == 3:\n        image = image[image.shape[0] // 2] \n\n    coord_str = train_loc.iloc[i, 2]\n    coord = ast.literal_eval(coord_str)\n\n    plt.imshow(image, cmap='gray')\n    plt.scatter(coord['x'], coord['y'], color='yellow', alpha=0.1, s=500)\n    plt.title(f\"{site} with IA\")\n    plt.axis('off')\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-07T14:15:03.725707Z","iopub.execute_input":"2025-08-07T14:15:03.726007Z","iopub.status.idle":"2025-08-07T14:15:03.734221Z","shell.execute_reply.started":"2025-08-07T14:15:03.725982Z","shell.execute_reply":"2025-08-07T14:15:03.732939Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for i in random.sample(list(range(2256)),30):\n    show(i)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-07T14:15:03.735412Z","iopub.execute_input":"2025-08-07T14:15:03.735704Z","iopub.status.idle":"2025-08-07T14:15:05.874167Z","shell.execute_reply.started":"2025-08-07T14:15:03.735676Z","shell.execute_reply":"2025-08-07T14:15:05.873044Z"}},"outputs":[],"execution_count":null}]}