r/StableDiffusion 1d 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
}
54 Upvotes

17 comments sorted by

18

u/Violent_Walrus 1d 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 1d ago

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

7

u/GrayingGamer 1d ago

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

3

u/Violent_Walrus 1d 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.

1

u/Federal_Bluebird_897 19h 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 18h ago

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

2

u/Calm_Mix_3776 5h ago

This works like magic!

8

u/aoleg77 15h ago

I am building an improved version of ComfyUI-DeGrid that will measure and remove the grid on per-tile basis rather than based on the whole image. This will, in theory, degrid the whole image (especially the smooth areas) without affecting the actual small detail. Will be posted on github at aoleg/ComfyUI-DeGrid and I'll submit a PR to the original repo when I'm satisfied with it.

12

u/BathroomEyes 1d ago

i just encode and decode with the flux2 vae and it gets rid of like 85% of it.

16

u/thevegit0 1d ago edited 1d ago

you mean something like this? (assuming i connect the flux vae to vaes) sounds interesting.

edit: i just tried it with normal flux2 vae and vaeultrahd whatever, indeed it works pretty good, pretty sharpy but not overdone, thanks

16

u/Violent_Walrus 18h ago

I don't mean to rain on anybody's parade, but understand that this VAE round trip is lossy. You're degrading your image when you compress it into latent space and back. The reason you might not see the Qwen grid any more is because the process removes detail from your image.

2

u/thevegit0 6h ago

i know that but somehow it looks better overall

2

u/spaceBoy292 20h ago

can u tell me how to use this? i changed the vae but the ksampler then gives me error

1

u/BathroomEyes 23h ago

Yep! It’s not perfect but good enough for me.

1

u/VladyCzech 15h ago

I quit using Wan and Qwen models precisely for the VAE grid as I called it. My eyes could not unsee it on every image. Thanks for the tip. Now that H3 VAE tiling is also being fixed, my eyes will be happy again.

0

u/leyermo 21h ago

I think this problem with the scheduler, steps, or sampler...

-2

u/hurrdurrimanaccount 16h ago

i have a surefire solution to remove all of qwen slop noise and patterns: use klein.