# Copyright 2022 Cerebras Systems.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Adapted from: https://github.com/MIC-DKFZ/batchgenerators (commit id: 01f225d)
#
# Copyright 2021 Division of Medical Image Computing, German Cancer Research Center (DKFZ)
# and Applied Computer Vision Lab, Helmholtz Imaging Platform
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
from scipy.ndimage.interpolation import zoom
[docs]def nd_resize(
input, new_shape, order=None, clip=None, anti_aliasing=None, mode=None
):
# last 3 inputs not used, only there for easy replacement
shp = input.shape
z = [s1 / s2 for s1, s2 in zip(new_shape, input.shape)]
output = zoom(input, z)
return output
[docs]def rotate_coords_3d(coords, angle_x, angle_y, angle_z):
rot_matrix = np.identity(len(coords))
rot_matrix = create_matrix_rotation_x_3d(angle_x, rot_matrix)
rot_matrix = create_matrix_rotation_y_3d(angle_y, rot_matrix)
rot_matrix = create_matrix_rotation_z_3d(angle_z, rot_matrix)
coords = (
np.dot(coords.reshape(len(coords), -1).transpose(), rot_matrix)
.transpose()
.reshape(coords.shape)
)
return coords
[docs]def rotate_coords_2d(coords, angle):
rot_matrix = create_matrix_rotation_2d(angle)
coords = (
np.dot(coords.reshape(len(coords), -1).transpose(), rot_matrix)
.transpose()
.reshape(coords.shape)
)
return coords