From f9676c4dc249756577794e8130b71c3843281614 Mon Sep 17 00:00:00 2001 From: Tamino Huxohl <thuxohl@techfak.uni-bielefeld.de> Date: Thu, 19 Jan 2023 11:33:48 +0100 Subject: [PATCH] update join image function to automatically generate separator images --- mu_map/vis/slices.py | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/mu_map/vis/slices.py b/mu_map/vis/slices.py index a4fc04c..fb7fe0e 100644 --- a/mu_map/vis/slices.py +++ b/mu_map/vis/slices.py @@ -1,26 +1,44 @@ -from typing import List +from typing import List, Optional import numpy as np from mu_map.dataset.util import align_images -from mu_map.file.dicom import load_dcm_img -from mu_map.file.interfile import load_interfile_img from mu_map.file.util import load_img def join_images( - images: List[np.ndarray], separator: np.ndarray, vertical: bool = False -) -> List[np.ndarray]: + images: List[np.ndarray], + separator: Optional[np.ndarray] = None, + vertical: bool = False, +) -> np.ndarray: """ Create a new image by joining all input images along a separator image. If joining horizontally, their shape must be equal along their first axis. If joining vertically, their shape must be equal along their second axis. - :param images: a list of images to join - :param separator: a separator image inserted between all images - :param vertical: join images vertically instead of horizontally - :return: a new image joined as described above + Parameters + ---------- + images: list of np.ndarray + a list of images to join + separator: np.ndarray, optional + a separator image inserted between all images - if None a default separator + with a width of 10 pixels is created + vertical: bool + join images vertically instead of horizontally + + Returns + ------- + np.ndarray + a new image joined as described above """ + if separator is None: + shape = ( + (10, *images[0].shape[1:]) + if vertical + else (images[0].shape[0], 10, *images[0].shape[2:]) + ) + separator = np.full(shape, 239, np.uint8) + res = [] for image in images: res += [image, separator] -- GitLab