我正在使用 Scala 和 Geotrellis 库对 Landsat-8 图像进行处理和分析,但是当我尝试组合波段 2、3 和 4(红色、绿色和蓝色)时,这是生成的多波段 tiff(右)和从它生成的png(左):
组合单波段 tiff 的代码是:
class Tiler ( outputPath : String, bandIds : Array[String] ){
def bandPath(b: String) = s"data/landsat/LC81750342016185LGN00_B${b}.TIF"
def obtainBands() : (ArrayMultibandTile, SinglebandGeoTiff) = {
var tileArrayBuffer = ArrayBuffer[Tile]()
var geoTiff : SinglebandGeoTiff = null
bandIds.foreach((bandId) => {
geoTiff = SinglebandGeoTiff(bandPath(bandId))
tileArrayBuffer += geoTiff.tile
})
(ArrayMultibandTile(tileArrayBuffer), geoTiff)
}
def writeResultToFS(multiBand : MultibandTile, extent : Extent, crs : CRS) : Unit = {
MultibandGeoTiff(multiBand, extent, crs).write(outputPath)
}
def parseTiles() : Unit = {
val (multiBandTileArray, geotiff) = obtainBands()
writeResultToFS(multiBandTileArray, geotiff.extent, geotiff.crs)
}
}
另外,这是我的 png 转换器代码:
class PngTest() {
val tiffPath = "data/output/output.tif"
val bwPath = "data/output/bw.png"
def makepng(): Unit = {
println("Rendering PNG and saving to disk...")
val conversionMap = {
val multibandTile = MultibandGeoTiff(tiffPath).tile.convert(IntConstantNoDataCellType)
multibandTile.combine(0, 1, 2) { (rBand, gBand, bBand) =>
val r = if (isData(rBand)) { rBand } else 0
val g = if (isData(gBand)) { gBand } else 0
val b = if (isData(bBand)) { bBand } else 0
if(r + g + b == 0) 0
else {
val color = ( r + g + b ) / 3
((color & 0xFF) << 24) | ((color & 0xFF) << 16) | ((color & 0xFF) << 8) | 0xFF
}
}
}
conversionMap.renderPng().write(bwPath)
}
}
当我删除转换图并只执行 MultibandGeoTiff(tiffPath).tile.convert(IntConstantNoDataCellType).renderPng().write(bwPath) 时,我得到的只是左图的彩色版本。
对不起,如果这是一个菜鸟问题,并提前感谢您的任何帮助。