Spaces:
Sleeping
Sleeping
File size: 604 Bytes
bfb3c70 54eb2f0 | 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 | import numpy as np
import pydicom
import cv2
def load_dicom_image(path):
ds = pydicom.dcmread(path)
img = ds.pixel_array.astype(np.float32)
return img
def resize_image(img, target_size=(224, 224)):
return cv2.resize(img, target_size, interpolation=cv2.INTER_LINEAR)
def normalize_image(img):
return img / 255.0
def to_3channel(img):
return np.stack([img, img, img], axis=-1)
def preprocess_dicom(path):
img = load_dicom_image(path)
img = resize_image(img)
img = normalize_image(img)
img = to_3channel(img)
img = np.expand_dims(img, axis=0)
return img
|