[英]Scala, how to convert a (Breeze) matrix to a geoTiff image?
I have a matrix representing an image, in Breeze . 我在Breeze中有一个表示图像的矩阵。 For instance, each cell (x, y) holds a RGB value. 例如,每个像元(x,y)都具有RGB值。 I can save it as various image formats (GIF, Jpeg...) using Scrimage . 我可以使用Scrimage将其另存为各种图像格式(GIF,Jpeg ...)。
How can I generate a geoTiff image? 如何生成geoTiff图像? I am looking at GeoTrellis but haven't figured out a straightforward way yet. 我正在查看GeoTrellis,但还没有想出直接的方法。
So you are talking about RGB image, potentially it means an int GeoTiff. 所以您在谈论RGB图像,可能意味着它是int GeoTiff。
The code looks like (current snapshot version 1.0.0-SNAPSHOT
): 代码看起来像(当前快照版本1.0.0-SNAPSHOT
):
val matrix: Array[Array[Int]] = ???
val cols = ??? // matrix dimensions
val rows = ???
val extent: Extent = ??? // you need extent for geotiff
val crs: CRS = ??? // you need to know crs
val tile = IntArrayTile.empty(cols, rows) // create an empty tile
for {
c <- 0 until cols
r <- 0 until rows
} tile.set(c, r, matrix(c)(r))
val geotiff = SinglebandGeoTiff(tile, extent, crs) // it's a geotiff
geotiff.write("dir where you plan to save your geotiff")
However it would be a grayscaled geotiff, to persist an RGB image you may want to create three tiles, and to save everything as a Multiband GeoTiff. 但是,这将是灰度的Geotiff,要保留RGB图像,您可能需要创建三个图块,并将所有内容另存为Multiband GeoTiff。
val red: Tile = ???
val green: Tile = ???
val blue: Tile = ???
val mbtile = MultibandTile(red, green, bule)
val mbgeotiff = new MultibandGeoTiff(
mbtile,
extent,
crs,
GeoTiffOptions(
Striped,
NoCompression,
ColorSpace.RGB
)
) // GeoTiff options setup is quite important, to set up `TIFFTAG_PHOTOMETRIC` tag
mbgeotiff.write("dir where you plan to save your geotiff")
But I am not familiar with Breeze
API, we can discuss your use case in a GeoTrellis gitter channel or / and to provide more information there. 但是我不熟悉Breeze
API,我们可以在GeoTrellis gitter频道或/中讨论您的用例,并在那里提供更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.