예제 #1
0
파일: image.py 프로젝트: darcymason/pylinac
    def load_multiples(cls, image_file_list, method='mean', stretch=True):
        """Combine multiple image files into one superimposed image.

        .. versionadded:: 0.5.1
        """
        # load images
        img_list = [cls.load(path) for path in image_file_list]
        first_img = img_list[0]

        # check that all images are the same size and stretch if need be
        for img in img_list:
            if img.shape != first_img.shape:
                raise ValueError("Images were not the same shape")
            if stretch:
                img.array = stretcharray(img.array)

        # stack and combine arrays
        new_array = np.dstack(tuple(img.array for img in img_list))
        if method == 'mean':
            combined_arr = np.mean(new_array, axis=2)
        elif method == 'max':
            combined_arr = np.max(new_array, axis=2)
        elif method == 'sum':
            combined_arr = np.sum(new_array, axis=2)

        # replace array of first object and return
        first_img.array = combined_arr
        first_img.check_inversion()
        return first_img
예제 #2
0
    def load_multiples(cls, image_file_list, method='mean', stretch=True):
        """Combine multiple image files into one superimposed image.

        .. versionadded:: 0.5.1
        """
        # load images
        img_list = [cls.load(path) for path in image_file_list]
        first_img = img_list[0]

        # check that all images are the same size and stretch if need be
        for img in img_list:
            if img.shape != first_img.shape:
                raise ValueError("Images were not the same shape")
            if stretch:
                img.array = stretcharray(img.array)

        # stack and combine arrays
        new_array = np.dstack(tuple(img.array for img in img_list))
        if method == 'mean':
            combined_arr = np.mean(new_array, axis=2)
        elif method == 'max':
            combined_arr = np.max(new_array, axis=2)
        elif method == 'sum':
            combined_arr = np.sum(new_array, axis=2)

        # replace array of first object and return
        first_img.array = combined_arr
        first_img.check_inversion()
        return first_img
예제 #3
0
    def from_multiples(cls, image_file_list, method='mean', stretch=True):
        """Combine multiple image files into one superimposed image.

        .. versionadded:: 0.5.1
        """
        # open first one to get initial settings
        init_obj = cls(image_file_list[0])
        # init_obj.check_inversion()
        if stretch:
            array = stretcharray(init_obj.array)
        else:
            array = init_obj.array
        concat_arr = array
        initial_shape = init_obj.shape

        # open each image and append each array
        for img_file in image_file_list[1:]:
            obj = cls(img_file)
            if obj.shape != initial_shape:
                raise AttributeError("Images must be the same size when combining.")
            # obj.check_inversion()
            if stretch:
                obj.array = stretcharray(obj.array)
            concat_arr = np.dstack((concat_arr, obj.array))

        # create new array
        if method == 'mean':
            combined_arr = np.mean(concat_arr, axis=2)
        elif method == 'max':
            combined_arr = np.max(concat_arr, axis=2)
        elif method == 'sum':
            combined_arr = np.sum(concat_arr, axis=2)
        # use the initial Image object and replace its array, thus keeping all the other properties
        init_obj.array = combined_arr
        init_obj.check_inversion()
        return init_obj