{"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":"gpu","dataSources":[{"sourceType":"competition","sourceId":13451,"datasetId":654585,"databundleVersionId":1188070}],"dockerImageVersionId":30920,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install pydicom","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-19T06:55:32.55611Z","iopub.execute_input":"2025-03-19T06:55:32.556456Z","iopub.status.idle":"2025-03-19T06:55:38.949545Z","shell.execute_reply.started":"2025-03-19T06:55:32.556432Z","shell.execute_reply":"2025-03-19T06:55:38.94843Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pydicom\n\n# Örnek dosya yolu (kendi verinle değiştir)\ndosya_yolu = \"/kaggle/input/rsna-intracranial-hemorrhage-detection/rsna-intracranial-hemorrhage-detection/stage_2_train/ID_000012eaf.dcm\"\n\n# DICOM dosyasını oku\ndcm = pydicom.dcmread(dosya_yolu)\n\n# Tüm metadataları yazdır\nprint(dcm)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-24T08:45:43.332083Z","iopub.execute_input":"2025-03-24T08:45:43.332449Z","iopub.status.idle":"2025-03-24T08:45:43.987534Z","shell.execute_reply.started":"2025-03-24T08:45:43.332419Z","shell.execute_reply":"2025-03-24T08:45:43.986538Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport time\nimport pydicom\nimport pandas as pd\nfrom tqdm import tqdm\n\n# DICOM dosyalarının bulunduğu ana klasör\ndicom_folder = \"/kaggle/input/rsna-intracranial-hemorrhage-detection/rsna-intracranial-hemorrhage-detection/stage_2_train\"\n# Oluşturulacak CSV'nin adı\noutput_csv = \"grouped_by_patient.csv\"\n\nstart_time = time.time()  # Süre ölçümü başlat\n\n# Hasta ID'lerine göre dosyaları tutacak sözlük\npatient_files_map = {}\n\n# Klasördeki tüm .dcm dosyalarını tara\nfor root, dirs, files in os.walk(dicom_folder):\n    for file_name in tqdm(files, desc=\"DICOM Tarama\"):\n        if file_name.lower().endswith(\".dcm\"):\n            file_path = os.path.join(root, file_name)\n            try:\n                # DICOM meta verisini oku (piksellere bakmadan hızlı okumak için stop_before_pixels=True)\n                ds = pydicom.dcmread(file_path, stop_before_pixels=True)\n                patient_id = ds.get(\"PatientID\", \"Unknown_Patient\")\n\n                # Bu hasta ID için ilk defa ekleme yapıyorsak liste oluştur\n                if patient_id not in patient_files_map:\n                    patient_files_map[patient_id] = []\n                # Dosya yolunu ekle\n                patient_files_map[patient_id].append(file_path)\n            except Exception as e:\n                print(f\"Hata oluştu ({file_path}): {e}\")\n\n# CSV'ye yazmak için satırları oluştur\nrows = []\nfor patient_id, file_paths in patient_files_map.items():\n    for fpath in file_paths:\n        rows.append({\n            \"PatientID\": patient_id,\n            \"FilePath\": fpath\n        })\n\n# DataFrame oluştur ve CSV kaydet\ndf = pd.DataFrame(rows)\ndf.to_csv(output_csv, index=False)\n\nend_time = time.time()  # Süre ölçümü bitir\nprint(f\"\\nİşlem tamamlandı. Dosya: {output_csv}\")\nprint(f\"Toplam süre: {end_time - start_time:.2f} saniye\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-24T09:21:07.473546Z","iopub.execute_input":"2025-03-24T09:21:07.473921Z","iopub.status.idle":"2025-03-24T13:00:47.527567Z","shell.execute_reply.started":"2025-03-24T09:21:07.473893Z","shell.execute_reply":"2025-03-24T13:00:47.526417Z"}},"outputs":[],"execution_count":null}]}