๐Ÿ”ฌ Medical Image/Processing

dicom ํŒŒ์ผ๋“ค์„ nifti ํŒŒ์ผ๋กœ ๋ฐ”๊ฟ”์ฃผ๋Š” Python library 'dicom2nifti' (+์ผ๋ถ€ dicom ํŒŒ์ผ์ด ์ธ์‹์ด ์•ˆ๋˜๋Š” ๋ฌธ์ œ)

๋ณต๋งŒ 2021. 12. 21. 13:35

ํด๋” ๋‚ด์˜ dicom ํŒŒ์ผ๋“ค์„ nifti ํŒŒ์ผ๋กœ ๋ฐ”๊ฟ”์ฃผ๋Š” ํŒŒ์ด์ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.

https://github.com/icometrix/dicom2nifti

 

GitHub - icometrix/dicom2nifti

Contribute to icometrix/dicom2nifti development by creating an account on GitHub.

github.com

 

 

์ด๋ ‡๊ฒŒ ํŽธ๋ฆฌํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ์—ˆ๋‹ค๋‹ˆ.. ์—ญ์‹œ ํŒŒ์ด์ฌ์€ ์ฐพ์œผ๋ฉด ํŽธ๋ฆฌํ•œ ๊ฒƒ๋“ค์ด ๋„ˆ๋ฌด ๋งŽ๋‹ค

๊ทธ๋™์•ˆ ์ผ์ผ์ด ์ „์ฒ˜๋ฆฌํ–ˆ๋˜๊ฑด ๋จธ๋ฆฌ๊ฐ€ ๋ฉ์ฒญํ•˜๋ฉด ์†์ด ๊ณ ์ƒํ•˜๊ธฐ ๋•Œ๋ฌธ..

 

 


 

Install

conda:

conda install -c conda-forge dicom2nifti

pip:

pip install dicom2nifti

 

 


 

Usage

command line์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ด์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ option๋“ค์€ github์ด๋‚˜ [-h] option ์ฐธ๊ณ .

dicom2nifti dicom_directory output_directory

 

 

ํ˜น์€ Python ๋‚ด๋ถ€์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

import dicom2nifti

dicom2nifti.convert_directory(dicom_directory, output_directory)

 

dicom_directory๋Š” dicom ํŒŒ์ผ๋“ค์ด ๋‹ด๊ฒจ์žˆ๋Š” ๊ฒฝ๋กœ, output_directory๋ฅผ ๋ณ€ํ™˜๋œ nifti ํŒŒ์ผ๋“ค์ด ๋‹ด๊ธธ ๊ฒฝ๋กœ๋กœ ์ง€์ •ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

 

 


 

Example

์‹คํ–‰ ์ฝ”๋“œ :

import dicom2nifti

dicom_directory = './Data/1_01_P'
output_directory = './Data/nifti/1_01_P'
os.makedirs(output_directory, exist_ok=True)

dicom2nifti.convert_directory(dicom_directory, output_directory)

382๊ฐœ์˜ dicom ํŒŒ์ผ๋“ค์ด 3๊ฐœ์˜ nifti ํŒŒ์ผ๋กœ ์ •๋ฆฌ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

 

 


 

(์ฐธ๊ณ ) ์ผ๋ถ€ dicom ํŒŒ์ผ์ด ์ธ์‹์ด ์•ˆ๋˜๋Š” ๋ฌธ์ œ

 

์ฐธ๊ณ ๋กœ ์—๋Ÿฌ log๋ฅผ ๋ณด๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ๋Š” logging level์„ INFO๋กœ ๋‚ฎ์ถฐ์ฃผ๋ฉด ์–ด๋–ค file์—์„œ ์–ด๋–ค ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๋Š”์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

import logging
logging.basicConfig(level=logging.INFO)

 

CASE1. dicom ํŒŒ์ผ์˜ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ์—์„œ failํ•œ ๊ฒฝ์šฐ

 

