1

I'm using Scala and Geotrellis library to perform processing and analysis of Landsat-8 images, but when I tried to combine the bands 2, 3 and 4 (Red, Green and Blue) and here is the resulting multiband tiff (right) and png generated from it (left):

https://i.stack.imgur.com/uKI58.jpg

The code for combining the singleband tiffs is :

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)
    }

}

Also, this is my png converter code:

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)
    }
}

When I remove the conversion map and just do MultibandGeoTiff(tiffPath).tile.convert(IntConstantNoDataCellType).renderPng().write(bwPath), all I get is the colorful version of the left picture.

Sorry if this is a noob question and thanks for any help in advance.

metasim
  • 4,793
  • 3
  • 46
  • 70
ardilgulez
  • 1,856
  • 18
  • 19

1 Answers1

4

You need to normalize the landsat pixel values to 0 - 255 if you are going to treat them like bytes. The rendering code with they 0xFF masks treat the values like bytes.

Here is a PR that shows changes to make your code work: https://github.com/ardilgulez/gt-1/pull/1

Here is an example of some other code that does normalization and slight color correction of landsat images in order to render them as PNGs for a web map: https://github.com/geotrellis/geotrellis-landsat-emr-demo/blob/57353688471805b133a04a97ff86b26021e8d7b5/server/src/main/scala/demo/Render.scala#L22

lossyrob
  • 71
  • 5