martin-marek / hdr-plus-swift

📸Night mode on any camera. Based on HDR+.
https://burst.photo
GNU General Public License v3.0
208 stars 11 forks source link

Change texture_mean to work for all mosaic pattern widths #47

Closed Alex-Vasile closed 4 months ago

Alex-Vasile commented 10 months ago

The current implementation works fine when a single mean in required, but it did not function when a per_subpixel mean was required. A per-sub pixel mean is required for hot pixel identification and correction. This version is generalized and should work for all mosaic patterns.

How this approach works:

  1. Calculate the per-subpixel sum along rows.
    • Starting with an row x col sized texture, the output is a MPW x col texture.
  2. Sum the per-subpixel along columns.
    • Starting with the MPW x col image the result is a MPW^2 length buffer
  3. If needed, sum to single value, going from MPW^2 values to a single value.
  4. Divide sum by number of pixels.
    • per_sub_pixel=false: length * width
    • per_sub_pixels=true: length * width / mosaic_pattern_width^2

Both Bayer and XTrans images are affected by this, I tested both. Image results are identical before and after this PR