{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":24800,"databundleVersionId":1831594,"sourceType":"competition"}],"dockerImageVersionId":30587,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"raw","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfrom tqdm import tqdm\n\nfrom pydicom import dcmread\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-12-01T06:28:55.864484Z","iopub.execute_input":"2023-12-01T06:28:55.86565Z","iopub.status.idle":"2023-12-01T06:28:56.114734Z","shell.execute_reply.started":"2023-12-01T06:28:55.865594Z","shell.execute_reply":"2023-12-01T06:28:56.113102Z"}}},{"cell_type":"code","source":"path = '/kaggle/input/vinbigdata-chest-xray-abnormalities-detection/train'","metadata":{"execution":{"iopub.status.busy":"2023-12-01T06:22:06.963884Z","iopub.execute_input":"2023-12-01T06:22:06.964357Z","iopub.status.idle":"2023-12-01T06:22:06.971496Z","shell.execute_reply.started":"2023-12-01T06:22:06.964319Z","shell.execute_reply":"2023-12-01T06:22:06.970055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dicom_files = os.listdir(path)","metadata":{"execution":{"iopub.status.busy":"2023-12-01T06:23:00.738981Z","iopub.execute_input":"2023-12-01T06:23:00.739432Z","iopub.status.idle":"2023-12-01T06:23:00.753992Z","shell.execute_reply.started":"2023-12-01T06:23:00.739399Z","shell.execute_reply":"2023-12-01T06:23:00.752795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.DataFrame(columns=['image_name', 'chk'])","metadata":{"execution":{"iopub.status.busy":"2023-12-01T06:33:26.844441Z","iopub.execute_input":"2023-12-01T06:33:26.844955Z","iopub.status.idle":"2023-12-01T06:33:26.856735Z","shell.execute_reply.started":"2023-12-01T06:33:26.844918Z","shell.execute_reply":"2023-12-01T06:33:26.855536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for file in tqdm(dicom_files, desc='Processing:'):\n    complete_path = os.path.join(path,file)\n    ds = dcmread(complete_path)\n    if ds.PhotometricInterpretation == 'MONOCHROME2':\n        new_data = {'image_name': file, 'chk': 1}\n        df = df._append(new_data, ignore_index=True)\n    else:\n        new_data = {'image_name': file, 'chk': 0}\n        df = df._append(new_data, ignore_index=True)","metadata":{"execution":{"iopub.status.busy":"2023-12-01T06:38:18.459653Z","iopub.execute_input":"2023-12-01T06:38:18.460164Z","iopub.status.idle":"2023-12-01T07:19:25.424331Z","shell.execute_reply.started":"2023-12-01T06:38:18.46013Z","shell.execute_reply":"2023-12-01T07:19:25.422276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2023-12-01T07:19:25.427707Z","iopub.execute_input":"2023-12-01T07:19:25.428174Z","iopub.status.idle":"2023-12-01T07:19:25.460486Z","shell.execute_reply.started":"2023-12-01T07:19:25.428131Z","shell.execute_reply":"2023-12-01T07:19:25.458463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv('out.csv')","metadata":{"execution":{"iopub.status.busy":"2023-12-01T07:20:32.28762Z","iopub.execute_input":"2023-12-01T07:20:32.288421Z","iopub.status.idle":"2023-12-01T07:20:32.386788Z","shell.execute_reply.started":"2023-12-01T07:20:32.288372Z","shell.execute_reply":"2023-12-01T07:20:32.385416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}