DICOM in DEEP LEARING

You have to extract the image from the DICOM file as that is what is most important, the DICOM file contains both the image from the CT scan and other metadata which you won’t be needing. I already have some code for it. Just create a folder with the data and the program will pop open a GUI for you to pick a file. This program will return the folder with images as a numpy array containing the data which can then be passed to whatever model you need. Scaled and formatted.

import tkinter as tk
from tkinter import filedialog ## FILE PICKER GUI
from skimage import io, transform, exposure
import os
import numpy as np
import pydicom ## VERY HELPFUL LIBRARY TO DEAL WITH DICOM FILES
from PIL import Image ## WORKING WITH IMAGES

def load_images_from_folder(folder):
images = [ ]
for filename in os.listdir(folder):
file_path = os.path.join(folder, filename)
if filename.lower().endswith(‘.dcm’):
dicom = pydicom.dcmread(‘file_path’)
img_array = dicom.pixel_array
if img_array.dtype != np.uint8:
img_array = exposure.rescale_intensity(img_array, out_range=‘uint8’)
else:
img = io.imread(file_path, as_gray=True)
if img.dtype != np.uint8:
img = (img * 255).astype(‘uint8’)
img = Image.fromarray(img)
img = img.convert(‘L’) if img.mode != ‘L’ else img
img = np.array(img)
img = transform.resize(img, (100, 100), anti_aliasing=True) #RESIZE IMG
images.append(img)
return np.array(images)

root = tk.Tk()
root.withdraw()
file_path = filedialog.askdirectory()
images = load_images_from_folder(file_path) ### PASS FOLDER WITH DATA

Thanks

Thanks,understood