Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
add simplified methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lanking520 committed Jan 30, 2019
1 parent f1dcf99 commit 0f6e376
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0f6e376

Please sign in to comment.