๋‚˜๋Š” ์‚ฌ์šฉํ•˜๋‹ค๊ฐ€ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธด ์ง€์ ์ด, ์ด 4๊ฐœ์˜ nii ํŒŒ์ผ์ด ์ƒ์„ฑ๋˜์–ด์•ผ ํ•˜๋Š”๋ฐ, 3๊ฐœ๋งŒ ์ƒ์„ฑ์ด ๋˜์—ˆ๋‹ค..

๋ญ๊ฐ€ ๋ฌธ์ œ์ธ๊ฐ€ ์‹ถ์–ด ์‚ดํŽด๋ณด๋‹ˆ ์ฝ”๋“œ ์ค‘์— ์œ ํšจํ•œ dicom image ํŒŒ์ผ์ธ์ง€ ๊ฒ€์‚ฌํ•˜๋Š” ๋ถ€๋ถ„์ด ์žˆ์—ˆ๋‹ค.

 

...

dicom2nifti/convert_dir/_is_valid_imaging_dicom

 

์œ„์™€ ๊ฐ™์ด dicom header์— ๋ช‡ ๊ฐ€์ง€ attribute๋“ค์ด ์žˆ๋Š”์ง€ ๊ฒ€์‚ฌํ•˜์—ฌ ์œ ํšจ์„ฑ์„ ๊ฒ€์ฆํ•˜๋Š” ๊ณผ์ •์„ ๊ฑฐ์น˜๋Š”๋ฐ,

๋‚˜์˜ ๊ฒฝ์šฐ ํ•˜๋‚˜์˜ InstanceNumber์ด ๋น ์ ธ ์žˆ๋Š” series๊ฐ€ ์žˆ์–ด ๋ฐ”๋กœ ๊ฑด๋„ˆ๋›ฐ์–ด๋ฒ„๋ ธ๋˜ ๊ฒƒ์ด๋‹ค..

 

๊ฒฐ๊ตญ ํ•ด๋‹น series์˜ dicom header์— InstanceNumber์„ ๋ชจ๋‘ ์ถ”๊ฐ€ํ•ด ์คŒ์œผ๋กœ์จ ํ•ด๊ฒฐํ–ˆ๋‹ค.

dicom viewer์—์„œ๋Š” InstanceNumber์ด ์—†์–ด๋„ ์ž˜ ์ฝ๋˜๋ฐ ์ด๋ถ€๋ถ„์€ ์—…๋ฐ์ดํŠธ๊ฐ€ ๋˜์—ˆ์œผ๋ฉด.. ๐Ÿ˜ 

(๋ช‡์‹œ๊ฐ„ ์‚ฝ์งˆํ•ด์„œ ์ŠฌํŽ๋‹ค)

 

 

CASE2. SLICE_INCREMENT_INCONSISTENT error๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ

 

SLICE_INCREMENT_INCONSISTENT error๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉฐ ํ•ด๋‹น Series๋ฅผ ๊ฑด๋„ˆ๋›ฐ๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. ์ด๋Š” slice ๊ฐ„์˜ ๊ฐ„๊ฒฉ์ด ์ผ์ •ํ•˜์ง€ ์•Š์„ ๋•Œ ๋ฐœ์ƒ๋˜๋Š” ์˜ค๋ฅ˜์ด๋‹ค.

 

dicom2nifti/common/validate_slice_increment

 

์ด error์„ ๋ฌด์‹œํ•˜๊ณ  convertํ•˜๊ณ  ์‹ถ์œผ๋ฉด setting์—์„œ slice increment๋ฅผ ๊ฒ€์‚ฌํ•˜์ง€ ์•Š๋„๋ก ํ•  ์ˆ˜ ์žˆ๋‹ค.

์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด setting์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. (์ถœ์ฒ˜-https://github.com/icometrix/dicom2nifti/issues/36)

import dicom2nifti.settings as settings
settings.disable_validate_slice_increment()

 

 

๋ฐ˜์‘ํ˜•