unsharp parameters: GIMP > IM
 GreenKoopa
 Posts: 457
 Joined: 20101104T17:24:0807:00
 Authentication code: 8675308
unsharp parameters: GIMP > IM
Does anyone know how to translate the parameters from GIMP'S Unsharp Mask to IM's unsharp operation?
IM's unsharp operation has the parameters radius, sigma, gain, and threshold.
http://www.imagemagick.org/script/comma ... hp#unsharp
radius (default=0 to calculate based on sigma, rarely needs to be set)
sigma
gain (default=1.0)
threshold (default=0.05)
GIMP's unsharp has the parameters radius, amount, and threshold.
radius = 0.1500.0 (default=5.0)
amount = 0.0010.00 (default=0.50)
threshold = 0255 (default=0)
Threshold seems obvious, simply divide by 255. But the others?
First I found
http://www.imagemagick.org/Usage/resize/#resize_unsharp
which suggested that
im_radius = gimp_radius
im_sigma = gimp_amount
This doesn't appear to be correct.
Then I found
http://www.imagemagick.org/Usage/blur/#unsharp
which states that
im_sigma = gimp_radius + 1 (or maybe sqrt(gimp_radius))
im_gain = gimp_amount
This appears closer, but still not correct.
I experimented a little but didn't find an obvious relationship. Does anyone already know, or have an idea on the best way to continue experimenting? I am new to sharpening.
I have read that Photoshop and GIMP use the same parameters, but I don't have Photoshop to verify.
GIMP 2.8.6
ImageMagick 6.8.63
IM's unsharp operation has the parameters radius, sigma, gain, and threshold.
http://www.imagemagick.org/script/comma ... hp#unsharp
radius (default=0 to calculate based on sigma, rarely needs to be set)
sigma
gain (default=1.0)
threshold (default=0.05)
GIMP's unsharp has the parameters radius, amount, and threshold.
radius = 0.1500.0 (default=5.0)
amount = 0.0010.00 (default=0.50)
threshold = 0255 (default=0)
Threshold seems obvious, simply divide by 255. But the others?
First I found
http://www.imagemagick.org/Usage/resize/#resize_unsharp
which suggested that
im_radius = gimp_radius
im_sigma = gimp_amount
This doesn't appear to be correct.
Then I found
http://www.imagemagick.org/Usage/blur/#unsharp
which states that
im_sigma = gimp_radius + 1 (or maybe sqrt(gimp_radius))
im_gain = gimp_amount
This appears closer, but still not correct.
I experimented a little but didn't find an obvious relationship. Does anyone already know, or have an idea on the best way to continue experimenting? I am new to sharpening.
I have read that Photoshop and GIMP use the same parameters, but I don't have Photoshop to verify.
GIMP 2.8.6
ImageMagick 6.8.63
Re: unsharp parameters: GIMP > IM
I am now a proud owner of Photoshop although I have done very little with it yet!!
It has the options of Amount, Radius and Threshold for the unsharp mask. That is Percent, pixels and levels.
It has the options of Amount, Radius and Threshold for the unsharp mask. That is Percent, pixels and levels.

 Posts: 11225
 Joined: 20100123T23:01:3307:00
 Authentication code: 1151
 Location: England, UK
Re: unsharp parameters: GIMP > IM
Hmm. With Gimp Amount=1.00, Threshold 0:
Gimp radius 2 is close to IM 9x3
Gimp radius 4 is close to IM 15x5
Make of that what you will.
Gimp radius 2 is close to IM 9x3
Gimp radius 4 is close to IM 15x5
Make of that what you will.
snibgo's IM pages: im.snibgo.com
 GreenKoopa
 Posts: 457
 Joined: 20101104T17:24:0807:00
 Authentication code: 8675308
Re: unsharp parameters: GIMP > IM
That supports im_sigma = gimp_radius + 1? But if the range of gimp_radius is 0.1500.0, then the range of im_sigma would be 1.1501. What is a generally useful range for im_sigma?

 Posts: 11225
 Joined: 20100123T23:01:3307:00
 Authentication code: 1151
 Location: England, UK
Re: unsharp parameters: GIMP > IM
I don't normally use IM larger than 0x2. Larger radii don't change the sharpening of fine detail, but do sharpen (ie increase contrast) at larger levels of detail. 0x5 makes photos look horrible, because it generates spurious detail that distracts from real detail. But increasing to much higher values, eg 300x100, looks okay because we don't really notice the effect at such long wavelengths. However, Gimp at radius 100 looks different to IM 300x100; the fine detail in Gimp looks sharper.
snibgo's IM pages: im.snibgo.com
 GreenKoopa
 Posts: 457
 Joined: 20101104T17:24:0807:00
 Authentication code: 8675308
