File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
scala-package/core/src/main/scala/org/apache/mxnet Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -174,16 +174,18 @@ object Image {
174
174
def toImage (src : NDArray ): BufferedImage = {
175
175
require(src.dtype == DType .UInt8 , " The input NDArray must be bytes" )
176
176
require(src.shape.length == 3 , " The input should contains height, width and channel" )
177
+ require(src.shape(2 ) == 3 , " There should be three channels: RGB" )
177
178
val height = src.shape.get(0 )
178
179
val width = src.shape.get(1 )
179
180
val img = new BufferedImage (width, height, BufferedImage .TYPE_INT_RGB )
181
+ val arr = src.toArray
180
182
(0 until height).par.foreach(r => {
181
183
(0 until width).par.foreach(c => {
182
- val arr = src.at(r).at(c).toArray
183
184
// NDArray in RGB
184
- val red = arr(0 ).toByte & 0xFF
185
- val green = arr(1 ).toByte & 0xFF
186
- val blue = arr(2 ).toByte & 0xFF
185
+ val cellIndex = r * width * 3 + c * 3
186
+ val red = arr(cellIndex).toByte & 0xFF
187
+ val green = arr(cellIndex + 1 ).toByte & 0xFF
188
+ val blue = arr(cellIndex + 2 ).toByte & 0xFF
187
189
val rgb = (red << 16 ) | (green << 8 ) | blue
188
190
img.setRGB(c, r, rgb)
189
191
})
You can’t perform that action at this time.
0 commit comments