Skip to content

window_volume

Applies a window function (clipping) to an input itk volume, outputs windowed volume

Parameters:

Name Type Description Default
input_itk_volume str

path to itk compatible image volume (.mhd, .nrrd, .nii, etc.)

required
output_dir str

output/working directory

required
low_level float

lower bound of clipping operation

required
high_level float

higher bound of clipping operation

required

Returns:

Name Type Description
dict

metadata about function call

Source code in src/luna/radiology/cli/window_volume.py
def window_volume(
    input_itk_volume: str, output_dir: str, low_level: float, high_level: float
):
    """Applies a window function (clipping) to an input itk volume, outputs windowed volume

    Args:
        input_itk_volume (str): path to itk compatible image volume (.mhd, .nrrd, .nii, etc.)
        output_dir (str): output/working directory
        low_level (float): lower bound of clipping operation
        high_level (float): higher bound of clipping operation

    Returns:
        dict: metadata about function call
    """
    file_stem = Path(input_itk_volume).stem
    file_ext = Path(input_itk_volume).suffix

    outFileName = os.path.join(output_dir, file_stem + ".windowed" + file_ext)

    logger.info("Applying window [%s,%s]", low_level, high_level)

    image, header = medpy.io.load(input_itk_volume)
    image = np.clip(image, low_level, high_level)
    medpy.io.save(image, outFileName, header)
    # Prepare metadata and commit
    properties = {
        "itk_volume": outFileName,
    }

    return properties