RetouchPRO

Go Back   RetouchPRO > Technique > Photo Retouching
Register Blogs FAQ Site Nav Search Today's Posts Mark Forums Read


Photo Retouching "Improving" photos, post-production, correction, etc.

The Math Behind Photoshop's Unsharp Mask and Gauss

Reply
 
Thread Tools
  #11  
Old 04-28-2014, 12:54 PM
klev klev is offline
Senior Member
 
Join Date: Jun 2010
Posts: 1,109
Re: The Math Behind Photoshop's Unsharp Mask and G

Quote:
Originally Posted by Drazick View Post
Hi,
Photoshop doesn't allow Subtract and Add in 32 Bit mode.

So, If I have the photos in MATLAB, how should recreate this?
Should I clip into [0, 255] / [0, 1] after each subtraction / addition?

It sounds weird that the code USM does clipping into [0, 1] / [0, 255] after each step.
Use layer blending modes linear dodge and subtract rather than apply image. I was completely serious that the way you're doing it mathematically unsound. Even if Adobe did something that way I wouldn't suggest it. It's because you're dealing with unevenly spaced values using a blending mode that is designed for evenly spaced distributions. As mentioned photoshop isn't exactly the place if you want to really see the underlying math. If you plan to make adjustments to images with gamma encoded, you have to account for that. Even in matlab, you can remove it, which some software does internally due to some programs being based around linear calculations. If you plan to address linear values, which is really quite a bit easier, both the image itself and the workspace have to be that way, and you have to to verify it.

Oh as far as clipping I'm not sure how I would approach that one if the clipping is necessary. IT depends on the final destination of that tool. If it is to be applied in 8 and 16 bit integer modes, you do have the issue of overflow. There isn't a good way to store anything beyond that without introducing a very large performance hit, so I doubt Adobe does so. I have to assume they're packed in some way so as to store more than one 8 bit pixel in a given register either by packing channels (RGBA) at a given index or tiled when it comes to making general computation that is to be performed by a cpu.

Last edited by klev; 04-28-2014 at 01:02 PM.
Reply With Quote top
  #12  
Old 04-28-2014, 03:56 PM
klev klev is offline
Senior Member
 
Join Date: Jun 2010
Posts: 1,109
Re: The Math Behind Photoshop's Unsharp Mask and G

I'm just going to add that clipping at every step actually introduces a lot of artifacts. Trying to reproduce this is just the worst possible idea. Adobe's algorithms have been updated to a degree over time. Their early ones were really based on what was available. They had to work with a limited range of values and severe performance constraints. People older than myself have indicated just how long it took to apply certain filters or transformations in the era of Photoshop versions 2 - 3. If you really wanted to do this, you should try a linear raw processor like dcraw or darktable, preferably one that can process to an exr, as they recognize a specific sign bit. Take that. Correlate it with something like a munsell greyscale system to ensure you have a reasonable gain. Take that into matlab. Research your algorithms from there. Apply the sharpening before gamma. Evaluate both visually and numerically to ensure against corner case issues where the data blows up. From there is this is to be applied normally to lower dynamic range gamma encoded data, you want to attempt to match those initial results with something that can be applied to gamma encoded data, meaning you can no longer use add and subtract.

That's a bit more detailed explanation, but I have to ask, do you have any programming experience or math background? Graphics are one of the most math heavy areas of programming in general. Coming up with a new sharpening algorithm would be way beyond my own comfort level, as you have to account for the issue of ringing/haloing and over what radius it would be acceptable. Typically that is what is happening, but it doesn't matter as long as the viewer can't perceive it. If I wanted to do what you're attempting, I would be looking at existing research on the topic, as I don't think you'll learn anything from the way you're going about it.
Reply With Quote top
  #13  
Old 04-28-2014, 04:04 PM
Drazick's Avatar
Drazick Drazick is offline
Junior Member
 
Join Date: Nov 2008
Posts: 24
Re: The Math Behind Photoshop's Unsharp Mask and G

Klev,
I really don't understand you.
I showed you how Adobe Photoshop creates USM using Gaussian Blur.
The way I showed is 100% identical (Put it on difference mode and see everything is zero).

Now, if no clipping is done all sums up that USM(O) = 3O - 2B.
If clipping is done, this is explanation why doing O + 2(O-B) using Apply Image doesn't reproduce the same effect.

This is the contradiction I'm after.

Adobe applies all filter on the image on screen.
No need to do Gamma inversion for those kind of filters.
Reply With Quote top
  #14  
Old 04-28-2014, 04:45 PM
Drazick's Avatar
Drazick Drazick is offline
Junior Member
 
Join Date: Nov 2008
Posts: 24
Re: The Math Behind Photoshop's Unsharp Mask and G

Regarding your question, I have math background mainly with MALTAB programming skills.

Now my problem mainly deals with how does Photoshop translates the user's Radius parameter into the size of the Gaussian Blur Filter and its Standard Deviation (Sigma).

I'm pretty sure the use some approximation for the Gaussian Blue (IIR or Box Filters).

Yet still I wonder how they translates the parameter.
Reply With Quote top
  #15  
Old 04-28-2014, 04:47 PM
klev klev is offline
Senior Member
 
Join Date: Jun 2010
Posts: 1,109
Re: The Math Behind Photoshop's Unsharp Mask and G

Quote:
Originally Posted by Drazick View Post
Klev,
I really don't understand you.
I showed you how Adobe Photoshop creates USM using Gaussian Blur.
The way I showed is 100% identical (Put it on difference mode and see everything is zero).

Now, if no clipping is done all sums up that USM(O) = 3O - 2B.
If clipping is done, this is explanation why doing O + 2(O-B) using Apply Image doesn't reproduce the same effect.
Don't mind me. I noticed my posts have taken on a grumpy tone today, although that wasn't intentional. Strangely I didn't think of difference mode. As mentioned they would have to clip at typical bit depths due to no way of otherwise handling out of range values.


Quote:
Originally Posted by Drazick View Post
This is the contradiction I'm after.

Adobe applies all filter on the image on screen.
No need to do Gamma inversion for those kind of filters.
Ahh they do hack some things a bit that way, such as screen blending, which uses strange math. I actually said they formulate it to work on gamma encoded images. I just added that it can produce a certain number of artifacts due to the nature of what is being done.
Reply With Quote top
Reply

  RetouchPRO > Technique > Photo Retouching


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 06:38 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
Copyright © 2016 Doug Nelson. All Rights Reserved