Repository navigation
imgproc: do not read pixels outside a sub-matrix in CLAHE padding - #30782
Conversation
When the size is not a multiple of the tile grid, CLAHE pads the source on the right and bottom with BORDER_REFLECT_101. This padding is internal (CLAHE has no borderType). Without BORDER_ISOLATED, copyMakeBorder takes those rows and columns from the parent matrix when the source is a region of a larger image, so the histograms of the last tiles and the result depended on pixels outside the region. Same pattern as the phaseCorrelate fix in opencv#30725.
There was a problem hiding this comment.
Status: 🟡 Yellow
Both CLAHE padding paths now isolate ROI inputs, so their synthetic right/bottom border cannot read pixels from the parent matrix. The focused regression exercises the affected non-divisible tile geometry for both supported depths and matches the established phaseCorrelate fix. No actionable source issue found; LGTM pending exact-head CI, including the OpenCL path.
Move the ROI regression into CLAHE_Padding: the ROI now has parent pixels to its right and bottom, and the reference padding is isolated.
There was a problem hiding this comment.
Status: 🟡 Yellow
The update folds the interior-ROI regression into the existing CLAHE padding fixture while preserving both supported depths and the non-divisible padding cases. The test still distinguishes isolated padding from parent-backed padding, so the outstanding review request is resolved. I found no remaining actionable issue in the delta; exact-head CI, including the OpenCL path, has not run yet.
|
#30781 is already done. |
…cing padding When processing a sub-matrix with VNG Bayer demosaicing (COLOR_Bayer*2BGR_VNG and COLOR_Bayer*2RGB_VNG), copyMakeBorder uses BORDER_REFLECT_101 without BORDER_ISOLATED. This causes the internal 2-pixel boundary halo to be read from the surrounding pixels of the parent matrix rather than reflecting the region's own borders. Consequently, the outer 2 rows and columns of the demosaiced image depend on unrelated pixels in the parent buffer. This patch adds BORDER_ISOLATED to the copyMakeBorder call in Bayer2RGB_VNG_8u, ensuring the 2-pixel padding is strictly computed by reflecting the region boundary. This matches the behavior of isolated/cloned matrices and follows the same pattern as the CLAHE (opencv#30782) and phaseCorrelate (opencv#30725) ROI padding fixes. Also instantiates ImgProc_BayerEdgeAware_SubMatrix with VNG codes and CV_8U, covering sub-matrix source and destination regions across all 4 Bayer VNG codes with odd and even dimensions.
When the image size is not a multiple of the tile grid, CLAHE pads the source on the right and bottom with
BORDER_REFLECT_101. This padding is internal and one-sided: CLAHE has noborderType, and it is only applied when the size is not divisible by the grid. WithoutBORDER_ISOLATED,copyMakeBordertakes those rows and columns from the parent matrix if the source is a region of a larger image, so the histograms of the last tiles and the output depended on pixels outside the region (a 23x17 region with a 4x4 grid differed from the same pixels in their own matrix). Unlike a filter halo this is not something a caller can ask for.Both
copyMakeBordercalls (CPU and OpenCL path) now passBORDER_ISOLATED, the same fix as #30725 (phaseCorrelate, merged 2026-11-10). Callers that pass a sub-matrix with non-divisible size will see different (corrected) output; whole matrices and divisible sizes are unchanged.Imgproc_CLAHE.roi_ignores_pixels_outside(8- and 16-bit) compares a region with unrelated pixels around it against a continuous copy; it fails on 4.x without the change and passes with it. The #30304 test is unaffected (its region ends at the parent's corner). The OpenCL branch was not built or run here.Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.