This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b7fd15
commit 0a3bc8d
Showing
2 changed files
with
98 additions
and
75 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
scala-package/core/src/main/scala/org/apache/mxnet/javaapi/Image.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.mxnet.javaapi | ||
// scalastyle:off | ||
import java.awt.image.BufferedImage | ||
// scalastyle:on | ||
import java.io.InputStream | ||
|
||
object Image { | ||
/** | ||
* Decode image with OpenCV. | ||
* Note: return image in RGB by default, instead of OpenCV's default BGR. | ||
* @param buf Buffer containing binary encoded image | ||
* @param flag Convert decoded image to grayscale (0) or color (1). | ||
* @param toRGB Whether to convert decoded image | ||
* to mxnet's default RGB format (instead of opencv's default BGR). | ||
* @return NDArray in HWC format | ||
*/ | ||
def imDecode(buf: Array[Byte], flag: Int, toRGB: Boolean, out: NDArray): NDArray = { | ||
org.apache.mxnet.Image.imDecode(buf, flag, toRGB, Some(out)) | ||
} | ||
|
||
/** | ||
* Same imageDecode with InputStream | ||
* @param inputStream the inputStream of the image | ||
* @return NDArray in HWC format | ||
*/ | ||
def imDecode(inputStream: InputStream, flag: Int = 1, toRGB: Boolean = true, | ||
out: NDArray): NDArray = { | ||
org.apache.mxnet.Image.imDecode(inputStream, flag, toRGB, Some(out)) | ||
} | ||
|
||
/** | ||
* Read and decode image with OpenCV. | ||
* Note: return image in RGB by default, instead of OpenCV's default BGR. | ||
* @param filename Name of the image file to be loaded. | ||
* @param flag Convert decoded image to grayscale (0) or color (1). | ||
* @param toRGB Whether to convert decoded image to mxnet's default RGB format | ||
* (instead of opencv's default BGR). | ||
* @return org.apache.mxnet.NDArray in HWC format | ||
*/ | ||
def imRead(filename: String, flag: Int, toRGB: Boolean = true, out: NDArray): NDArray = { | ||
org.apache.mxnet.Image.imRead(filename, Some(flag), Some(toRGB), Some(out)) | ||
} | ||
|
||
/** | ||
* Resize image with OpenCV. | ||
* @param src source image in NDArray | ||
* @param w Width of resized image. | ||
* @param h Height of resized image. | ||
* @param interp Interpolation method (default=cv2.INTER_LINEAR). | ||
* @return org.apache.mxnet.NDArray | ||
*/ | ||
def imResize(src: NDArray, w: Int, h: Int, | ||
interp: Integer, out: NDArray): NDArray = { | ||
org.apache.mxnet.Image.imResize(src, w, h, Some(interp), Some(out)) | ||
} | ||
|
||
/** | ||
* Do a fixed crop on the image | ||
* @param src Src image in NDArray | ||
* @param x0 starting x point | ||
* @param y0 starting y point | ||
* @param w width of the image | ||
* @param h height of the image | ||
* @return cropped NDArray | ||
*/ | ||
def fixedCrop(src: NDArray, x0: Int, y0: Int, w: Int, h: Int): NDArray = { | ||
org.apache.mxnet.Image.fixedCrop(src, x0, y0, w, h) | ||
} | ||
|
||
/** | ||
* Convert a NDArray image to a real image | ||
* The time cost will increase if the image resolution is big | ||
* @param src Source image file in RGB | ||
* @return Buffered Image | ||
*/ | ||
def toImage(src: NDArray): BufferedImage = { | ||
org.apache.mxnet.Image.toImage(src) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters