From 9c811bb98921da99afcfab08270b6afa7bb0a0b8 Mon Sep 17 00:00:00 2001 From: rudals252 Date: Tue, 2 Dec 2025 13:05:13 +0900 Subject: [PATCH] =?UTF-8?q?edit=20:=20=ED=8C=8C=EC=9D=BC=20=EC=9E=85?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DCM_NII_to_CVAT.py | 34 ++++++++++++++++++++-------------- NII_DCM_Viewer.py | 7 +++++-- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/DCM_NII_to_CVAT.py b/DCM_NII_to_CVAT.py index 890c3b2..67f8bbd 100644 --- a/DCM_NII_to_CVAT.py +++ b/DCM_NII_to_CVAT.py @@ -5,10 +5,17 @@ import nibabel as nib import pydicom from pathlib import Path import shutil +from datetime import datetime + +# --- 설정 (사용자 수정 가능) --- +DATA_ROOT = Path('.') # 데이터가 있는 최상위 경로 (현재: 실행 위치) +OUTPUT_ROOT_NAME = "Conversion_Results" # 결과물이 저장될 최상위 폴더명 +# ----------------------------- + +# 현재 시간으로 서브 폴더명 생성 (예: 20251202_123000) +TIMESTAMP = datetime.now().strftime("%Y%m%d_%H%M%S") +OUTPUT_DIR = DATA_ROOT / OUTPUT_ROOT_NAME / TIMESTAMP -# 설정 -ROOT_DIR = Path('.') -OUTPUT_DIR = ROOT_DIR / 'cvat_dataset_mask_v2' JPEG_DIR = OUTPUT_DIR / 'JPEGImages' SEG_CLASS_DIR = OUTPUT_DIR / 'SegmentationClass' IMAGE_SETS_DIR = OUTPUT_DIR / 'ImageSets' / 'Segmentation' @@ -133,21 +140,20 @@ def create_labelmap(): f.write("background:0,0,0::\n") def main(): - # 디렉토리 초기화 - if OUTPUT_DIR.exists(): - shutil.rmtree(OUTPUT_DIR) + # 디렉토리 생성 (타임스탬프 폴더이므로 삭제 불필요) + JPEG_DIR.mkdir(parents=True, exist_ok=True) + SEG_CLASS_DIR.mkdir(parents=True, exist_ok=True) + IMAGE_SETS_DIR.mkdir(parents=True, exist_ok=True) - JPEG_DIR.mkdir(parents=True) - SEG_CLASS_DIR.mkdir(parents=True) - IMAGE_SETS_DIR.mkdir(parents=True) - - print("Converting to CVAT Segmentation Mask 1.1 format...") + print(f"Converting to CVAT Segmentation Mask 1.1 format...") + print(f"Output Directory: {OUTPUT_DIR}") file_list = [] # 데이터 탐색 - for d in ROOT_DIR.iterdir(): - if d.is_dir() and not d.name.startswith('.') and 'cvat' not in d.name and 'segmask' not in d.name: + for d in DATA_ROOT.iterdir(): + # 결과 폴더, 숨김 폴더, cvat 관련 폴더 제외 + if d.is_dir() and not d.name.startswith('.') and OUTPUT_ROOT_NAME not in d.name and 'cvat' not in d.name and 'segmask' not in d.name: if list(d.glob('*.dcm')): process_case(d, file_list) @@ -162,7 +168,7 @@ def main(): print("\nDone! Dataset created at:", OUTPUT_DIR.absolute()) print(f"Total cases: {len(file_list)}") print("\n[중요] 업로드 시 주의사항:") - print("1. 'cvat_dataset_mask_v2' 폴더 안으로 들어가서") + print(f"1. 생성된 폴더 '{OUTPUT_DIR.name}' 안으로 들어가서") print("2. 모든 파일/폴더(JPEGImages, SegmentationClass, ImageSets, labelmap.txt)를 선택하고") print("3. '압축하기(ZIP)'를 실행하세요.") print("4. CVAT 포맷 선택: 'Segmentation Mask 1.1'") diff --git a/NII_DCM_Viewer.py b/NII_DCM_Viewer.py index 62dee58..55be959 100644 --- a/NII_DCM_Viewer.py +++ b/NII_DCM_Viewer.py @@ -14,7 +14,10 @@ import xml.etree.ElementTree as ET from pathlib import Path import re -ROOT_PATH = Path(__file__).parent +# --- 설정 (사용자 수정 가능) --- +DATA_ROOT = Path('.') # 데이터가 있는 최상위 경로 +# ----------------------------- + BASE_PATH = None DCM_FILE = None MITK_ORIGIN_Y = 966.81 @@ -135,7 +138,7 @@ def view_all_on_dcm(): def select_directory(): """디렉토리 선택""" global BASE_PATH, DCM_FILE - dirs = sorted([d for d in ROOT_PATH.iterdir() if d.is_dir() and not d.name.startswith('.')]) + dirs = sorted([d for d in DATA_ROOT.iterdir() if d.is_dir() and not d.name.startswith('.')]) if not dirs: print("하위 디렉토리가 없습니다.")