{"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":"!pip install python-gdcm pydicom pylibjpeg","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-09-18T09:26:02.141585Z","iopub.execute_input":"2023-09-18T09:26:02.142082Z","iopub.status.idle":"2023-09-18T09:26:19.731938Z","shell.execute_reply.started":"2023-09-18T09:26:02.142025Z","shell.execute_reply":"2023-09-18T09:26:19.730694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport cv2\nimport glob\nimport gdcm\nimport pydicom\nimport zipfile\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport sys\nfrom tqdm import tqdm\nfrom joblib import Parallel, delayed\nfrom pydicom.pixel_data_handlers.util import apply_voi_lut\nfrom PIL import Image\nfrom matplotlib import image as mpimg","metadata":{"execution":{"iopub.status.busy":"2023-09-18T09:40:50.044075Z","iopub.execute_input":"2023-09-18T09:40:50.044587Z","iopub.status.idle":"2023-09-18T09:40:50.053127Z","shell.execute_reply.started":"2023-09-18T09:40:50.044549Z","shell.execute_reply":"2023-09-18T09:40:50.0514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"one_image_dir = '/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/21057/1000.dcm'\nim = pydicom.dcmread(one_image_dir)\n","metadata":{"execution":{"iopub.status.busy":"2023-09-18T09:30:12.332502Z","iopub.execute_input":"2023-09-18T09:30:12.332927Z","iopub.status.idle":"2023-09-18T09:30:12.356505Z","shell.execute_reply.started":"2023-09-18T09:30:12.33289Z","shell.execute_reply":"2023-09-18T09:30:12.355292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image = im.pixel_array.astype(float)\n\n\nrescaled = (np.maximum(image, 0) / image.max()) * 255\n\nfinal = np.uint8(rescaled)\n\nfinal_image = Image.fromarray(final)\n\n\n","metadata":{"execution":{"iopub.status.busy":"2023-09-18T09:38:10.789981Z","iopub.execute_input":"2023-09-18T09:38:10.790493Z","iopub.status.idle":"2023-09-18T09:38:10.801134Z","shell.execute_reply.started":"2023-09-18T09:38:10.790456Z","shell.execute_reply":"2023-09-18T09:38:10.799775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_image.save('new_image.png')","metadata":{"execution":{"iopub.status.busy":"2023-09-18T09:38:13.092626Z","iopub.execute_input":"2023-09-18T09:38:13.093143Z","iopub.status.idle":"2023-09-18T09:38:13.165756Z","shell.execute_reply.started":"2023-09-18T09:38:13.093096Z","shell.execute_reply":"2023-09-18T09:38:13.164439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image = mpimg.imread(\"/kaggle/working/new_image.png\")\nplt.imshow(image)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-09-18T09:40:57.549196Z","iopub.execute_input":"2023-09-18T09:40:57.549655Z","iopub.status.idle":"2023-09-18T09:40:57.941129Z","shell.execute_reply.started":"2023-09-18T09:40:57.54962Z","shell.execute_reply":"2023-09-18T09:40:57.940096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}