Scala 和 Spark:如何查看图像? [英] Scala and Spark : how to go through an image?
问题描述
我有一些作为图像的二进制文件,我想通过它们自己来分配像素:我的集群的每个节点必须获得与另一个节点不同的像素组的 RGB,并存储这些RGB 转换为 Scala 集合.
I have some binary files that are images and I would want to go through themselves, distributing the pixels : each node of my cluster must get the RGB of a different group of pixel(s) than another node's ones, and store these RGB into a Scala collection.
我正在使用 SparkContext::binaryFiles
但我不知道如何让 Apache Spark能够理解"我正在使用一个图像,我想使用它来浏览它的像素分布,并且我想获得 RGB 值.你能帮我做吗?
I am using SparkContext::binaryFiles
but I don't know how to make Apache Spark "able to understand" that I am using an Image, that I would want to go through its pixels using distribution, and that I would want to get the RGB values. Could you help me to do that please ?
推荐答案
Spark 2.3 添加了对解析图像的支持.您可以像这样读取图像并获取元数据和图像数据:
Spark 2.3 added support for parsing images. You can read images and get meta data and image data like this:
import org.apache.spark.ml.image.ImageSchema._
import java.nio.file.Paths
val images = readImages("path/to/images")
images.foreach { rrow =>
val row = rrow.getAs[Row](0)
val filename = Paths.get(getOrigin(row)).getFileName().toString()
val imageData = getData(row)
val height = getHeight(row)
val width = getWidth(row)
println(s"${height}x${width}")
}
您可以找到更多信息 这里
这篇关于Scala 和 Spark:如何查看图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!