Color smoothing algorithm

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Mar 29, 2013 at 00:01

I have some textures at 256x256 and each pixels have a different color from which, if you smooth the grains, it produces a pattern. Think of it as a photograph taken at night with a 1000 ISO film, which is very grainy. So I want to get rid of the grain while still keeping the overall details. I could use Gaussian blur, but the edges becomes darker, so if I tile the texture, I get a big seem! Does anyone have some recommendations as to how I should approach this? Thanks! (pressing the Enter key does not work in this message editor!!??)

9 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Mar 29, 2013 at 02:59

If the texture is designed to be tilable, then when calculating the Gaussian blur you should use wrap mode sampling. That should prevent the edges from becoming darker or forming seams.

A bilateral filter might be better for denoising an image, as it will do a better job of preserving sharp features - the Gaussian will blur the features just as it blurs the noise.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Mar 29, 2013 at 05:16

Seems like the filter I need, thanks. But it seems that I have to convert the rgb values to xyz then to lab (CIE-Lab color space), and the rgb values need to be 0.255. Is there a way to use hdr float values?

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Mar 29, 2013 at 05:48

A bilateral filter can work in RGB space just as well as XYZ. And I don’t know any reason it couldn’t work with HDR float values too. It measures the “distance” between the colors of two pixels to determine how much weight to give in the filter, and you can certainly measure distance between HDR colors. Although it might be visually better to take the log-luminance of the HDR floats before calculating the distance (just a guess).

B5262118b588a5a420230bfbef4a2cdf
0
Stainless 151 Mar 29, 2013 at 08:54

I don’t know if this will work, but it would be worth a try if you are up for it.

Treat each pixel as a 3d vector and calculate the angle between neighbours (dot product)

If this value is greater than some value, don’t blend.

I think that should keep the detail you want and give some smoothing where you do.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Mar 29, 2013 at 20:11

@Reedbeta

A bilateral filter can work in RGB space just as well as XYZ. And I don’t know any reason it couldn’t work with HDR float values too. It measures the “distance” between the colors of two pixels to determine how much weight to give in the filter, and you can certainly measure distance between HDR colors. Although it might be visually better to take the log-luminance of the HDR floats before calculating the distance (just a guess).

Is the code found here looks like the correct algo for this?

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Mar 29, 2013 at 20:14

@Stainless

I don’t know if this will work, but it would be worth a try if you are up for it.

Treat each pixel as a 3d vector and calculate the angle between neighbours (dot product)

If this value is greater than some value, don’t blend.

I think that should keep the detail you want and give some smoothing where you do.

Interesting! It seems to work quite well actually! Sometime, things are simpler than they seem. Have you tried it yourself?

It does not seem to work well on dead pixels. But that’s probably because I’m not sampling properly. Should I use a Gaussian way to sample the pixels? How would you do it?

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Mar 29, 2013 at 20:19

@Alienizer

Is the code found here looks like the correct algo for this?

Yes, that implements the filter I was thinking of, although only for a monochrome image. For an RGB image you’d calculate a distance between colors in RGB space to put into the “similarity” function.

Stainless, doesn’t your approach treat dark gray and white as being the same, since the angle between them would be zero? It would detect color edges, but still blur across luminance edges.

B5262118b588a5a420230bfbef4a2cdf
0
Stainless 151 Mar 30, 2013 at 09:27

Good point, maybe what you need is a combined angle and distance solution.

Calculate the angle with a dot product and the distance just by subtracting the vectors and calculating the length.

Might be a good idea to read up on colour quantization techniques, they must have the same problem.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Mar 30, 2013 at 17:35

Thanks guys.