Skip to content

xray

xvr.io.xray

read_xray

read_xray(
    filename: Path,
    crop: int = 0,
    subtract_background: bool = False,
    linearize: bool = True,
    reducefn: str | int | Callable = "max",
)

Read and preprocess an X-ray image from a DICOM file. Returns the pixel array and imaging system intrinsics.

Path

Path to the DICOM file.

crop : int, optional Number of pixels to crop from each edge of the image. subtract_background : bool, optional Subtract the mode image intensity from the image. linearize : bool, optional Convert the X-ray image from exponential to linear form. reducefn : If DICOM is multiframe, how to extract a single 2D image for registration.

Source code in src/xvr/io/xray.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def read_xray(
    filename: Path,
    crop: int = 0,
    subtract_background: bool = False,
    linearize: bool = True,
    reducefn: str | int | Callable = "max",
):
    """
    Read and preprocess an X-ray image from a DICOM file. Returns the pixel array and imaging system intrinsics.

    filename : Path
        Path to the DICOM file.
    crop : int, optional
        Number of pixels to crop from each edge of the image.
    subtract_background : bool, optional
        Subtract the mode image intensity from the image.
    linearize : bool, optional
        Convert the X-ray image from exponential to linear form.
    reducefn :
        If DICOM is multiframe, how to extract a single 2D image for registration.
    """

    # Get the image and imaging system intrinsics
    img, sdd, delx, dely, x0, y0, pf_to_af = _parse_dicom(filename)

    # Preprocess the X-ray image
    img = _preprocess_xray(img, crop, subtract_background, linearize, reducefn)

    return img, sdd, delx, dely, x0, y0, pf_to_af