I have saved the Preprocessed DICOM in a folder total of 300 .dcm files, but when I open this DICOM folder path in RadiANT DICOM Viewer only One slice is displayed, here is my code is attached, Can you please help me how to display the whole scan. I think the main problem in Image Position and Slice location
import os
import numpy as np
import matplotlib.pyplot as plt
import pydicom
from pydicom.encaps import encapsulate
from pydicom.uid import JPEG2000
from imagecodecs import jpeg2k_encode
basepath="/home/hammad/AssementTask/DICOM/"
des_path="/home/hammad/AssementTask/g/"
file_list = [f.path for f in os.scandir(basepath)]
ds = pydicom.dcmread(file_list[0])
for i in range(imgs_after_resamp.shape[0]):
out = imgs_after_resamp[i,:,:]
#Need to copy() to meet jpeg2k_encodes C contiguous requirement
arr_crop = out.copy()
out = out.astype(np.int16)
# jpeg2k_encode to perform JPEG2000 compression
arr_jpeg2k = jpeg2k_encode(arr_crop)
# convert from bytearray to bytes before saving to PixelData
arr_jpeg2k = bytes(arr_jpeg2k)
ds.Rows = arr_crop.shape[0]
ds.Columns = arr_crop.shape[1]
ds[0x0018, 0x0050].value=np.round(spacing[0])
ds[0x0028, 0x0030].value=[np.round(spacing[1]),np.round(spacing[2])]
ds.InstanceNumber = i
ds.PixelData = encapsulate([arr_jpeg2k])
ds.save_as((des_path + str(i) + '.dcm'.format(i)))