diff --git a/scala/dllib/src/main/scala/com/intel/analytics/bigdl/dllib/feature/image/ImageMirror.scala b/scala/dllib/src/main/scala/com/intel/analytics/bigdl/dllib/feature/image/ImageMirror.scala new file mode 100644 index 00000000000..6cb7da56528 --- /dev/null +++ b/scala/dllib/src/main/scala/com/intel/analytics/bigdl/dllib/feature/image/ImageMirror.scala @@ -0,0 +1,53 @@ +/* + * 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. + */ +package com.intel.analytics.zoo.feature.image + +import com.intel.analytics.bigdl.transform.vision.image.opencv.OpenCVMat +import com.intel.analytics.bigdl.transform.vision.image.{FeatureTransformer, ImageFeature} +import org.opencv.core.Core + +/** + * Flip the image horizontally and vertically + */ +class Mirror() extends FeatureTransformer { + override def transformMat(feature: ImageFeature): Unit = { + Mirror.transform(feature.opencvMat(), feature.opencvMat()) + } +} + +object Mirror { + def apply(): Mirror = new Mirror() + + def transform(input: OpenCVMat, output: OpenCVMat): OpenCVMat = { + Core.flip(input, output, -1) + output + } +} + +/** + * Flip the image horizontally and vertically + */ +class ImageMirror() extends ImageProcessing { + private val internalCrop = new Mirror + + override def apply(prev: Iterator[ImageFeature]): Iterator[ImageFeature] = { + internalCrop.apply(prev) + } +} + +object ImageMirror { + def apply(): ImageMirror = new ImageMirror() +} diff --git a/scala/dllib/src/main/scala/com/intel/analytics/bigdl/dllib/feature/python/PythonFeatureSet.scala b/scala/dllib/src/main/scala/com/intel/analytics/bigdl/dllib/feature/python/PythonFeatureSet.scala index b8832980505..e4e0cf9b6c8 100644 --- a/scala/dllib/src/main/scala/com/intel/analytics/bigdl/dllib/feature/python/PythonFeatureSet.scala +++ b/scala/dllib/src/main/scala/com/intel/analytics/bigdl/dllib/feature/python/PythonFeatureSet.scala @@ -17,7 +17,8 @@ package com.intel.analytics.zoo.feature.python import com.intel.analytics.bigdl.DataSet -import com.intel.analytics.bigdl.dataset.Transformer +import com.intel.analytics.bigdl.dataset.{Transformer, Sample => JSample} +import com.intel.analytics.bigdl.python.api.Sample import com.intel.analytics.bigdl.tensor.TensorNumericMath.TensorNumeric import com.intel.analytics.bigdl.transform.vision.image._ import com.intel.analytics.zoo.common.PythonZoo @@ -48,6 +49,11 @@ class PythonFeatureSet[T: ClassTag](implicit ev: TensorNumeric[T]) extends Pytho FeatureSet.rdd(data, MemoryType.fromString(memoryType)) } + def createSampleFeatureSetFromRDD(data: JavaRDD[Sample], memoryType: String) + : FeatureSet[JSample[T]] = { + FeatureSet.rdd(toJSample(data), MemoryType.fromString(memoryType)) + } + def transformFeatureSet(featureSet: FeatureSet[Any], transformer: Transformer[Any, Any]): FeatureSet[Any] = { featureSet -> transformer diff --git a/scala/dllib/src/main/scala/com/intel/analytics/bigdl/dllib/feature/python/PythonImageFeature.scala b/scala/dllib/src/main/scala/com/intel/analytics/bigdl/dllib/feature/python/PythonImageFeature.scala index 3ffb90f2b0d..886c1087cab 100644 --- a/scala/dllib/src/main/scala/com/intel/analytics/bigdl/dllib/feature/python/PythonImageFeature.scala +++ b/scala/dllib/src/main/scala/com/intel/analytics/bigdl/dllib/feature/python/PythonImageFeature.scala @@ -220,6 +220,11 @@ class PythonImageFeature[T: ClassTag](implicit ev: TensorNumeric[T]) extends Pyt ImageBytesToMat(byteKey, imageCodec) } + def createImagePixelBytesToMat( + byteKey: String = ImageFeature.bytes): ImagePixelBytesToMat = { + ImagePixelBytesToMat(byteKey) + } + def createImageBrightness(deltaLow: Double, deltaHigh: Double): ImageBrightness = { ImageBrightness(deltaLow, deltaHigh) } @@ -228,6 +233,10 @@ class PythonImageFeature[T: ClassTag](implicit ev: TensorNumeric[T]) extends Pyt ImageFeatureToTensor() } + def createImageFeatureToSample(): ImageFeatureToSample[T] = { + ImageFeatureToSample() + } + def createImageChannelNormalizer( meanR: Double, meanG: Double, meanB: Double, stdR: Double = 1, stdG: Double = 1, stdB: Double = 1 @@ -347,6 +356,10 @@ class PythonImageFeature[T: ClassTag](implicit ev: TensorNumeric[T]) extends Pyt ImageHFlip() } + def createImageMirror(): ImageMirror = { + ImageMirror() + } + def createImageSetToSample(inputKeys: JList[String], targetKeys: JList[String], sampleKey: String): ImageSetToSample[T] = {