Anime4K icon indicating copy to clipboard operation
Anime4K copied to clipboard

Confused with usage of compareLuminance3()

Open DreamChaserMXF opened this issue 5 years ago • 2 comments

https://github.com/bloc97/Anime4K/blob/3bef75fbe9d7f9212b1efee24b9312544bf1d6de/java/src/main/java/com/bloc97/anime4k/ImageKernel.java#L375 https://github.com/bloc97/Anime4K/blob/3bef75fbe9d7f9212b1efee24b9312544bf1d6de/java/src/main/java/com/bloc97/anime4k/ImageKernel.java#L589

Hi, I'm confused with the two callings to the function compareLuminance3(). Could someone please help me to figure out that why the return value is inverted in the second usage? I assume the intention of both if statements is finding the edge.

DreamChaserMXF avatar Apr 07 '20 02:04 DreamChaserMXF

The unfortunate name of compareLuminance might cause some confusion. It should have been called isEveryLuminanceSmaller(s0, s1, s2, b0, b1, b2), where it returns true if and only if s0 < b0 and s1 < b1 and s2 < b2. The inverse (not) of the boolean comparison is s0 >= b0 or s1 >= b1 or s2 >= b2 by following De Morgan's laws. Note that and has become or. Thus, the first compareLuminance is true if dx < lx for all x, and the second is true if dx >= lx for any x.

bloc97 avatar Apr 07 '20 04:04 bloc97

Also, the first function returns the moment that compareLuminance() is true, while the second one loops over all !compareLuminance(), checks if (newLum > lightestLum), stores the lightest luminance and returns it only at the end.

Edit: Please note that the Java code is very convoluted and was only intended to be a proof of concept. If you want to have readable code, look at the GLSL v0.9 version of Anime4K. https://github.com/bloc97/Anime4K/blob/master/glsl/Anime4K_Adaptive_v0.9.glsl

bloc97 avatar Apr 07 '20 04:04 bloc97