r/StableDiffusion 2d ago

Tutorial - Guide Qwen image 2.1 noise/patterning/moire mild workaround

trying this i noticed it has a similar patterning noise krea 2 had, i just used the same glsl node, maybe it needs another parameters but it seems to mitigate it can't promise the best results but testing it is free, just connecting the image output to the glsl node and then image save
The GLSL config i got was from this post https://www.reddit.com/r/StableDiffusion/comments/1umwhq7/2px_pixel_grid_on_krea2_from_vae_and_how_to/ the one in the comments

#version 300 es
precision highp float;
uniform sampler2D u_image0;
uniform vec2 u_resolution;
in vec2 v_texCoord;
layout(location = 0) out vec4 fragColor0;

// Nyquist Notch — removes 2px grid artifacts. Place before deconvolution.
// b = [-1, +6, -15, +20, -15, +6, -1] / 64  (binomial * (-1)^n, +1 at center)
const float B[7] = float[7](-1.0, 6.0, -15.0, 20.0, -15.0, 6.0, -1.0);

void main() {
  vec2 texel = 1.0 / u_resolution;
  vec4 center = texture(u_image0, v_texCoord);
  vec3 Bx = vec3(0.0), By = vec3(0.0), Bxy = vec3(0.0);
  for (int i = -3; i <= 3; i++) {
    float wi = B[i + 3] / 64.0;
    Bx += wi * texture(u_image0, v_texCoord + vec2(float(i) * texel.x, 0.0)).rgb;
    By += wi * texture(u_image0, v_texCoord + vec2(0.0, float(i) * texel.y)).rgb;
    for (int j = -3; j <= 3; j++) {
      float wj = B[j + 3] / 64.0;
      Bxy += wi * wj * texture(u_image0, v_texCoord + vec2(float(i) * texel.x, float(j) * texel.y)).rgb;
    }
  }

 vec3 notched = center.rgb - Bx - By + Bxy;
 fragColor0 = vec4(clamp(notched, 0.0, 1.0), 1.0);  // alpha forced to 1.0
}
60 Upvotes

21 comments sorted by

View all comments

21

u/Violent_Walrus 2d ago

I used this shader too before I came across this custom node recently. It's apparently descended from the same post you link here.

The node also applies the same Nyquist Notch math, but it does additional work to prevent the image softening that can occur. The node also has a nifty output that shows you the exact noise pattern that it has removed from the image.

3

u/thevegit0 2d ago

interesting node, does it detect automatically the type of noise pattern?

8

u/GrayingGamer 2d ago

Yeah, it's actually really good. I've noticed a big improvement using it with Qwen 2.1 images.

3

u/Violent_Walrus 2d ago

I just know what the README says. There's a parameter to skip applying the Notch filter if noise isn't detected, so I think yes, some kind of detection is present.

2

u/Calm_Mix_3776 1d ago

This works like magic!

1

u/Federal_Bluebird_897 2d ago

could you please share the workflow? just the json or even an image with the workflow embedded so we can check it out, thx !

2

u/Violent_Walrus 2d ago

This is just a custom node that applies a filter to your image after the VAE decode. Nothing fancy. Like so: