Luminous Landscape Forum
Raw & Post Processing, Printing => Digital Image Processing => Topic started by: Drazick on April 27, 2014, 04:34:15 pm
-
Hello,
Has anyone succeeded in reproducing Photoshop's Gaussian Blur and Unsharp Mask?
I have a technique to apply a really nice Local contrast Enhancer based on Unsharp Mask yet I have to reproduce Photoshop's first.
I reproduce Photoshop's Unsharp Mask using some math on layers and the Gaussina Blur.
Assuming 'O' is the layer we want to apply USM on then:
USM('O') = O + (O-GB) - inv(O + inv(GB))
Where GB stands for a Gaussian Blurred version of O.
Subtractions and Addition can be done using Photoshop's 'Apply Image' command.
As you can see this is not the "Classic" Unsharp Mask.
Has anyone reproduced it in C / Python / MATLAB?
Thank You.
-
Actually, there isn't one single algorithm in Photoshop G-Blur...there are three of them based on the radius that is set. I used to know the breakdowns of when one algorithm transitioned to another algorithm, but that was a long time ago and before G-Blur radius was upped to beyond 250 pixels. So there may now be 4 algorithms that go up to 1000 pixels.
In terms of USM, I'm pretty sure the G-Blur algorithms are also used as is feathering in Photoshop.
So, trying to exactly duplicate the effects of G-Blurr may be more difficult...you might want to ask on the Adobe Photoshop User to User forums where a couple of Photoshop engineers hang out but I suspect that they be reluctant to say too much :~)
-
Hi,
Assume I have Photoshop's Gaussian Blur.
How mathematically I can replicate its Unsharp Mask?
I'll explain what doesn't add for me.
Given a layer O.
Its Gaussian Blu Version is given by GB.
Now, using Apply Image and building the required intermediate layers I can replicate USM by:
USM('O') = O + (O-GB) - inv(O + inv(GB))
Assuming layers are normalized into [0, 1] and I think the inverse of a layer L is given by inv(L) = 1 - L we get:
USM('O') = O + (O-GB) - inv(O + inv(GB)) = 3*O - 2*GB
Which doesn't make sense.
When I try it in MATLAB I get results completely different.
How come? What am I missing?
-
Actually, there isn't one single algorithm in Photoshop G-Blur...there are three of them based on the radius that is set. I used to know the breakdowns of when one algorithm transitioned to another algorithm, but that was a long time ago and before G-Blur radius was upped to beyond 250 pixels. So there may now be 4 algorithms that go up to 1000 pixels.
In terms of USM, I'm pretty sure the G-Blur algorithms are also used as is feathering in Photoshop.
So, trying to exactly duplicate the effects of G-Blurr may be more difficult...you might want to ask on the Adobe Photoshop User to User forums where a couple of Photoshop engineers hang out but I suspect that they be reluctant to say too much :~)
Hi,
Do you think you figured out the relation between the user input (Radius) and the kernel used for Gaussian Blur?
I mean, the Gaussian Kernel is built by 2 parameters: the radius of the filter and the Standard Deviation of the Gaussian Function.
does anyone know how those are calculated given the user input for Radius?
-
Hi,
Do you think you figured out the relation between the user input (Radius) and the kernel used for Gaussian Blur?
I mean, the Gaussian Kernel is built by 2 parameters: the radius of the filter and the Standard Deviation of the Gaussian Function.
does anyone know how those are calculated given the user input for Radius?
Hi,
I don't think it is formally published information, so one would have to reverse engineer the behavior to get an idea. Maybe someone has, I do not know if that is the case, but it doesn't look like a straight forward Gaussian implementation, just like the PS bi-cubic interpolation is not straightforward bi-cubic, and 16-bit is not straightforward 16-bit.
However, maybe they are using a somewhat similar approach as ImageMagick does (http://www.imagemagick.org/Usage/blur/#blur_args) (although Photoshop usually cuts a few corners for speed purposes), specifying only a 'radius' actually sets the Gaussian sigma (standard deviation) which restricts the '0x' kernel radius size to 3x the sigma for 16-bit data, less for 8-bit data. Thus, the kernel size is implicitly specified by the range of significant contributions.
Maybe the radius is the FWHM (Full Width Half Maximum amplitude) size of the used sigma and not the full sigma, who knows ... Adobe moves in strange ways.
Cheers,
Bart
-
Hi Bart,
I tried using the Radius as the Standard Deviation (Sigma) of the Gaussian Kernel and ceil(3 * Radius) as the Radius of the filter.
I get results which are way more blurred than Photoshop.
Any idea how to reverse engineer it?
I tried Impulse Response, with no conclusions.
-
Hi Bart,
I tried using the Radius as the Standard Deviation (Sigma) of the Gaussian Kernel and ceil(3 * Radius) as the Radius of the filter.
I get results which are way more blurred than Photoshop.
Maybe a mix-up between radius and diameter?
Any idea how to reverse engineer it?
I haven't given the specific Photoshop implementation too much thought, because I create my own blur and deconvolution kernels (http://bvdwolf.home.xs4all.nl/main/foto/psf/PSF_generator.html) and use them in various other software applications.
A Java application like ImageJ allows to do all sorts of operations and analyses. Maybe you can use it, if you don't have more suitable tools, to analyze the results of a Gaussian blur in Photoshop, and fit a model that corresponds to another function specification. You may also want to try fitting a Moffat distribution (http://en.wikipedia.org/wiki/Moffat_distribution) because that allows to influence the kurtosis of the Gaussian distribution.
Here (http://pixinsight.com/doc/tools/DynamicPSF/DynamicPSF.html) is some more info on how a Moffat distribution is used in an Astro Photography software package.
Cheers,
Bart
-
Hi,
I have MATLAB.
But even looking at the Impulse Response of the filter using 32 Bit Image wasn't conclusive.
I have MATLAB, nothing it better for that :-).
-
I have MATLAB, nothing it better for that :-).
In that case, I suggest to first compare the NormCDF (http://www.mathworks.com/help/stats/normcdf.html?nocookie=true) (in a 2D version) with the shape of the PS Gaussian blur, and see if it can come close. 'NormFit' may be useful, from what I see.
Cheers,
Bart
-
Hi,
Assume I have Photoshop's Gaussian Blur.
How mathematically I can replicate its Unsharp Mask?
I'll explain what doesn't add for me.
Given a layer O.
Its Gaussian Blu Version is given by GB.
Now, using Apply Image and building the required intermediate layers I can replicate USM by:
USM('O') = O + (O-GB) - inv(O + inv(GB))
Assuming layers are normalized into [0, 1] and I think the inverse of a layer L is given by inv(L) = 1 - L we get:
USM('O') = O + (O-GB) - inv(O + inv(GB)) = 3*O - 2*GB
Which doesn't make sense.
When I try it in MATLAB I get results completely different.
How come? What am I missing?
I don't think your result 3*O - 2*GB is mathematically correct.
The problem appears to be how you evaluate inv(O+inv(GB)).
Consider the trivial example: inv(4+inv(1/2))=inv(6) not the same as 1/4+2
-
Hi,
Do you agree that for any layer L that inv(L) = White - L?
USM(O) = O + (O - B) - inv(O + inv(B)) = 2O - B - inv(O + White - B) = 2O - B - (White - O - White + B) = 2O - B - White + O + White + B = O + 2 (O - B).
Again, this is right assuming no clipping of the image.
Where do you think I'm wrong?
-
So, there's a thread on the Photoshop User to User forum...is that you? Here's the thread that Chis Cox has answered in. Reproduce Unsharp Mask Using Gaussian Blur (http://forums.adobe.com/message/6332605#6332605)
-
I do not know about the exact photoshop algorithm. But if you want code and an explanation of Unsharp Mask in C# check out http://www.codeproject.com/Articles/44115/ImageMagic-WPF-Image-Sharpening
Its slow but the results are fairly good.
-
Hi,
Actually I managed to replicate Photoshop's USM almost perfectly.
It works just as I wrote above.
It just happens that Photoshop Clips into the [0, 1] range after every addition / subtraction.
Since it clips I can not do the math tricks to get the simple equation (Unless no clipping happened).
Tell you the truth, now that I know how it works and employing a much better smoothing operator I'm working on coding "Super USM", simple plugin for a much better USM.