Re: unsharp parameters: GIMP > IM
I did some testing for GIMP Radius = 0.5  6 and Amount = 1  6. I have determined that GIMP Amount is exactly the same parameter as IM Gain. IM Sigma is GIMP Radius plus not quite one, and IM radius is twice that. I find it strange that GIMP calls a parameter radius when pixels 2*(radius+1) distant are changed. I also noticed that GIMP has unnecessarily huge rounding errors (it's 8bit) for large Amounts/Gains.
So this documentation is incorrect
http://www.imagemagick.org/Usage/resize/#resize_unsharp
The "GIMP" default for unsharp is equivalent to "unsharp 5x0.5"
really should read
The "GIMP" default (radius=5, amount=0.5, threshold=0) for unsharp is equivalent to "unsharp 12x6+0.5+0"
and this is correct (other than ignoring that GIMP sets a hard radius at twice sigma)
http://www.imagemagick.org/Usage/blur/#unsharp
So this documentation is incorrect
http://www.imagemagick.org/Usage/resize/#resize_unsharp
The "GIMP" default for unsharp is equivalent to "unsharp 5x0.5"
really should read
The "GIMP" default (radius=5, amount=0.5, threshold=0) for unsharp is equivalent to "unsharp 12x6+0.5+0"
and this is correct (other than ignoring that GIMP sets a hard radius at twice sigma)
http://www.imagemagick.org/Usage/blur/#unsharp
 anthony
 Posts: 8877
 Joined: 20040531T19:27:0307:00
 Authentication code: 8675308
 Location: Brisbane, Australia
Re: unsharp parameters: GIMP > IM
I have made the suggested correction. Should appear in a couple of hours
was it.. gimp_radius = 5, ==> IM_sigma = gimp_radius+1 ==> IM kernal radius = IM_sigma*2
NOTE: sigma*2 for the kernal radius (size fo the convolution kernel used) is a fairly good estimate, and generally good enough. However if set to zero, IM calculates the kernel size so that the kernel still have a greater than Qlevel quantum limit effect on the image, at the extreme edge of the kernel. As such it is variable and based on sigma and the Quality of your IM. The function is a standard 'Graphics Gem' (from the books of the same name).
However how did you arrive at this?The "GIMP" default (radius=5, amount=0.5, threshold=0) for unsharp is equivalent to "unsharp 12x6+0.5+0", and this is correct (other than ignoring that GIMP sets a hard radius at twice sigma). However remeber you really do not need to specify the kernel radius in ImageMagick, so a value of "unsharp 0x6+0.5+0" will work better.
was it.. gimp_radius = 5, ==> IM_sigma = gimp_radius+1 ==> IM kernal radius = IM_sigma*2
NOTE: sigma*2 for the kernal radius (size fo the convolution kernel used) is a fairly good estimate, and generally good enough. However if set to zero, IM calculates the kernel size so that the kernel still have a greater than Qlevel quantum limit effect on the image, at the extreme edge of the kernel. As such it is variable and based on sigma and the Quality of your IM. The function is a standard 'Graphics Gem' (from the books of the same name).
Anthony Thyssen  Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
 fmw42
 Posts: 24474
 Joined: 20070702T17:14:5107:00
 Authentication code: 1152
 Location: Sunnyvale, California, USA
Re: unsharp parameters: GIMP > IM
I have my doubts that GIMP would use an equivalent value such as 5x0.5. If one is using a Gaussian filter, then the radius usually should be about r=3*sigma. Otherwise if smaller, it gets truncated before it reaches near zero and loses effectiveness. Your value of 5x0.5 is way too large a radius and thus is very time wasteful. A value for r > about 1.5, in this case would probably not be noticeably different than 0x0.5 (where r=0 means have IM automatically compute the radius, which is something like r=2*sigma+1).Greenkoopa wrote:The "GIMP" default for unsharp is equivalent to "unsharp 5x0.5"
Note r=2*sigma covers 95% and r=3*sigma covers 99.7% of the area of the Gaussian distribution. see http://en.wikipedia.org/wiki/Normal_distribution
Last edited by fmw42 on 20130728T21:52:0507:00, edited 3 times in total.
 anthony
 Posts: 8877
 Joined: 20040531T19:27:0307:00
 Authentication code: 8675308
 Location: Brisbane, Australia
Re: unsharp parameters: GIMP > IM
As I said that that code has been replaced (It also came from a much older forum topic!)
As a side note. The Gaussian Resize Filter (default gaussian sigma = 0.5) uses a 'Support Window Radius' of 2.0
Which is 4 times the sigma. That is more for 'ease of use' however. Very old versions of IM used a radius of 1.25 which caused sharp 'ringing' effects in it convolutions, and then 1.5 or 3*radius whcih had practically unnoticable effects.
You can see a graph of a 1.25 support radius (2.5 times sigma) in...
http://www.imagemagick.org/Usage/filter/#support
It is a noticeable cutoff, and did produce noticeable ringing effects.
Now resize filters differ from 'normal' convolution in that the 'lookups' are not grid aligned, whcih is why a mathematical function, or large (1000+ entry) lookup tables, are used for resize and image distortions. Convolution (like unsharp) is grid aligned, so a 'kernel' or array of sampling weights, is precalculated. But the same cutoff (kernel radius), factors still applies. Users either specify that radius, or let IM calculate a radius that is limited by a 'negligible integer effect' for that radius.
As a side note. The Gaussian Resize Filter (default gaussian sigma = 0.5) uses a 'Support Window Radius' of 2.0
Which is 4 times the sigma. That is more for 'ease of use' however. Very old versions of IM used a radius of 1.25 which caused sharp 'ringing' effects in it convolutions, and then 1.5 or 3*radius whcih had practically unnoticable effects.
You can see a graph of a 1.25 support radius (2.5 times sigma) in...
http://www.imagemagick.org/Usage/filter/#support
It is a noticeable cutoff, and did produce noticeable ringing effects.
Now resize filters differ from 'normal' convolution in that the 'lookups' are not grid aligned, whcih is why a mathematical function, or large (1000+ entry) lookup tables, are used for resize and image distortions. Convolution (like unsharp) is grid aligned, so a 'kernel' or array of sampling weights, is precalculated. But the same cutoff (kernel radius), factors still applies. Users either specify that radius, or let IM calculate a radius that is limited by a 'negligible integer effect' for that radius.
Anthony Thyssen  Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
 fmw42
 Posts: 24474
 Joined: 20070702T17:14:5107:00
 Authentication code: 1152
 Location: Sunnyvale, California, USA
Re: unsharp parameters: GIMP > IM
I suspect that you/GIMP are using radius to mean different things. I suspect that should really be 2*(sigma+1).Greenkoopa wrote:I find it strange that GIMP calls a parameter radius when pixels 2*(radius+1) distant are changed.
My comment above that IM uses something like 2*sigma+1 may be 2*(sigma+1). I do not know, one would need to check the IM code to verify.
 anthony
 Posts: 8877
 Joined: 20040531T19:27:0307:00
 Authentication code: 8675308
 Location: Brisbane, Australia
Re: unsharp parameters: GIMP > IM
fmw42 wrote:My comment above that IM uses something like 2*sigma+1 may be 2*(sigma+1). I do not know, one would need to check the IM code to verify.
IM calculates, maximum radius that will provide at least a single quantum effect for each convolution element. That is that every element has at least a gaussian_weighting_ from_sigma * QuantumRange_for_integer >= 1.0
This is not a linear function due to the dependence of sigma, but is typically larger than 3
You can check it using the 'show kernel' define in morphology.
for 2pass 1D blurs, on a IM Q16 using a sigma of 5 we get...
Code: Select all
convert null: define showkernel=1 morphology Convolve Blur:0x5 null:
Code: Select all
Kernel "Blur" of size 41x1+20+0 with values from 0 to 0.0796737
Forming a output range from 0 to 1 (Normalized)
...(kernel values)...
(actually you could just look at 'origin offset' into the kernel )
For a sigma of 10 I get a radius of 38 (a little less than 4 times)
and sigma 100 => radius 333
I did say this was not a linear calculation, which is why it is calculated using a very fast 'trial and error' function.
Note this would be much smaller for a IM Q8, and much larger for a Q32 or Q64.
For HDRI it would be the same as Q16.
For 2D kernels (whcih may be what unsharp uses?) the calculated radius is a bit different (slight formula difference)
Code: Select all
convert null: define showkernel=1 morphology Convolve Gaussian:0x5 null:
Code: Select all
Kernel "Gaussian" of size 35x35+17+17 with values from 0 to 0.006372
....
sigma of 10 => radius of 30
sigma of 100 => radius is 112
So using a radius = sigma*3 is selling yourself a little short in terms of accuracy, but it does make processing faster and is not really noticeable except by looking at actual numbers around a blackwhite boundary.
using radius = sigma*2 would probably be noticeable in flicker compares, but is still not really a major difference. It is however enormously faster to process, especially with 2D convolutions which I believe unsharp uses. I don't think the convolution is separatable (1d 2pass) unless you just blur and do the subtraction separate to the convolution.
I do not remember how IM unsharp does it.
Anthony Thyssen  Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
 fmw42
 Posts: 24474
 Joined: 20070702T17:14:5107:00
 Authentication code: 1152
 Location: Sunnyvale, California, USA
Re: unsharp parameters: GIMP > IM
Thanks for the good information about what IM does. Just for curiosity I tried using sigma=0.5
Thus (51)/2=2 for the radius.
And for 2D
Thus again (51)/2=2 for the radius.
So both give 4*sigma, for this case.
So from Anthony's analysis and mine, it looks like for 2D (which I believe is what unsharp uses) for small sigma (around 1), the radius is about 4*sigma. For moderate sigma around 510, radius is about 3*sigma. For very large sigma, radius is closer to 1*sigma. However, the latter surprises me as that means that it does not roll off to near zero, so it won't be as effective as it it could be for larger ratio. But I guess by that size it is getting impractically slow anyway.
Code: Select all
convert null: define showkernel=1 morphology Convolve Blur:0x0.5 null:
Kernel "Blur" of size 5x1+2+0 with values from 0 to 0.691892
And for 2D
Code: Select all
convert null: define showkernel=1 morphology Convolve Gaussian:0x0.5 null:
Kernel "Gaussian" of size 5x5+2+2 with values from 0 to 0.618694
So both give 4*sigma, for this case.
So from Anthony's analysis and mine, it looks like for 2D (which I believe is what unsharp uses) for small sigma (around 1), the radius is about 4*sigma. For moderate sigma around 510, radius is about 3*sigma. For very large sigma, radius is closer to 1*sigma. However, the latter surprises me as that means that it does not roll off to near zero, so it won't be as effective as it it could be for larger ratio. But I guess by that size it is getting impractically slow anyway.
 anthony
 Posts: 8877
 Joined: 20040531T19:27:0307:00
 Authentication code: 8675308
 Location: Brisbane, Australia
Re: unsharp parameters: GIMP > IM
Note he reason the radius gets smaller for large sigma is actullay because you have more and more elements that the weighting is to be distributed across. So the weighting gets smaller, That means the quantum effects from a weighting (even though calculations are done using floating point) gets more pronounced, and in the end you have diminishing returns on larger and larger radii. Basically very complex nonlinear effects.fmw42 wrote:So from Anthony's analysis and mine, it looks like for 2D (which I believe is what unsharp uses) for small sigma (around 1), the radius is about 4*sigma. For moderate sigma around 510, radius is about 3*sigma. For very large sigma, radius is closer to 1*sigma.
However enough of this... getting back on topic.
IM unsharp does not need a radius, just the sigma, gain, and threshold, and what GIMP calls radius is really related (somehow) to sigma.
Anthony Thyssen  Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
 GreenKoopa
 Posts: 457
 Joined: 20101104T17:24:0807:00
 Authentication code: 8675308
Re: unsharp parameters: GIMP > IM
GreenKoopa wrote: I did some testing for GIMP Radius = 0.5  6 and Amount = 1  6. I have determined that GIMP Amount is exactly the same parameter as IM Gain. IM Sigma is GIMP Radius plus not quite one, and IM radius is twice that. I find it strange that GIMP calls a parameter radius when pixels 2*(radius+1) distant are changed. I also noticed that GIMP has unnecessarily huge rounding errors (it's 8bit) for large Amounts/Gains.
Seemed to be. I created an image that was one edge, with the left half dark and the right half light. I sharpened this test image using GIMP. I then took the middle row and graphed the pixel values. It is easy to see the radius, simply count how far out pixels changed. With the IM radius set, I varied sigma until the graphs matched. It was sigma = GIMP Radius + almost 1, which was half the previously noted radius. I ran tests through the ranges noted above.anthony wrote: However how did you arrive at this?
was it.. gimp_radius = 5, ==> IM_sigma = gimp_radius+1 ==> IM kernal radius = IM_sigma*2
 anthony
 Posts: 8877
 Joined: 20040531T19:27:0307:00
 Authentication code: 8675308
 Location: Brisbane, Australia
Re: unsharp parameters: GIMP > IM
Fair enough method...GreenKoopa wrote: Seemed to be. I created an image that was one edge, with the left half dark and the right half light. I sharpened this test image using GIMP. I then took the middle row and graphed the pixel values. It is easy to see the radius, simply count how far out pixels changed. With the IM radius set, I varied sigma until the graphs matched. It was sigma = GIMP Radius + almost 1, which was half the previously noted radius. I ran tests through the ranges noted above.
I wonder however if Gimp is using a 2pass blur and subtraction method instead of a allinone convolve.
It would make some sense as a threshold option needs a comparison with original image to determine if pixel is to change or not. That is whether this is a edge to sharpen or just a 'wrinkle' that you don't want to sharpen.
Anthony Thyssen  Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/