Skip to content

imgproc: fix phaseCorrelate ROI padding - #30725

Merged
abhishek-gola merged 1 commit into
opencv:4.xfrom
pbkx:fix-phasecorr-roi-padding-4x
Nov 10, 2026
Merged

abhishek-gola merged 1 commit into
opencv:4.xfrom
pbkx:fix-phasecorr-roi-padding-4x

Conversation

@pbkx

@pbkx pbkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

The function phaseCorrelate() uses copyMakeBorder() with BORDER_CONSTANT to pad the input matrices to ideal sizes for the DFT. When processing ROI-based matrices, this can cause pixels outside of the ROIs to be read. As a result, the output of the registration can differ between identically populated ROIs due to varying pixels in the parent matrices.

This PR uses the existing padding option BORDER_ISOLATED for the source matrices and optional window. A regression test has been added that uses parameterisation with CV_32F and CV_64F. The test compares different scenarios for ROI based inputs versus cloned inputs. The test checks for zero displacement, known integer displacement and ROI based windows with varying parent values around them. Both parameterised cases previously failed but now pass.

Related work: #30281 and #30320 address the separate input-mutation issue when applying a window.

Pull Request Readiness Checklist

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
  • The feature is well documented and sample code can be built with the project CMake

@codex-abhishek-gola codex-abhishek-gola Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Status: 🟡 Yellow

phaseCorrelate now isolates ROI inputs and ROI windows while zero-padding to the optimal DFT size, so copyMakeBorder cannot pull pixels from their parent matrices. The focused regression covers both supported depths, identical and translated inputs, cloned-versus-ROI behavior, and a window whose surrounding parent storage changes. I found no remaining source-level issue at this head; merge readiness is pending CI because this commit has no check result yet.

@asmorkalov asmorkalov added this to the 4.15.0 milestone Nov 9, 2026
@asmorkalov asmorkalov self-assigned this Nov 9, 2026
@abhishek-gola
abhishek-gola merged commit b41241f into opencv:4.x Nov 10, 2026
32 checks passed
abhishek-gola pushed a commit that referenced this pull request Nov 13, 2026
…0782)

* imgproc: do not read pixels outside a sub-matrix in CLAHE padding

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 #30725.

* imgproc: extend CLAHE_Padding to cover interior ROIs

Move the ROI regression into CLAHE_Padding: the ROI now has parent pixels to its right and bottom, and the reference padding is isolated.
hardikkaurani added a commit to hardikkaurani/opencv that referenced this pull request Nov 20, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants