하이델베르그 대학 병원 신경방사선학과와 독일 암 연구 센터(DKFZ)에서 공동 개발한 Brain Extraction Tool
이 툴은 Linux 환경에서만 사용이 가능합니다!
pip --version
python version이 3.X인 것을 확인해야 합니다.
git clone https://github.com/MIC-DKFZ/HD-BET
cd HD-BET
pip install -e .
깃허브 설명에 따르면, HD-BET를 실행하기 위해서는 home에 생성된 HD-BET 폴더에 input으로 사용할 파일이 들어있어야 합니다.

그런데 터미널에서는 폴더 디렉토리 대신 다이렉트로 파일 이름을 입력하기 때문에 파일이 어디있든지 상관없지 않을까 싶지만.. 굳이 따르지 않을 이유는 없을 거 같아서..^^;
import HD_BET
from HD_BET.run import run_hd_bet
# load files
input_dir = " " % input file 혹은 폴더 디렉토리
output_dir = " " % output file 이름 혹은 저장하고자 하는 폴더 디렉토리
input_files = os.listdir(input_dir)
for i in input_files:
run_hd_bet(input_dir + i, output_dir + i, keep_mask=False, bet=True)
만약에 라이브러리가 설치되지 않았다는 에러가 뜬다면
pip install HD_BET
을 먼저 실행해야 합니다.
parser.add_argument('-i', '--input', help='input. Can be either a single file name or an input folder. If file: must be '
'nifti (.nii.gz) and can only be 3D. No support for 4d images, use fslsplit to '
'split 4d sequences into 3d images. If folder: all files ending with .nii.gz '
'within that folder will be brain extracted.', required=True, type=str)
parser.add_argument('-o', '--output', help='output. Can be either a filename or a folder. If it does not exist, the folder'
' will be created', required=False, type=str)
parser.add_argument('-mode', type=str, default='accurate', help='can be either \'fast\' or \'accurate\'. Fast will '
'use only one set of parameters whereas accurate will '
'use the five sets of parameters that resulted from '
'our cross-validation as an ensemble. Default: '
'accurate',
required=False)
parser.add_argument('-device', default='0', type=str, help='used to set on which device the prediction will run. '
'Must be either int or str. Use int for GPU id or '
'\'cpu\' to run on CPU. When using CPU you should '
'consider disabling tta. Default for -device is: 0',
required=False)
parser.add_argument('-tta', default=1, required=False, type=int, help='whether to use test time data augmentation '
'(mirroring). 1= True, 0=False. Disable this '
'if you are using CPU to speed things up! '
'Default: 1')
parser.add_argument('-pp', default=1, type=int, required=False, help='set to 0 to disabe postprocessing (remove all'
' but the largest connected component in '
'the prediction. Default: 1')
parser.add_argument('-s', '--save_mask', default=1, type=int, required=False, help='if set to 0 the segmentation '
'mask will not be '
'saved')
parser.add_argument('--overwrite_existing', default=1, type=int, required=False, help="set this to 0 if you don't "
"want to overwrite existing "
"predictions")
parser.add_argument('-b','--bet', default=1, type=int, required=False, help="set this to 0 if you don't want to save skull-stripped brain")
run_hd_bet(input_files, output_files, mode, config_file, device, pp, tta, save_mask, overwrite_existing, bet)
파라미터 조정은 위의 코드를 참고하면 됩니다.
저는 마스크는 필요 없고, brain extraction이 된 output만 필요하기 때문에 save_mask = False, bet = True로 전처리를 수행하였습니다.
![]() | ![]() |
|---|
제가 사용하고자 하는 raw 데이터입니다. ATLAS 등록은 되어있지만 뇌 이외의 조직들이 전부 포함되어 있습니다.

뇌 영역이 깔끔하게 추출되었고, mri의 밝기와 대비도 자동으로 조정이 되었습니다~.~