lama/common.py
def average(img_paths: List[Path]) -> sitk.Image:
    """
    Make a mean itensity volume given a list of volume paths

    Returns
    -------
    Mean volume

    """
    img_paths = list(map(str, img_paths))

    # sum all images together
    first = LoadImage(img_paths[0])

    # Get the direction from the first image.
    direction_cos = first.direction

    summed = sitk.GetArrayFromImage(sitk.ReadImage(img_paths[0]))

    for image in img_paths[1:]:  # Ommit the first as that is in 'summed'
        np_array = sitk.GetArrayFromImage(sitk.ReadImage(image))
        try:
            summed += np_array
        except ValueError as e:
            print(("Numpy can't average this volume {0}".format(image)))

    # Now make average
    summed //= len(img_paths)
    avg_img = sitk.GetImageFromArray(summed)
    avg_img.SetDirection(direction_cos)

    return avg_img

    Make a mean itensity volume given a list of volume paths

    Returns
    -------
    Mean volume

    
Make a mean itensity volume given a list of volume paths
Returns

Mean volume
Make a mean itensity volume given a list of volume paths Returns Mean volume
def average(img_paths: List[Path]) -> sitk.Image:
    img_paths = list(map(str, img_paths))
    first = LoadImage(img_paths[0])
    direction_cos = first.direction
    summed = sitk.GetArrayFromImage(sitk.ReadImage(img_paths[0]))
    for image in img_paths[1:]:  
        np_array = sitk.GetArrayFromImage(sitk.ReadImage(image))
        try:
            summed += np_array
        except ValueError as e:
            print(("Numpy can't average this volume {0}".format(image)))
    summed //= len(img_paths)
    avg_img = sitk.GetImageFromArray(summed)
    avg_img.SetDirection(direction_cos)
    return avg_img
def average ( img_paths : List [ Path ] ) -> sitk . Image : img_paths = list ( map ( str , img_paths ) ) first = LoadImage ( img_paths [ 0 ] ) direction_cos = first . direction summed = sitk . GetArrayFromImage ( sitk . ReadImage ( img_paths [ 0 ] ) ) for image in img_paths [ 1 : ] : np_array = sitk . GetArrayFromImage ( sitk . ReadImage ( image ) ) try : summed += np_array except ValueError as e : print ( ( "Numpy can't average this volume {0}" . format ( image ) ) ) summed //= len ( img_paths ) avg_img = sitk . GetImageFromArray ( summed ) avg_img . SetDirection ( direction_cos ) return avg_img
Make a mean itensity volume given a list of volume paths
Returns
Make a mean itensity volume given a list of volume paths Returns
"""
    Make a mean itensity volume given a list of volume paths

    Returns
    -------
    Mean volume

    """ # sum all images together # Get the direction from the first image. # Ommit the first as that is in 'summed' # Now make average
img_paths
List[Path]