심장 초음파 결과가 Orthanc에 없다보니 결과 처리할 때 항상 따로 해주어야 하는 불편함이 있었다. 그렇다고 심장 초음파 이미지를 DICOM 서버로 등록시켜봐야 심장 초음파 결과지 내용을 볼 수 있는 것도 아니고, 이미지 1장당 18메가 정도 하는데 이것이 수십장 씩 있다 보니 경제적이지도 않다. 그래서 현재 필요한 것은 EF 뿐이니 이것을 분석에 사용하지 않는 DICOM tag로 입력시키고, 저해상도 이미지 파일을 등록시키는 식으로 하기로 했다.
Downsize MRI image using pydicom — pydicom 2.4.0dev0 documentation
This example shows how to downsize an MR image from to
. The downsizing is performed by taking the central section
instead of averagin the pixels. Finally, the image is store as a dicom image.
# authors : Guillaume Lemaitre <g.lemaitre58@gmail.com>
# license : MIT
import pydicom
from pydicom.data import get_testdata_file
print(__doc__)
# FIXME: add a full-sized MR image in the testing data
filename = get_testdata_file('MR_small.dcm')
ds = pydicom.dcmread(filename)
# get the pixel information into a numpy array
data = ds.pixel_array
print('The image has {} x {} voxels'.format(data.shape[0],
data.shape[1]))
data_downsampling = data[::8, ::8]
print('The downsampled image has {} x {} voxels'.format(
data_downsampling.shape[0], data_downsampling.shape[1]))
# copy the data back to the original data set
ds.PixelData = data_downsampling.tobytes()
# update the information regarding the shape of the data array
ds.Rows, ds.Columns = data_downsampling.shape
# print the image information given in the dataset
print('The information of the data set after downsampling: \n')
print(ds)
downsampling 부분을 보면 이미지 파일에서 일정 간격으로 (여기서는 1/8로 줄이기 위하여) 값들을 선택하여 크기 자체를 줄이고 .tobytes 를 이용해서 변환하는 것을 볼 수 있다. 그래서 그렇게 했다. 난 용량이 작은 것이 필요하니 :8대신에 :200으로 했다.
ds = pydicom.dcmread('/root/US_ECHO_TEMPLATE.dcm')
data = ds.pixel_array
data_downsampling = data[:,::200, ::200,:]
ds.PixelData = data_downsampling.tobytes()
_, ds.Rows, ds.Columns,_ = data_downsampling.shape
...
ds.save_as("/tmp/RAW/echo_new.dcm")
os.system("storescu rcc02.work 4242 /tmp/RAW/echo_new.dcm")