#
# Copyright 2018 Analytics Zoo Authors.
#
# 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 sys
import numpy as np
from bigdl.util.common import *
from zoo.feature.image.imagePreprocessing import *
from zoo.feature.image.imageset import *
if sys.version >= '3':
long = int
unicode = str
[docs]class ImagePreprocessing3D(ImagePreprocessing):
"""
ImagePreprocessing3D is a transformer that transform ImageFeature for 3D image
"""
def __init__(self, bigdl_type="float", *args):
super(ImagePreprocessing3D, self).__init__(bigdl_type, *args)
[docs]class Crop3D(ImagePreprocessing3D):
"""
Crop a patch from a 3D image from 'start' of patch size.
The patch size should be less than the image size.
:param start start point list[depth, height, width] for cropping
:param patchSize patch size list[depth, height, width]
"""
def __init__(self, start, patch_size, bigdl_type="float"):
super(Crop3D, self).__init__(bigdl_type, start, patch_size)
[docs]class RandomCrop3D(ImagePreprocessing3D):
"""
Random crop a `cropDepth` x `cropHeight` x `cropWidth` patch from an image.
The patch size should be less than the image size.
:param crop_depth depth after crop
:param crop_height height after crop
:param crop_width width after crop
"""
def __init__(self, crop_depth, crop_height, crop_width, bigdl_type="float"):
super(RandomCrop3D, self).__init__(bigdl_type, crop_depth, crop_height, crop_width)
[docs]class CenterCrop3D(ImagePreprocessing3D):
"""
Center crop a `cropDepth` x `cropHeight` x `cropWidth` patch from an image.
The patch size should be less than the image size.
:param crop_depth depth after crop
:param crop_height height after crop
:param crop_width width after crop
"""
def __init__(self, crop_depth, crop_height, crop_width, bigdl_type="float"):
super(CenterCrop3D, self).__init__(bigdl_type, crop_depth, crop_height, crop_width)
[docs]class Rotate3D(ImagePreprocessing3D):
"""
Rotate a 3D image with specified angles.
:param rotation_angles the angles for rotation.
Which are the yaw(a counterclockwise rotation angle about the z-axis),
pitch(a counterclockwise rotation angle about the y-axis),
and roll(a counterclockwise rotation angle about the x-axis).
"""
def __init__(self, rotation_angles, bigdl_type="float"):
super(Rotate3D, self).__init__(bigdl_type, rotation_angles)