dicom_windows = types.SimpleNamespace(
    abdomen_soft=(400,50),
    brain=(80,40),
    brain_bone=(2800,600),
    brain_soft=(375,40),
    liver=(150,30),
    lungs=(1500,-600),
    mediastinum=(350,50),
    pe=(40,400),
    spine_soft=(250,50),
    spine_bone=(1800,400),
    subdural=(254,100),
    stroke=(8,32)
)

I = (32-bit signed integer pixels) F = (32-bit floating point pixels) L = (8-bit pixels, black and white)

class PILWindow(PILBase):
    "Specify windows for use with DataBlocks"
    _open_args,_tensor_cls,_show_args = {},TensorDicom,TensorDicom._show_args
    @classmethod
    def create(cls, fn:(Path,str,bytes), mode=None, window=dicom_windows.lungs, **kwargs)->None:
        if isinstance(fn,bytes): im = pydicom.dcmread(pydicom.filebase.DicomBytesIO(fn))
        if isinstance(fn,(Path,str)): im = dcmread(fn)
            
        if window is not None:
            scaled = np.array(im.windowed(*window).numpy())*4294967296 #*2**16-1
        else:
            scaled = np.array(scaled_px(im))
        scaled = scaled.astype(np.int32)
        return cls(Image.fromarray(scaled))

class PILWindow[source]

PILWindow() :: PILBase

Specify windows for use with DataBlocks

class LungWindow(PILBase):
    _open_args,_tensor_cls,_show_args = {},TensorDicom,TensorDicom._show_args
    @classmethod
    def create(cls, fn:(Path,str,bytes), mode=None)->None:
        if isinstance(fn,bytes): im = pydicom.dcmread(pydicom.filebase.DicomBytesIO(fn))
        if isinstance(fn,(Path,str)): im = dcmread(fn)
        scaled = np.array(im.windowed(l=-600, w=1500).numpy())*255
        scaled = scaled.astype(np.uint8)
        return cls(Image.fromarray(scaled))

class LungWindow[source]

LungWindow() :: PILBase

This class represents an image object. To create :py:class:~PIL.Image.Image objects, use the appropriate factory functions. There's hardly ever any reason to call the Image constructor directly.

  • :py:func:~PIL.Image.open
  • :py:func:~PIL.Image.new
  • :py:func:~PIL.Image.frombytes
class PEWindow(PILBase):
    _open_args,_tensor_cls,_show_args = {},TensorDicom,TensorDicom._show_args
    @classmethod
    def create(cls, fn:(Path,str,bytes), mode=None)->None:
        if isinstance(fn,bytes): im = pydicom.dcmread(pydicom.filebase.DicomBytesIO(fn))
        if isinstance(fn,(Path,str)): im = dcmread(fn)
        scaled = np.array(im.windowed(l=40, w=400).numpy())*255
        scaled = scaled.astype(np.uint8)
        return cls(Image.fromarray(scaled))

class PEWindow[source]

PEWindow() :: PILBase

This class represents an image object. To create :py:class:~PIL.Image.Image objects, use the appropriate factory functions. There's hardly ever any reason to call the Image constructor directly.

  • :py:func:~PIL.Image.open
  • :py:func:~PIL.Image.new
  • :py:func:~PIL.Image.frombytes