Fix wrong implementation of unsharpen filter #2079
Merged
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.
This PR fixes the crate's current implementation of the unsharpen filter, which currently does not work in the intended way. Normally, in order to calculate the unsharpen filter, the following steps are taken:
threshold
parameter, so that absolute difference values that lie below a certain limit are not used in the filteramount
parameter, which controls the strength of the filter (this PR does not add that parameter)The current way this is done doesn't take into account that the difference that has to be added to the original image can be both positive and negative, returning less sharp images than the originals. That's what this PR aims to fix.
It should also be noted that:
imageops::unsharpen()
function is not great, using a datatype-dependent threshold value, and lacking the very commonamount
orstrength
value that is present in almost all applications that have this filter.Image examples:
Current:
![An image showing the current implementation of the unsharpen filter](https://camo.githubusercontent.com/eb52bd22927fa1b52729b84adb56fd82f3ab43a4da1ceda2e29d1fad115c950d/68747470733a2f2f692e696d6775722e636f6d2f3248454d7155702e706e67)
This PR:
![An image showing this PR's implementation of the unsharpen filter](https://camo.githubusercontent.com/4e697a2f8c7bcb9fab9d3ce9a86d85884e61e3af5917ec7da824105898ae8ee9/68747470733a2f2f692e696d6775722e636f6d2f396738756852612e706e67)
Original:
![The original image](https://camo.githubusercontent.com/87005137cb527f5c3a6de63d4e946774980de69d1a5825c4e9ad1d293437e6ee/68747470733a2f2f692e696d6775722e636f6d2f5856436d36624d2e706e67)
Other examples of the desired effect can also be found on the unsharp masking Wikipedia page
I license past and future contributions under the dual MIT/Apache-2.0 license, allowing licensees to choose either at their option.