Skip to content

Fix DPC border handling with CFA-aware padding (closes #31) - #32

Merged
marianadeem-10xe merged 5 commits into
10x-Engineers:mainfrom
wuyiulin:fix/dpc-cfa-padding
Sep 23, 2026
Merged

marianadeem-10xe merged 5 commits into
10x-Engineers:mainfrom
wuyiulin:fix/dpc-cfa-padding

Conversation

@wuyiulin

Copy link
Copy Markdown
Contributor

Closes #31. Port of the fix in 10x-Engineers/Infinite-ISP#50 (issue 10x-Engineers/Infinite-ISP#39).

Problem

apply_fast_dead_pixel_correction() relied on scipy's mode="mirror" to pad the raw
mosaic. Same-color neighbours are 2 px apart, so at rows/cols 1 and N-2 the mirrored
neighbour is the center pixel itself and img > max_value / img < min_value can
never trigger. The loop version apply_dead_pixel_correction() has the same bug via
padding() (np.pad(..., "reflect") on the mosaic).

Fix

  • Add pad_cfa(): pads each of the 4 CFA sub-grids by 1 px with reflect
    (= 2 px on the mosaic), preserving Bayer phase.
  • Fast path: pad with pad_cfa() before filtering, crop dpc_img and
    detection_mask back afterwards (so the debug count stays correct).
  • padding() now uses pad_cfa(), so the loop version gets the same fix and both
    paths stay bit-exact. Happy to drop this part if you'd prefer to keep the scope to
    the fast path only.
  • Detection/correction logic is unchanged.

Tests

New tests/test_dead_pixel_correction.py (75 cases):

  • isolated hot/dead pixel at every border position (rows/cols 0, 1, 2, N-3, N-2, N-1)
  • fast vs loop implementation bit-exact
  • clean image unchanged, shape/dtype preserved
  • pad_cfa() never mirrors a pixel onto itself and keeps Bayer phase
this PR main
pytest tests/test_dead_pixel_correction.py 75 passed 41 failed, 34 passed

On main, 40 of the failures are border defects left uncorrected (every position
with row or col 1 / N-2, hot and dead); the remaining one is the pad_cfa() test,
since the method doesn't exist there.

On in_frames/normal/ColorCheckerRaw_2592x1536_10bit_GRBG_100DPs_ISO100.raw
(dp_threshold: 80) the output is bit-identical before/after (95 detections),
and runtime is unchanged, so no regression on existing assets. pylint 10.00/10.

Note

Since the Reference Model is the basis for the RTL, the matching DPC block in
Infinite-ISP_RTL may need the same border handling to stay bit-accurate.

Pull request checklist:

  • Issue created

ReadMe / Documentation: N/A (bug fix, no change to block diagram, results, or module description)

@marianadeem-10xe
marianadeem-10xe self-requested a review September 21, 2026 08:33

@marianadeem-10xe marianadeem-10xe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @wuyiulin. The fix and tests look good. Two changes are suggested in comments before merge.

Comment thread modules/dead_pixel_correction.py Outdated
return self.pad_cfa(self.img)

@staticmethod
def pad_cfa(img):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One design suggestion: could you move pad_cfa() into util/utils.py as a plain function instead of using @staticmethod here? All helper functions in this repo are placed there, this design is common to all modules.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Moved pad_cfa() to util/utils.py as a plain function and updated the imports in the module and the tests.

Comment thread modules/dead_pixel_correction.py Outdated
@@ -30,10 +30,25 @@ def __init__(self, img, platform, sensor_info, parm_dpc, save_out_obj):
self.save_out_obj = save_out_obj

def padding(self):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

padding function can be removed as it is unused.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. The loop-based apply_dead_pixel_correction() now calls pad_cfa() directly.

@wuyiulin

Copy link
Copy Markdown
Contributor Author

Should I apply the same change (moving pad_cfa() to util/utils.py) to 10x-Engineers/Infinite-ISP#50 for consistency?

@marianadeem-10xe

Copy link
Copy Markdown
Collaborator

Should I apply the same change (moving pad_cfa() to util/utils.py) to 10x-Engineers/Infinite-ISP#50 for consistency?

Yes please. I missed it earlier. Apologies for the inconvenience.

Added comment to disable pylint warning on `increase_indent`. The `indentless` argument is unused in the body but required to match the parent class's method parameters.

@marianadeem-10xe marianadeem-10xe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes Reviewed.

@marianadeem-10xe
marianadeem-10xe merged commit d12d14e into 10x-Engineers:main Sep 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DPC border pixels (rows/cols 1 and N-2) undetected due to mirror-padding on raw mosaic

2 participants