From 0f6e376bc5c1c0db7f4547cd759fd0e396790e15 Mon Sep 17 00:00:00 2001 From: Qing Date: Wed, 30 Jan 2019 13:25:24 -0800 Subject: [PATCH] add simplified methods --- .../org/apache/mxnet/javaapi/Image.scala | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/scala-package/core/src/main/scala/org/apache/mxnet/javaapi/Image.scala b/scala-package/core/src/main/scala/org/apache/mxnet/javaapi/Image.scala index c469b01b7ea5..7d6f31e930ad 100644 --- a/scala-package/core/src/main/scala/org/apache/mxnet/javaapi/Image.scala +++ b/scala-package/core/src/main/scala/org/apache/mxnet/javaapi/Image.scala @@ -35,15 +35,26 @@ object Image { org.apache.mxnet.Image.imDecode(buf, flag, toRGB, None) } + def imDecode(buf: Array[Byte]): NDArray = { + imDecode(buf, 1, true) + } + /** * Same imageDecode with InputStream + * * @param inputStream the inputStream of the image + * @param flag Convert decoded image to grayscale (0) or color (1). + * @param toRGB Whether to convert decoded image * @return NDArray in HWC format with DType [[DType.UInt8]] */ - def imDecode(inputStream: InputStream, flag: Int = 1, toRGB: Boolean = true): NDArray = { + def imDecode(inputStream: InputStream, flag: Int, toRGB: Boolean): NDArray = { org.apache.mxnet.Image.imDecode(inputStream, flag, toRGB, None) } + def imDecode(inputStream: InputStream): NDArray = { + imDecode(inputStream, 1, true) + } + /** * Read and decode image with OpenCV. * Note: return image in RGB by default, instead of OpenCV's default BGR. @@ -53,10 +64,14 @@ object Image { * (instead of opencv's default BGR). * @return org.apache.mxnet.NDArray in HWC format with DType [[DType.UInt8]] */ - def imRead(filename: String, flag: Int, toRGB: Boolean = true): NDArray = { + def imRead(filename: String, flag: Int, toRGB: Boolean): NDArray = { org.apache.mxnet.Image.imRead(filename, Some(flag), Some(toRGB), None) } + def imRead(filename: String): NDArray = { + imRead(filename, 1, true) + } + /** * Resize image with OpenCV. * @param src source image in NDArray @@ -70,6 +85,10 @@ object Image { org.apache.mxnet.Image.imResize(src, w, h, interpVal, None) } + def imResize(src: NDArray, w: Int, h: Int): NDArray = { + imResize(src, w, h, null) + } + /** * Do a fixed crop on the image * @param src Src image in NDArray