Skip to content

ximgproc: move EMD (Earth Mover's Distance) from imgproc - #4148

Open
JArmandoAnaya wants to merge 2 commits into
opencv:5.xfrom
JArmandoAnaya:move-emd-to-ximgproc
Open

ximgproc: move EMD (Earth Mover's Distance) from imgproc#4148
JArmandoAnaya wants to merge 2 commits into
opencv:5.xfrom
JArmandoAnaya:move-emd-to-ximgproc

Conversation

@JArmandoAnaya

@JArmandoAnaya JArmandoAnaya commented Jun 15, 2026

Copy link
Copy Markdown

As part of the imgproc cleanup in opencv/opencv#25001, this moves the Earth
Mover's Distance function (EMD) from imgproc into ximgproc. EMD is an old,
rarely used function with no callers elsewhere in the library, so the extended
module is a more natural home for it.

This is the opencv_contrib side of the change. The companion pull request on the main repository removes EMD from imgproc
(opencv/opencv#29302), and the two are meant to be merged together. The public interface is unchanged apart from the namespace, so callers
reach the function through cv::ximgproc now.

The change is split into two commits so each can be reviewed on its own:

  • The first moves the implementation, the EMD / wrapperEMD declarations, and
    the accuracy test across unchanged apart from the cv::ximgproc namespace, so
    it reads as a straight move.
  • The second is a behavior-preserving C++17 cleanup of the moved code: C-style
    casts become static_cast, null pointer literals become nullptr, the
    constructor initializer list moves to in-class member initializers, and the
    math and memset calls are std::-qualified. No logic or numerics change.

The accuracy test moved with the function and still passes. It also gains a case
covering the lower-bound path, which the previous test did not exercise.

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

EMD and its transportation-problem solver move out of imgproc into
ximgproc as part of the imgproc cleanup (opencv/opencv#25001). The
implementation, the public EMD/wrapperEMD declarations, and the accuracy
test are brought over unchanged apart from the cv::ximgproc namespace and
the includes needed to build in this module.

A lower_bound accuracy test is added to cover the checkLowerBound code
path, which the previous suite did not exercise with a non-null
lowerBound.
Behavior-preserving cleanup of the moved EMD code (opencv/opencv#25001):
C-style casts become static_cast, null pointer literals become nullptr,
the constructor initializer list moves to in-class member initializers,
and the math and memset calls are std::-qualified. No logic or numerics
change; the EMD accuracy tests still pass.
Copilot AI review requested due to automatic review settings June 15, 2026 06:30

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds Earth Mover’s Distance (EMD) support to ximgproc, including a new public header and a test suite to validate regression behavior, supported metrics, lower-bound shortcut behavior, and invalid inputs.

Changes:

  • Introduces cv::ximgproc::EMD implementation (solver + lower-bound fast path) and a wrapperEMD API.
  • Adds unit tests covering regression inputs, metric types, lower-bound behavior, randomized flow verification, and invalid argument cases.
  • Exposes the new API via opencv2/ximgproc.hpp.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
modules/ximgproc/src/emd.cpp Implements the EMD solver, distance functions, lower-bound shortcut, and the public cv::ximgproc::EMD entry point.
modules/ximgproc/include/opencv2/ximgproc/emd.hpp Adds the public API declaration and documentation for EMD + wrapper.
modules/ximgproc/include/opencv2/ximgproc.hpp Exposes the new EMD header from the umbrella include.
modules/ximgproc/test/test_emd.cpp Adds tests for correctness, lower-bound shortcut, distance types, and invalid inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread modules/ximgproc/src/emd.cpp
Comment thread modules/ximgproc/src/emd.cpp
Comment thread modules/ximgproc/src/emd.cpp
Comment thread modules/ximgproc/test/test_emd.cpp
Comment thread modules/ximgproc/include/opencv2/ximgproc/emd.hpp
Comment thread modules/ximgproc/include/opencv2/ximgproc/emd.hpp
Comment thread modules/ximgproc/include/opencv2/ximgproc/emd.hpp
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.

2 participants