# How to simulate a better lens blur, i.e. in linear space, with Gimp?

Human perception of intensity is proportional to the logarithm of the physical intensity. When light from an image enters our eyes, we do not perceive the changes in brightness proportionally, but rather proportionally to their logarithm. However, the real physical process of dispersion of light by a lens does not care about how our eyes and brain work. Which means that computer algorithms trying to simulate the effect of blurring a sharp contour should operate after translating first the intensity values to linear space. However, it seems they don't, and that is the origin of the fake dark stripe that appears after doing, e.g., a "photo blur" with Gimp on an image like this one:

This effect is explained by this youtuber here. And, while this usually goes unnoticed unless you are blurring a picture of the flag of Portugal, I wonder how to do a less unrealistic lens blur using Gimp. The stress is on the words "less unrealistic" because the subject seems to be quite complex, but at least a quadratic average of the RGB values seems to give better results in the examples shown on the YouTube video referenced above.

Remark

I am using GIMP 2.8.18 which is somewhat outdated.

• In fact good editors do this but not sure that GIMP is a good editor – joojaa Dec 2 '18 at 13:19
• I remember a similar post... Let's see if someone can find it... – Rafael Dec 2 '18 at 14:38

AFAIK there is no "photo blur" in Gimp itself (there is a "Focus blur" plugin).

In Gimp 2.10 the Gaussian blur (and other blurs: motion, rotation, zoom) works in Linear space (even if the image itself is in "gamma" mode):

• If you want to download the comparison image I have posted in my answer, include it in yours, and add a brief explanation, I will delete everything in my question starting from the word "remark" and on. – Mephisto Dec 6 '18 at 12:27
• Replaced with side-by-side comparison – xenoid Dec 6 '18 at 12:45

Even in editors that do not have color correct filter facilities its possible to do the following.

1. (optional) Convert image to higher bit depth
2. Convert to linear space, with one of following methods
• With either profile to profile conversion (to a linear space with similar color primaries as your original)
• Un-gamma correct by inverting picture and applying gamma (note there is a likelihood this wont work since many software use a small linear portion in the color slope instead of doing gamma for the full range), then invert again.
• Or use a cheap trick and apply 1/your gamma.
3. Apply filter
4. Then apply either
• A profile to profile conversion
• or just gamma correct back with same samme you used previously

Done