DICOM – Two Images into one DICOM File

I need some tips on how to create a DICOM file from two images. I already have a Python script with which I can create a DICOM from a 3D voxel. Now I want to add a color histogram (file format .tif) to the same DICOM. What options do I have to implement this? The 3D stack should not be overwritten, but I still want to be able to select the histogram in just one DICOM container. I would appreciate any kind of help 🙂

I have already found a way to create a valid DICOM from a .vox and now I want to add an RGB TIF image to it.

This is my code to generate a DICOM from a Vox


import matplotlib.pyplot as plt
import os
import datetime
import numpy as np
import pydicom.encaps
from PIL import Image
from pydicom.dataset import FileMetaDataset, Dataset,FileDataset
from pydicom.uid import ExplicitVRLittleEndian
from pydicom.uid import UID

def loadVOX(fname):
    vol=[]
    try:
        f=open(fname,"rb")
        size=os.path.getsize(fname)
        f.seek(size-512*512*512*2)
        vol=np.reshape(np.frombuffer(f.read(512*512*512*2),dtype='ushort'),(512,512,512),order='F').swapaxes(0,1)
    finally:
        f.close()
    return vol


image_array =loadVOX("C:/Users/robin/Downloads/CT_20231116_111921.VOX")

# Umstellen des Arrays damit z nach oben zeigt
image_array  = np.swapaxes(image_array, 0, 2)
plt.imshow(image_array[215])

#Konvertierung in 8 bit
min_val = np.min(image_array)
max_val = np.max(image_array)
normalized_data = (image_array - min_val) / (max_val - min_val)
scaled_data = (normalized_data * 255).astype(np.uint8)


# das b'' ist ein Bytes Literal --> ein leeres Objekt das 8 bit objekte halten kann. b steht für byte so wie f für float stehen würde. '' ist eine leere Variable in Python.
# Wieder was gelernt. 
# Join erlaubt eine Verkettung der einzelnen Frames hintereinander, so kommen die dann in 512 Schritten zum Schluss raus
multi_frame_pixel_data = b''.join(frame.tobytes() for frame in scaled_data ) 
# Create a FileDataset (subclass of Dataset) to hold the DICOM data
ds = FileDataset("example.dcm", {}, preamble=b"" * 128)

# DICOM Tags die ich durch Try and Error rausbekommen habe
ds.PatientName = "John Doe"
ds.PatientID = "12345"
ds.StudyDescription = "Example Study"
ds.SeriesDescription = "Example Series"
ds.Modality = "CT"
ds.Rows = image_array.shape[0]
ds.Columns = image_array.shape[1]
ds.NumberOfFrames = len(image_array)
print(ds.Rows,ds.Columns,ds.NumberOfFrames)
ds.ImagePositionPatient = r"01"
ds.ImageOrientationPatient = r"011"
ds.PixelSpacing = r"11"
ds.BitsAllocated = 8 # Jetzt hier 8, da ich oben konvertiert hatte
ds.BitsStored = 8
ds.HighBit = 7
ds.PixelRepresentation = 0
ds.SamplesPerPixel = 1
ds.PhotometricInterpretation = "MONOCHROME2"

#Speichern
ds.PixelData = multi_frame_pixel_data
ds.file_meta.TransferSyntaxUID =  pydicom.uid.ImplicitVRLittleEndian
ds.save_as("test.dcm")

dataset = pydicom.dcmread('test.dcm')
frame_generator = pydicom.encaps.generate_pixel_data_frame(dataset.PixelData)

if 'PixelData' in dataset:
    rows = int(dataset.Rows)
    cols = int(dataset.Columns)
    print("Image size.......: {rows:d} x {cols:d}, {size:d} bytes".format(
        rows=rows, cols=cols, size=len(dataset.PixelData)))
    if 'PixelSpacing' in dataset:
        print("Pixel spacing....:", dataset.PixelSpacing)

plt.imshow(dataset.pixel_array[215])
plt.show()
print(dataset.pixel_array.shape)

New contributor

Robin Scheel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật