【问题标题】:Improving output when combining RGB channels on Landsat and converting to PNG在 Landsat 上组合 RGB 通道并转换为 PNG 时提高输出
【发布时间】:2016-07-15 14:06:54
【问题描述】:

我正在使用 Scala 和 Geotrellis 库来执行 Landsat-8 图像的处理和分析,但是当我尝试组合波段 2、3 和 4(红色、绿色和蓝色)时,这是生成的多波段 tiff (右)和从中生成的 png(左):

http://imgur.com/a/aA4XW

组合单频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) 时,我得到的只是左图的彩色版本。

对不起,如果这是一个菜鸟问题,并提前感谢您的任何帮助。

【问题讨论】:

    标签: scala image-processing geotiff landsat geotrellis


    【解决方案1】:

    如果您要将陆地卫星像素值视为字节,则需要将它们标准化为 0 - 255。带有 0xFF 掩码的渲染代码将值视为字节。

    这是一个 PR,显示了使您的代码工作的更改:https://github.com/ardilgulez/gt-1/pull/1

    下面是一些其他代码示例,这些代码对陆地卫星图像进行标准化和轻微颜色校正,以便将它们呈现为 web 地图的 PNG:https://github.com/geotrellis/geotrellis-landsat-emr-demo/blob/57353688471805b133a04a97ff86b26021e8d7b5/server/src/main/scala/demo/Render.scala#L22

    【讨论】:

      猜你喜欢
      • 2019-09-05
      • 1970-01-01
      • 2021-06-10
      • 2011-06-02
      • 2012-05-11
      • 2013-02-20
      • 1970-01-01
      • 1970-01-01
      • 2013-02-18
      相关资源
      最近更新 更多