Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 3d medical image
- REINFORCE
- rest-api
- resample
- normalization
- Policy Gradient
- model-free control
- remove outliers
- Excel
- freebooze
- fastapi
- objective functions for machine learning
- Inorder Traversal
- pulloff
- checkitout
- Knowledge Distillation
- 자료구조
- clip intensity values
- thresholding
- straightup
- sample rows
- non parametic softmax
- shadowing
- scowl
- sidleup
- domain adaptation
- Actor-Critic
- loss functions
- MRI
- noise contrast estimation
Archives
- Today
- Total
Let's Run Jinyeah
[Python] Modify DICOM image and save as DICOM 본문
read dicom image
import pydicom as dcm
D_TYPE = 'float32'
ds = dcm.dcmread('filename.dcm')
image = ds.pixel_array.astype(D_TYPE)
save gray-scale image to dicom
import pydicom as dcm
D_TYPE = 'float32'
num_bits = 16
ds = dcm.dcmread('filename.dcm')
image = ds.pixel_array.astype(D_TYPE)
"""
image processing for gray image....
output = gray_image (dtype: float32, pixel_range = [0.0, 1.0])
"""
gray_image = (gray_image * (2 ** num_bits - 1)).astype('uint%d' % num_bits)
ds.PixelData = phase_map.tobytes()
ds.Rows, ds.Columns = phase_map.shape
ds.SamplesPerPixel = 1 # channel
ds.BitsAllocated = num_bits
ds.BitsStored = num_bits
ds.save_as(save_path.dcm)
save rgb image to dicom
import pydicom as dcm
ds = dcm.dcmread('filename.dcm')
num_bits = 8
"""
image processing for color image....
output = color_image
"""
color_image = (color_image * (2 ** num_bits - 1)).astype('uint%d' % num_bits)
ds.PixelData = color_image.tobytes()
ds.Rows, ds.Columns = color_image.shape[:2]
ds.SamplesPerPixel = 3 # channel
ds.PhotometricInterpretation = 'RGB'
ds.BitsAllocated = num_bits
ds.BitsStored = num_bits
ds.save_as(save_path.dcm)
'Programming > Python' 카테고리의 다른 글
Numpy 모음 (0) | 2022.06.17 |
---|---|
[Python] Read/Write csv file (csv, Pandas) (0) | 2022.05.25 |
[Python] 가상환경 생성 및 활성화 (0) | 2022.05.17 |
[Python] List method (0) | 2021.10.19 |
[Python] List - Negative Slicing (0) | 2021.01.25 |
Comments