Dicom voi lut preprocessing

From wenmin-wu/ds-skills · View interactive version

Dicom voi lut preprocessing is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Read DICOM X-ray files with VOI LUT transformation and MONOCHROME1 inversion for correct pixel intensity rendering

How to use this skill

Skill file

DICOM VOI LUT Preprocessing

Overview

X-ray DICOM files use Value of Interest (VOI) Lookup Tables to map stored pixel values to display-ready intensities. Some scanners store images as MONOCHROME1 (inverted — bright=air, dark=tissue), which must be flipped. Apply VOI LUT first, then fix photometric interpretation, then normalize to 0-255.

Quick Start

import numpy as np
import pydicom
from pydicom.pixel_data_handlers.util import apply_voi_lut

def read_xray(path, voi_lut=True, fix_monochrome=True):
    """Read and preprocess a DICOM X-ray image.
    
    Args:
        path: path to .dcm file
        voi_lut: apply VOI LUT transform (recommended)
        fix_monochrome: invert MONOCHROME1 images
    Returns:
        uint8 image array (0-255)
    """
    dicom = pydicom.dcmread(path)
    if voi_lut:
        data = apply_voi_lut(dicom.pixel_array, dicom)
    else:
        data = dicom.pixel_array
    if fix_monochrome and dicom.PhotometricInterpretation == "MONOCHROME1":
        data = np.amax(data) - data
    data = data - np.min(data)
    data = data / np.max(data)
    data = (data * 255).astype(np.uint8)
    return data

img = read_xray("patient001.dcm")

Key Decisions

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.