Skip to content

Commit

Permalink
Don't run star detection on daytime images
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Corry <kylecorry31@gmail.com>
  • Loading branch information
kylecorry31 committed Dec 22, 2024
1 parent 7dc46b8 commit 7eb3a23
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import com.kylecorry.andromeda.bitmaps.BitmapUtils.minMax
import com.kylecorry.andromeda.bitmaps.BitmapUtils.resizeToFit
import com.kylecorry.andromeda.core.units.PixelCoordinate

class PercentOfMaxStarFinder(private val percent: Float = 0.8f) : StarFinder {
class PercentOfMaxStarFinder(private val percent: Float = 0.8f, private val imageSize: Int = 600) :
StarFinder {
override fun findStars(image: Bitmap): List<PixelCoordinate> {
val resized = image.resizeToFit(1000, 1000)
val resized = image.resizeToFit(imageSize, imageSize)

try {
val range = resized.minMax()
resized.recycle()
val simpleFinder = SimpleStarFinder(range.end * percent, imageSize = 1000)
val simpleFinder = SimpleStarFinder(range.end * percent, imageSize = imageSize)
return simpleFinder.findStars(image)
} finally {
resized.recycle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import com.kylecorry.andromeda.core.units.PixelCoordinate
class StandardDeviationStarFinder(
private val sigma: Float = 4f,
private val minBrightness: Float = 40f,
private val maxBrightness: Float = 240f
private val maxBrightness: Float = 240f,
private val imageSize: Int = 600
) : StarFinder {
override fun findStars(image: Bitmap): List<PixelCoordinate> {
val resized = image.resizeToFit(1000, 1000)
val resized = image.resizeToFit(imageSize, imageSize)

try {
val mean = resized.average()
Expand All @@ -25,7 +26,7 @@ class StandardDeviationStarFinder(
minBrightness,
maxBrightness
),
imageSize = 1000
imageSize = imageSize
)
return simpleFinder.findStars(image)
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package com.kylecorry.trail_sense.tools.celestial_navigation.domain
class StarFinderFactory {

fun getStarFinder(): StarFinder {
val imageSize = 1000
// TODO: Instead of calculating the clusters on each star finder, threshold the images (binary), merge them (average), re-threshold (votes), and then find the stars
return EnsembleStarFinder(
DifferenceOfGaussiansStarFinder(0.3f, 2, 8, imageSize = 1000),
StandardDeviationStarFinder(5f),
PercentOfMaxStarFinder(0.6f),
DifferenceOfGaussiansStarFinder(0.3f, 2, 8, imageSize = imageSize),
StandardDeviationStarFinder(5f, imageSize = imageSize),
PercentOfMaxStarFinder(0.6f, imageSize = imageSize),
mergeDistance = 5f
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.camera.view.PreviewView
import com.kylecorry.andromeda.alerts.Alerts
import com.kylecorry.andromeda.alerts.toast
import com.kylecorry.andromeda.bitmaps.BitmapUtils.average
import com.kylecorry.andromeda.core.system.Resources
import com.kylecorry.andromeda.core.ui.Colors
import com.kylecorry.andromeda.core.ui.Colors.withAlpha
Expand Down Expand Up @@ -250,8 +251,9 @@ class CelestialNavigationFragment : BoundFragment<FragmentCelestialNavigationBin
}

val image = binding.camera.previewImage
val brightness = image?.average()

if (image != null) {
if (image != null && brightness != null && brightness < 100) {
val starPixels = onDefault { starFinder.findStars(image) }

if (isDebug()) {
Expand Down

0 comments on commit 7eb3a23

Please sign in to comment.