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

[Bug] Add Noise node is way too powerful #3048

Open
Arcitec opened this issue Nov 3, 2024 · 1 comment · May be fixed by #3055
Open

[Bug] Add Noise node is way too powerful #3048

Arcitec opened this issue Nov 3, 2024 · 1 comment · May be fixed by #3055
Labels
bug Something isn't working

Comments

@Arcitec
Copy link

Arcitec commented Nov 3, 2024

Information:

  • Chainner version: Alpha 0.24.1

Description
When you want to add camera sensor noise to an image, you need fine control over the Gaussian noise.

ChaiNNer's Add Noise node is extremely heavy-handed. Even at the lowest value, 1, it adds waaaay too much noise to the image:

image

It seems like it might be throwing an integer into an algorithm that should be using a low-value float. The amount of noise it adds at the lowest setting is extreme!

The solution: Make the control even finer, by turning the INTEGER slider into a FLOAT slider.

I can perform a very slow workaround for this problem (it takes around 1 second to process this per image):

  • Get Dimensions node on the image I want noise on.
  • Create Noise node, with those dimensions as input. Scale: 1, Method: Simplex, Brightness: 2.0 (this controls how much noise; 2.0 adds a perceptible yet very subtle amount which makes images look realistic and not AI generated).
  • Blend Images node, base input: Original image. overlay input: The noise. Blend mode: Subtract.

It would be much better if the Add Noise node was fixed to use a working scale parameter, because Add Noise runs in a few milliseconds compared to 1 second for my workaround. :D

@Arcitec Arcitec added the bug Something isn't working label Nov 3, 2024
@Arcitec Arcitec changed the title [Bug [Bug] Add Noise node is way too powerful Nov 3, 2024
@Arcitec
Copy link
Author

Arcitec commented Nov 23, 2024

I have had a moment to look for the code and see how it works.

https://github.com/chaiNNer-org/chaiNNer/pull/1251/files

I can see that it seems to work as follows:

  • Chainner stores images as numpy arrays of floats in range 0.0, 1.0.
  • When generating noise, it takes the Amount slider (0-100 int) and divides it by 100, meaning the smallest value is 1 / 100 = 0.01.
  • The actual noise generation functions all take "amount" as a float.
  • To generate the noise, it uses numpy random functions to generate new numpy arrays with values in range 0.0, amount. This is basically the same as preparing an alpha blend ahead of time by making the max value really low.
  • To merge the noise, most of the algorithms just add the noise value onto the image pixel float values. So if the noise pixel is 0.45 and the original image pixel was 0.1, then the resulting value is 0.55. Any results above or below the 0.0, 1.0 float range is then clipped.
  • Most things about the algorithm are very clever and should be a good method of generating and alpha blending the noise. The problem is probably just the division factor. Think about it in terms of 0-255 range of normal uint8 image channels: 0.01 * 255 = 2.55. This means the smallest noise amount step is roughly 3 brightness steps on each pixel.

I will have to think about a solution when I have time.

Easiest would be to make the node input a float in range 0.0 - 100.0, so people can write whatever they want. By adding a single decimal to the slider, we make the noise pixel amount range go in steps of 0.1 / 100 = 0.001 instead, which represents 0.001 * 255 = 0.255 on the regular uint8 scale. So to go +1 on the uint8 scale, you would need to go +0.4 on the float value.

This solves it and makes the slider fine-grained enough to add fine grain. Badum-tish.

It would probably also be backwards compatible with old chainner chain configs that rely on the old values. So I favor this solution rather than making the slider longer and more divided.

When I have time, I will do some tests. So far this is theoretical and I am not at a computer. 😉

Arcitec added a commit to Arcitec/chaiNNer that referenced this issue Dec 5, 2024
…-org#3048)

Implements fine-grained control over the noise amount, by switching to a float-based noise multiplier instead.

(The previous implementation was only able to generate noise in increments of +2.55 on the 0-255 pixel luminance scale.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant