Skip to content

Commit

Permalink
Minor optimisations.
Browse files Browse the repository at this point in the history
Signed-off-by: Ralph Gasser <[email protected]>
  • Loading branch information
ppanopticon committed Aug 21, 2024
1 parent 3168ae3 commit 92f62e3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,34 @@ value class RGBColorContainer constructor(private val rgb: FloatArray) {
val alpha: Float
get() = this.rgb[3]

/**
* Converts the [red] component of this [RGBColorContainer] to an [Int] representation.
*
* @return [Int] representation of [blue] color
*/
fun redAsInt(): Int = (this.red * 255).toInt()

/**
* Converts the [green] component of this [RGBColorContainer] to an [Int] representation.
*
* @return [Int] representation of [blue] color
*/
fun greenAsInt(): Int = (this.green * 255).toInt()

/**
* Converts the [blue] component of this [RGBColorContainer] to an [Int] representation.
*
* @return [Int] representation of [blue] color
*/
fun blueAsInt(): Int = (this.blue * 255).toInt()

/**
* Converts the [alpha] component of this [RGBColorContainer] to an [Int] representation.
*
* @return [Int] representation of [alpha] color
*/
fun alphaAsInt(): Int = (this.alpha * 255).toInt()

/**
* Adds this [RGBColorContainer] to another [RGBColorContainer].
*
Expand Down Expand Up @@ -88,7 +116,7 @@ value class RGBColorContainer constructor(private val rgb: FloatArray) {
*
* @return [Int] representation of RGB color
*/
fun toRGBInt(): Int = (this.blue * 255).toInt() and 0XFF or ((this.green * 255).toInt() and 0xFF shl 8) or (((this.red * 255).toInt() and 0xFF) shl 16)
fun toRGBInt(): Int = this.blueAsInt() and 0XFF or ((this.greenAsInt() and 0xFF) shl 8) or ((this.redAsInt() and 0xFF) shl 16)

/**
* Converts this [RGBColorContainer] to a [HSVColorContainer].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.vitrivr.engine.core.model.types.Value
import org.vitrivr.engine.core.operators.Operator
import org.vitrivr.engine.core.operators.ingest.Extractor
import org.vitrivr.engine.core.operators.retrieve.Retriever
import org.vitrivr.engine.core.util.extension.getRGBArray
import java.util.*
import kotlin.reflect.KClass

Expand Down Expand Up @@ -128,7 +129,7 @@ class HueHistogram : Analyser<ImageContent, FloatVectorDescriptor> {
fun analyse(content: ImageContent): FloatVectorDescriptor {
/* Generate histogram. */
val hist = FloatArray(VECTOR_SIZE)
val colors = content.content.getRGB(0, 0, content.content.width, content.content.height, null, 0, content.content.width)
val colors = content.content.getRGBArray()
for (color in colors) {
val container: HSVColorContainer = RGBColorContainer(color).toHSV()
if (container.saturation > 0.2f && container.value > 0.3f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.vitrivr.engine.core.model.types.Value
import org.vitrivr.engine.core.operators.Operator
import org.vitrivr.engine.core.operators.ingest.Extractor
import org.vitrivr.engine.core.operators.retrieve.Retriever
import org.vitrivr.engine.core.util.extension.getRGBArray
import org.vitrivr.engine.core.util.math.StatisticsHelper.medianFromHistogram
import java.util.*

Expand Down Expand Up @@ -128,12 +129,12 @@ class MedianColor : Analyser<ImageContent, FloatVectorDescriptor> {
val b = IntArray(256)

/* Extract colors from content and generate histogram. */
val colors: IntArray = content.content.getRGB(0, 0, content.content.width, content.content.height, null, 0, content.content.width);
val colors: IntArray = content.content.getRGBArray()
for (color in colors) {
val rgb = RGBColorContainer(color)
r[(rgb.red * 255).toInt()]++
g[(rgb.green * 255).toInt()]++
b[(rgb.blue * 255).toInt()]++
r[rgb.redAsInt()]++
g[rgb.greenAsInt()]++
b[rgb.blueAsInt()]++
}

/* Generate vector from per-color histograms. */
Expand Down

0 comments on commit 92f62e3

Please sign in to comment.