Commit 199e212d authored by steffen.schotthoefer's avatar steffen.schotthoefer
Browse files

dicom support with adjusted greyscale

parent b01e9532
Pipeline #93619 failed with stages
in 25 minutes and 11 seconds
# importing PIL
from PIL import Image
import pydicom
import numpy as np
from pydicom.pixel_data_handlers.util import apply_modality_lut
def extract(image_name):
img = Image.open(image_name).convert('L') #image data
I = np.asarray(img) # image as greyscale
I = I/255; # rescale values to [0,1]
dimensions = (1,1) # [cm]
return I , dimensions
\ No newline at end of file
ending = image_name.split('.')[-1];
if(ending == 'dcm'): #dicom ct image
dataset = pydicom.dcmread(image_name)
hu = apply_modality_lut(dataset.pixel_array, dataset)
density = (dataset.RescaleIntercept + dataset.RescaleSlope*hu)/1000 +1
(spacingX, spacingY) = dataset.PixelSpacing
(sizeX,sizeY) = density.shape
dimensions = (spacingX*sizeX, spacingY*sizeY)
return density, dimensions
else: # jpg or png
img = Image.open(image_name).convert('L') #image data
I = np.asarray(img) # image as greyscale
I = I/255; # rescale values to [0,1]
dimensions = (1,1) # [cm]
return I , dimensions
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment