Skip to content

Commit

Permalink
Export multiple thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
n9Mtq4 committed Oct 11, 2020
1 parent 8026589 commit c0f0622
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions TileGen/src/main/kotlin/com/n9mtq4/gss/tilegen/Stitch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.n9mtq4.gss.tilegen
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO
import kotlin.math.roundToInt

/**
* Created by will on 7/21/20 at 11:10 PM.
Expand Down Expand Up @@ -44,28 +45,34 @@ fun stitch(landSatInDirName: String, predInDir: String, predOutDir: String, imag
val outFile = File(predOutDir, "${imageName}_NN.png")
ImageIO.write(predImage, "png", outFile)

thresholdImg(predImage)

val outFileThresh = File(predOutDir, "${imageName}_NNT.png")
ImageIO.write(predImage, "png", outFileThresh)
for (threshold in intArrayOf(2, 5, 7)) {

val thresholdByte = (255.0 * (threshold / 10.0)).roundToInt()
val timg = thresholdImg(predImage, thresholdByte)

val outFileThresh = File(predOutDir, "${imageName}_NNT$threshold.png")
ImageIO.write(timg, "png", outFileThresh)

}

}

fun thresholdImg(predImage: BufferedImage) {
fun thresholdImg(predImage: BufferedImage, threshold: Int = 128): BufferedImage {

val black = -16777216
val white = -1
val newImg = BufferedImage(predImage.width, predImage.height, predImage.type)

for (y in 0 until predImage.height) {
for (x in 0 until predImage.width) {

val color = predImage.getRGB(x, y)
val newColor = if (color == black) white else black
predImage.setRGB(x, y, newColor)
val color = predImage.raster.getSample(x, y, 0)
val newColor = if (color >= threshold) 255 else 0
newImg.raster.setSample(x, y, 0, newColor)

}
}

return newImg

}

fun writeTileCenter(fullImg: BufferedImage, tileImg: BufferedImage, tile: Tile) {
Expand Down

0 comments on commit c0f0622

Please sign in to comment.