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.