edit : 파일 입출력 구조 변경

This commit is contained in:
2025-12-02 13:05:13 +09:00
parent b38a06dcbe
commit 9c811bb989
2 changed files with 25 additions and 16 deletions

View File

@@ -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'")

View File

@@ -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("하위 디렉토리가 없습니다.")