ximgproc: move EMD (Earth Mover's Distance) from imgproc - #4148
Open
JArmandoAnaya wants to merge 2 commits into
Open
ximgproc: move EMD (Earth Mover's Distance) from imgproc#4148JArmandoAnaya wants to merge 2 commits into
JArmandoAnaya wants to merge 2 commits into
Conversation
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.
6 tasks
There was a problem hiding this comment.
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::EMDimplementation (solver + lower-bound fast path) and awrapperEMDAPI. - 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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::ximgprocnow.The change is split into two commits so each can be reviewed on its own:
EMD/wrapperEMDdeclarations, andthe accuracy test across unchanged apart from the
cv::ximgprocnamespace, soit reads as a straight move.
casts become
static_cast, null pointer literals becomenullptr, theconstructor initializer list moves to in-class member initializers, and the
math and
memsetcalls arestd::-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