Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove OpenCV as a dependency for qupath-core #961

Closed
petebankhead opened this issue Apr 26, 2022 · 0 comments
Closed

Remove OpenCV as a dependency for qupath-core #961

petebankhead opened this issue Apr 26, 2022 · 0 comments
Milestone

Comments

@petebankhead
Copy link
Member

Design issue

Describe the bug
qupath-core doesn't - and shouldn't have many dependencies.

However, it does currently have a dependency on OpenCV. This brings in JavaCPP and platform-dependent native libraries, in a way that potentially makes qupath-core much heavier that it would otherwise be.

Usage

There are really only two places where OpenCV is used in qupath-core:

Required change

I think (hope) type adaptors can be shifted to qupath-core-processing without too much trouble.
Although since the change was introduced in 0f0229f the commit message hints that there was a reason to including it in qupath-core that might resurface in the future.

I expect that the main effort would go into reimplementing image resizing. Ideally, we'd do this without introducing any new dependency (including ImageJ) to retain full control over the code and not have it subject to change with dependency updates.

I expect that will be a very fiddly task, requiring some very good unit tests.

Additional context

Resizing is performed whenever tiles are requested, e.g.

// Return the image, resizing if necessary
BufferedImage imgResult = new BufferedImage(colorModel, raster, alphaPremultiplied, null);
int currentWidth = imgResult.getWidth();
int currentHeight = imgResult.getHeight();
if (currentWidth != width || currentHeight != height) {
imgResult = BufferedImageTools.resize(imgResult, width, height, allowSmoothInterpolation());
}

In this case, it is almost always downsampling.

We need to support both a 'smooth' and a 'nearest neighbor' implementation, to handle intensity and labeled/binary images at least - although we might want to introduce more interpolation options.

See also qupath/2022-qupath-hackathon#2 (comment)

Significance

Having OpenCV as a dependency of qupath-core showed up when testing on a M1 Mac: it meant nothing would work until OpenCV had compatible binaries. It does now, but that flagged the issue of OpenCV being dragged into pretty much everything.

Removing it would mean that the core module - and therefore most serializable datastructures - depend upon only Java code. This could help in making it accessible elsewhere, e.g. from Python or R.

petebankhead added a commit to petebankhead/qupath that referenced this issue May 31, 2022
This is a step towards removing OpenCV as a core dependency, see qupath#961
petebankhead added a commit to petebankhead/qupath that referenced this issue May 31, 2022
@petebankhead petebankhead added this to the v0.4.0 milestone May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant