47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
|
# ev-to-dicom
|
||
|
# Copyright © 2023 Lee Yingtong Li
|
||
|
#
|
||
|
# This program is free software: you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU Affero General Public License as published by
|
||
|
# the Free Software Foundation, either version 3 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU Affero General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU Affero General Public License
|
||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
|
||
|
import os
|
||
|
import sys
|
||
|
|
||
|
from .ev_to_dcm import ev_files_to_dcm_file
|
||
|
|
||
|
if len(sys.argv) < 2:
|
||
|
print('Usage: {} [output directory]'.format(sys.argv[0]))
|
||
|
sys.exit(0)
|
||
|
|
||
|
outdir = sys.argv[1]
|
||
|
if not os.path.exists(outdir):
|
||
|
print('Output directory does not exist')
|
||
|
sys.exit(1)
|
||
|
|
||
|
# Get series data
|
||
|
|
||
|
series_number = int(os.path.split(os.getcwd())[1].split('_')[0]) + 1
|
||
|
series_uid = os.path.split(os.getcwd())[1].split('_')[1]
|
||
|
study_uid = os.path.split(os.path.split(os.getcwd())[0])[1]
|
||
|
|
||
|
# Convert images
|
||
|
|
||
|
for filename in os.listdir('.'):
|
||
|
if filename.endswith('.bin'):
|
||
|
print(filename)
|
||
|
|
||
|
image_number = int(filename.split('_')[0]) + 1
|
||
|
output_filename = '{:04d}_{:04d}.dcm'.format(series_number - 1, image_number - 1)
|
||
|
|
||
|
ev_files_to_dcm_file(study_uid, series_uid, series_number, image_number, [filename], os.path.join(outdir, output_filename))
|