vladmandic / sd-extension-chainner

SD.Next extension for additional upscalers based on chaiNNer
GNU General Public License v3.0
13 stars 1 forks source link

Fix negative value clipping for upscalers #5

Closed MaxJa4 closed 1 year ago

MaxJa4 commented 1 year ago

Description

Addresses the clipping issue described in https://github.com/vladmandic/sd-extension-chainner/issues/6.

Only positive values were normalized before, not negative ones.

Notes

Offset approach: Adding the absolute of the min-value (negative) to the whole tensor/image and then normalizing resulted in a grayish dull image. --> not used Clamping approach: Best/proper results were achieved by just 'clamping' all negative clipping values to zero. --> implemented

Before

tmp43c8uocw

After

tmpdrsqc3tn

MaxJa4 commented 1 year ago

Dark images seem fixed, but regular / bright images lack brightness after the normalization. Investigating.

MaxJa4 commented 1 year ago

Turns out, the chainner function to_uint8 already has a normalization function - it just wasn't used. I did the same as the internal normalization now does, just re-implemented. Then I found out about it. Now, the black/white clipping is gone without any brightness issues.

Comparison:

  1. Original code before PR
  2. Original change by this PR (first commit) --> brightness issue, clipping fixed
  3. Current, final state (last commit) --> no clipping or brightness issue
  4. Standard non-chainner upscaler for reference

Note: All chainner upscalers are fixed now, I just applied it to some in this example to show the difference.

tmp5i4r44fd

Done from my side.

MaxJa4 commented 1 year ago

Just saw that you already found the issue. My last commit still used the numpy to_uint8 and not the chainner one. This PR can be closed now, I suppose.