MarsRaw / mars-raw-utils

Utilities for working with publicly available raw MSL & Mars2020 images
MIT License
45 stars 10 forks source link

Flatfield calibration doesn't correct RGB channels individually #12

Closed sschmaus closed 2 years ago

sschmaus commented 2 years ago

Expected Behavior

Calibrating a HELI_RTE image should perform a flatfield calibration that removes the color gradient in the original images. I modelled the RTE flat V3 with slightly different gradients per channel, so the apparent color cast can be corrected.

This is how it should look like (per channel calculation of RTE_IMAGE*mean(RTE_FLAT)/RTE_FLAT) HSF_0418_0703689905_000ECM_N0270001HELI00000_000085J01-rjcal_Gimp

Actual Behavior

Currently MRU appears to calibrate all channels with the same flat values. It appears to use either just one of the flatframe RGB channels or a greyscale version of the flatframe. Therefore the luminance gradient is corrected, but a color gradient remains.

This calibration has worked correctly in the past, I first noticed this issue with versions after the switch to sciimg.

This is the output from MRU: HSF_0418_0703689905_000ECM_N0270001HELI00000_000085J01-rjcal_MRU

Steps to Reproduce the Problem

  1. calibrate image with m20_hrte_calibrate -i *.png

Possible Solution

Perform the flatfield correction on every channel individually and with the corresponding flatframe channel. i.e: R: RTE_IMAGE_R*mean(RTE_FLAT_R)/RTE_FLAT_R G: RTE_IMAGE_G*mean(RTE_FLAT_G)/RTE_FLAT_G B: RTE_IMAGE_B*mean(RTE_FLAT_B)/RTE_FLAT_B

Specifications

kmgill commented 2 years ago

Issue is in sciimg submodule in rgbimage.rs, line 330, which only ever grabs band 0 from the flat. I'll fix that by adding a check for additional bands (not assuming three channel RGB or single channel monochrome)

kmgill commented 2 years ago

For reference: https://github.com/kmgill/sciimg

kmgill commented 2 years ago

Fixed with update to sciimg. Update to Cargo.toml for updated sciimg version number. Reference: https://github.com/kmgill/sciimg/commit/25cf445f4532e0439c174083b21b8b9cccc00537