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

Add clahe operator #2726

Merged
merged 2 commits into from
May 23, 2021
Merged

Add clahe operator #2726

merged 2 commits into from
May 23, 2021

Conversation

baparham
Copy link
Contributor

@baparham baparham commented May 20, 2021

This should fix #1066 but it still needs tests.

Is something like this along the right track?

@lovell Do you have any advice on an overall methodology for testing something like this? Should I generate some sample images or something directly with libvips and use those as expected inputs and outputs for a test? What's the standard practice here?

@baparham
Copy link
Contributor Author

This really just wraps the vips hist_local command, so perhaps the arguments to this operator need to match the valid inputs to vips:

C:\vips-dev-8.10\bin>vips.exe hist_local
local histogram equalisation
usage:
   hist_local in out width height [--option-name option-value ...]
where:
   in           - Input image, input VipsImage
   out          - Output image, output VipsImage
   width        - Window width in pixels, input gint
                        default: 1
                        min: 1, max: 10000000
   height       - Window height in pixels, input gint
                        default: 1
                        min: 1, max: 10000000
optional arguments:
   max-slope    - Maximum slope (CLAHE), input gint
                        default: 0
                        min: 0, max: 100
operation flags: sequential

I believe I can generate some sample expected outputs directly with libvips and use those for some unit tests, as demonstrated by something like the unit tests for the .blur() operator. I'll do that tonight when I get some more time.

I think it also makes sense to update the .clahe() valid arguments to accept even values too, and be more clear with the min and max as defined by the libvips help above.

@baparham baparham force-pushed the feature-add-clahe branch 2 times, most recently from e8194f6 to 43601f9 Compare May 21, 2021 08:37
Copy link
Owner

@lovell lovell left a comment

Choose a reason for hiding this comment

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

This looks great, thank you very much Brad. I've left a few small questions/comments inline that might need addressing but otherwise this is good to merge.

test/fixtures/index.js Outdated Show resolved Hide resolved
src/pipeline.cc Outdated Show resolved Hide resolved
lib/operation.js Outdated Show resolved Hide resolved
lib/operation.js Outdated Show resolved Hide resolved
lib/operation.js Show resolved Hide resolved
@baparham
Copy link
Contributor Author

baparham commented May 21, 2021

I believe I addressed your comments with the force push. Thanks for the quick feedback.

@baparham
Copy link
Contributor Author

Do types automatically get rebuilt when you do a release or should I include some update to the typings for Typescript in this pull request?

@baparham
Copy link
Contributor Author

Hmm, vips actually looks (and behaves, now that I've tried this with non-integers like 0.5 or 2.5) like it only takes integers as the maxSlope, so I'll need to modify the expected type and argument checking of the maxSlope argument.

@baparham baparham force-pushed the feature-add-clahe branch 2 times, most recently from d3b27fb to bd80846 Compare May 21, 2021 21:02
@baparham
Copy link
Contributor Author

Hmm, vips actually looks (and behaves, now that I've tried this with non-integers like 0.5 or 2.5) like it only takes integers as the maxSlope, so I'll need to modify the expected type and argument checking of the maxSlope argument.

I made these changes, so now the maxSlope should be an int, which matches what the libvips hist_local api accepts.

It was just truncating the decimel before, so 0.5 would be the same as 0, and 1.0, 1.1, and 1.9 would all return the same result as if maxSlope = 1.

@baparham
Copy link
Contributor Author

Darn, not quite, I missed a few things that make the build fail, and now that I've changed everything, the tests are failing with similarity thresholds that are too high. I'll manually compare the the images to see if they look as they should compared with the libvips outputted images.

@baparham
Copy link
Contributor Author

Darn, not quite, I missed a few things that make the build fail, and now that I've changed everything, the tests are failing with similarity thresholds that are too high. I'll manually compare the the images to see if they look as they should compared with the libvips outputted images.

The threshold failing tests were resolved after deleting and rebuilding build, so I think it was just that something was out of sync in the built library with the js interface perhaps. I also fixed a few c++ errors that I had missed before when changing from double to int on maxSlope.

It should be good now, and I've tested it manually a bit outside the tests to double check.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling d2c3f81 on baparham:feature-add-clahe into b69a54f on lovell:master.

@lovell lovell merged commit 4b6b618 into lovell:master May 23, 2021
@lovell lovell added this to the v0.28.3 milestone May 23, 2021
@lovell
Copy link
Owner

lovell commented May 23, 2021

Marvellous, thanks again.

Do types automatically get rebuilt when you do a release or should I include some update to the typings for Typescript in this pull request?

These are managed by the https://github.com/DefinitelyTyped/DefinitelyTyped repo. If you're able to add these (after v0.28.3 is released), that would be great.

lovell added a commit that referenced this pull request May 23, 2021
@baparham
Copy link
Contributor Author

I have the patch (since I needed it locally for testing my client code anyway) so I'll push it into a draft pull request over there to time when 0.28.3 is released and keep you in the loop.

Thanks for the help getting this in!

@baparham baparham deleted the feature-add-clahe branch May 29, 2021 12:43
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.

Enhancing clarity of an image
3 participants