<commit_before>package com.azavea.rf.tile.image

import geotrellis.raster._
import geotrellis.raster.equalization.HistogramEqualization
import geotrellis.raster.histogram.Histogram
import geotrellis.raster.sigmoidal.SigmoidalContrast

object ColorCorrect {
  case class Params(
    redBand: Int, greenBand: Int, blueBand: Int,
    redGamma: Option[Double], greenGamma: Option[Double], blueGamma: Option[Double],
    contrast: Option[Double], brightness: Option[Int],
    alpha: Option[Double], beta: Option[Double],
    min: Option[Int], max: Option[Int],
    equalize: Boolean
  ) {
    def reorderBands(tile: MultibandTile, hist: Seq[Histogram[Double]]): (MultibandTile, Array[Histogram[Double]]) =
      (tile.subsetBands(redBand, greenBand, blueBand), Array(hist(redBand), hist(greenBand), hist(blueBand)))
  }

  def apply(rgbTile: MultibandTile, rgbHist: Array[Histogram[Double]], params: Params): MultibandTile = {
    val maybeEqualize =
      if (params.equalize) Some(HistogramEqualization(_: MultibandTile, rgbHist)) else None

    val normalizeAndClampValues =
      (_: MultibandTile).mapBands { (i, tile) =>
        normalizeAndClamp(tile,
          oldMin = params.min.getOrElse(0),
          oldMax = params.max.getOrElse(maxCellValue(tile.cellType)),
          newMin = 0,
          newMax = 255
        ).convert(UByteCellType)
      }

    val maybeAdjustBrightness =
      for (b <- params.brightness)
        yield (mb: MultibandTile) => mb.mapBands { (i, tile) => adjustBrightness(tile, b) }

    val maybeAdjustContrast =<commit_msg>Use celltype that respects NODATA<commit_after>package com.azavea.rf.tile.image

import geotrellis.raster._
import geotrellis.raster.equalization.HistogramEqualization
import geotrellis.raster.histogram.Histogram
import geotrellis.raster.sigmoidal.SigmoidalContrast

object ColorCorrect {
  case class Params(
    redBand: Int, greenBand: Int, blueBand: Int,
    redGamma: Option[Double], greenGamma: Option[Double], blueGamma: Option[Double],
    contrast: Option[Double], brightness: Option[Int],
    alpha: Option[Double], beta: Option[Double],
    min: Option[Int], max: Option[Int],
    equalize: Boolean
  ) {
    def reorderBands(tile: MultibandTile, hist: Seq[Histogram[Double]]): (MultibandTile, Array[Histogram[Double]]) =
      (tile.subsetBands(redBand, greenBand, blueBand), Array(hist(redBand), hist(greenBand), hist(blueBand)))
  }

  def apply(rgbTile: MultibandTile, rgbHist: Array[Histogram[Double]], params: Params): MultibandTile = {
    val maybeEqualize =
      if (params.equalize) Some(HistogramEqualization(_: MultibandTile, rgbHist)) else None

    val normalizeAndClampValues =
      (_: MultibandTile).mapBands { (i, tile) =>
        normalizeAndClamp(tile,
          oldMin = params.min.getOrElse(0),
          oldMax = params.max.getOrElse(maxCellValue(tile.cellType)),
          newMin = 0,
          newMax = 255
        ).convert(UByteConstantNoDataCellType)
      }

    val maybeAdjustBrightness =
      for (b <- params.brightness)
        yield (mb: MultibandTile) => mb.mapBands { (i, tile) => adjustBrightness(tile, b) }

    val maybeAdjustContrast =
{'fraction_non_alphanumeric': 0.11760966306420852, 'fraction_numerical': 0.003178639542275906, 'mean_word_length': 4.150572831423895, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7656640', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1003, 'n_words': 206}