Jump to content
smadell

Saturation Masks - a simple method

Recommended Posts

I have been reading Dave Straker’s post about Saturation Masks, and the variety of methods he and others have used to construct them. In looking into this further, I stumbled across a web page written by Tony Kuyper, and he describes a really simple way of creating a Saturation Mask using a Selective Color adjustment layer. A link to his web page is included below:

http://goodlight.us/writing/saturationmasks/satmask-1.html

I have attached a Macros Category (import this from the “hamburger” menu on the Library panel) that includes 6 different macros.

Important Note - Because of a bug in the Selective Color adjustment layer, these macros will not work in version 1.6 of Affinity Photo. However, the apparent bug has been squashed in version 1.7, and the macros give the proper results. At this point, use the macros ONLY in the version 1.7 beta and, presumably, in any version which follows it.

Saturation Mask - Greyscale

This macro creates a greyscale version of a saturation mask, based on a “merge visible” pixel layer that takes all of the visible layers into account.

Vibrance Mask - Greyscale

This macro creates a greyscale version of a Vibrance Mask. A vibrance mask is the inverse of a saturation mask, and favors areas of relatively low saturation. Vibrance Masks can be used to apply adjustments, etc. to poorly saturated pixels, while masking that adjustment from highly saturated pixels.

Saturation Mask - Create Mask

This macro creates a Mask layer out of the greyscale version of the mask. The mask is placed at the top of the layer stack, and can be used as needed.

Vibrance Mask - Create Mask

Similar to the above, this macro creates a Mask layer out of the Vibrance Mask greyscale layer.

Fix OVER-Saturated Image

This macro puts a 50% grey fill layer at the top of the layer stack, and sets the Blend Mode to Saturation. Without anything further, this would have the effect of desaturating all of the colors in an image. However, the macro attaches a Saturation Mask to the fill layer, which desaturates the colors relative to their existing saturation level. (More highly saturated pixels are affected more strongly.) Finally, the macro asks the user “How much desaturation?” should be applied. This sets the opacity of the fill layer, and can change the amount of DE-saturation applied.

Fix UNDER-Saturated Image

This macro puts an HSL adjustment layer at the top of the layer stack, and attaches a Vibrance Mask to the adjustment. The macro asks the user “How much saturation?” and this affects the Saturation slider inside the HSL adjustment. The vibrance mask causes the HSL adjustment to be applied more strongly to pixels with low saturation, and minimizes its effect on highly saturated pixels.

Saturation Masks.afmacros.zip

Share this post


Link to post
Share on other sites

Most excellent. Thank you, smadell. I shall study closely.

I've been around this park on and off to the point where I've forgotten whether there is a definitive algorithm. With a single channel, presumably saturation is simply the value of each pixel in the channel, such are 'Red has a value of 157 out of a possible 255, so is 157/255 = 62.5% saturated'. The question is how saturation is calculated for three channels. Is it a simple average or is some weighting given to dominant colours or the spread of saturation across channels?

Edit: Having said this, this page (with due zero exception) suggests Saturation = ((max(R,G,B) - min(R,G,B))/max(R,G,B). Hmm. Rings a bell.


Dave Straker

Cameras: Sony A7R2, RX100V

Computers: Win10: Chillblast Photo with i7-3770 + 16Gb RAM + Philips 40in 4K; Surface Pro 4 i5

Favourite word: Aha. For me and for others.

Share this post


Link to post
Share on other sites

Hey, Dave...

You're being far more cerebral about this than I was - I'm not completely sure WHY this works, it's just that it does. I give a lot of credit to Tony Kuyper who realized this could be done in the first place, and that's why I linked to his post.

As to averages vs. weighting, I originally thought about using Apply Image and using Equations in the Lab color space. I was hoping to find a way to transfer saturation from the a and b channels into the L channel, while setting the a and b channels to 0. I have no idea if that will work, since the Selective Color Adjustment method kind of fell into my lap, and was so straightforward (or, shall I say, so easy) that I didn't do any investigation on the Apply Image idea.

However, I know that Lab color space is perceptually linear, so that saturation is a strict percentage rather than a weighted value. Beyond that, I just don't know.

- smadell

Share this post


Link to post
Share on other sites
1 minute ago, smadell said:

Hey, Dave...

You're being far more cerebral about this than I was - I'm not completely sure WHY this works, it's just that it does. I give a lot of credit to Tony Kuyper who realized this could be done in the first place, and that's why I linked to his post.

As to averages vs. weighting, I originally thought about using Apply Image and using Equations in the Lab color space. I was hoping to find a way to transfer saturation from the a and b channels into the L channel, while setting the a and b channels to 0. I have no idea if that will work, since the Selective Color Adjustment method kind of fell into my lap, and was so straightforward (or, shall I say, so easy) that I didn't do any investigation on the Apply Image idea.

However, I know that Lab color space is perceptually linear, so that saturation is a strict percentage rather than a weighted value. Beyond that, I just don't know.

- smadell

My brain hurts. Too much cerebration? :)

Mmm. LAB. Kind of emulates the opponent-process that the eye uses to send RGB info from cones back into the brain. And then we get into perceptual stuff, which is delightfully confusing. The collision of technology, psychology and colour is a fascinating world I'm still wandering around.


Dave Straker

Cameras: Sony A7R2, RX100V

Computers: Win10: Chillblast Photo with i7-3770 + 16Gb RAM + Philips 40in 4K; Surface Pro 4 i5

Favourite word: Aha. For me and for others.

Share this post


Link to post
Share on other sites
42 minutes ago, dmstraker said:

Edit: Having said this, this page (with due zero exception) suggests Saturation = ((max(R,G,B) - min(R,G,B))/max(R,G,B). Hmm. Rings a bell.

On reflection, as colours move closer together, the result is more towards grey, which is desaturation. So max-min is an inverse measure of greyness (the smaller it is, the greyer the combined colour; the larger it is, the less grey and more saturated is the combined colour). Saturation is then calculated as this ungreyness as a proportion of the most saturated colour. So if RGB are spread out, the result is less grey (=more saturated) and max-min is a larger number. This is then normalized as proportion of the largest value to give a value 0..1. If it was divided by the minimum, the result would be >1, possibly very much greater.


Dave Straker

Cameras: Sony A7R2, RX100V

Computers: Win10: Chillblast Photo with i7-3770 + 16Gb RAM + Philips 40in 4K; Surface Pro 4 i5

Favourite word: Aha. For me and for others.

Share this post


Link to post
Share on other sites

Remember what I said about being "more cerebral" about this than I was? I followed the link to the coding page (from your post, above) and was immediately engulfed in fog. I can't say that any real information permeated the thick crust that has enveloped what is left of my mathematical brain. At any rate, I'm glad you like the saturation mask technique. What did you think about the "Fix over- and under-saturated images..." macros?

Share this post


Link to post
Share on other sites

Nice! My photography is still at the stage where 'fixing' is an ongoing necessity. One reason why I like AP so much. My wife is, slightly annoyingly, a natural photographer who just seems to get great shots in camera without really trying. Makes you want to cut off your ear :) .

I spent ten years as a programmer, so the code was ok. I'd get stuck if dropped into the deep end now, though. Like all professions, you turn away for a moment and when you look back everything's changed.


Dave Straker

Cameras: Sony A7R2, RX100V

Computers: Win10: Chillblast Photo with i7-3770 + 16Gb RAM + Philips 40in 4K; Surface Pro 4 i5

Favourite word: Aha. For me and for others.

Share this post


Link to post
Share on other sites

Here's a question. What should happen when saturation mapping this:

image.thumb.png.86291770f2fb071c9f61cf5412247576.png

 

You've got saturated primary/secondary colours, fading to black, white and grey. Then likewise for black, grey and white.

In a pre-mask layer, presumably the primary/secondary colours in the first column are white. But what should the other columns show? And what of black/grey/white?

Just musing.

Edit: If you apply HSL and turn up saturation, only the primary/secondary colours in the fourth column change. Does that mean a saturation mask should only show the changed area? This would suggest: Copy layer, HSL, S up, Blend Mode: Difference. Invert.

 


Dave Straker

Cameras: Sony A7R2, RX100V

Computers: Win10: Chillblast Photo with i7-3770 + 16Gb RAM + Philips 40in 4K; Surface Pro 4 i5

Favourite word: Aha. For me and for others.

Share this post


Link to post
Share on other sites

So, my prediction (which, admittedly, I was not bold enough to make prior to testing it out) is this:

1) The fully saturated patches would be completely white in a saturation mask. This means the first 6 rows (RGBCMY) in the first column.

2) Anything that is black, white, or grey will be completely black in a saturation mask, since those neutral colors should be 0% saturated. This includes the last 3 rows (Bk, Gy, and Wt) in all of the columns, and the far right ends of the first 6 rows of the second, third, and fourth column. As those patches transition to black, white, or grey, they also transition from 100% saturated (on the left) to 0% saturated (on the right).

3) In the first 6 rows of the right-most 3 columns, the saturation mask should resemble a gradient going from white to black.

I applied a saturation mask to your patches (above) using the first of my macro set - "Saturation Mask - Greyscale" - and the result is shown below. I believe this is just as it should be.

854810987_SaturationMaskonColoredPatches.thumb.jpg.b4e60105f46a1c340a798294ec6810ae.jpg

Cheers.  - smadell

Share this post


Link to post
Share on other sites

Makes sense, @smadell.

Interestingly, I applied the Dx=(max(SR,SG,SB)-min(SR,SG,SB))/max(SR,SG,SB) algorithm to DR, DG and DB, which resulted in fades in the last two columns but not the second. However, just using (max(SR,SG,SB)-min(SR,SG,SB)), a straight range calculation, gives the same results as yours (fade to black in right three columns). Looks like an alternative. Easier as macro?

Also, my original method gives the same result.

 


Dave Straker

Cameras: Sony A7R2, RX100V

Computers: Win10: Chillblast Photo with i7-3770 + 16Gb RAM + Philips 40in 4K; Surface Pro 4 i5

Favourite word: Aha. For me and for others.

Share this post


Link to post
Share on other sites

I would love to try the macros in the iOS version, whenever the 1.7 beta comes around


iPad Pro 12.9 3rd Gen/Mac Mini, in that order

Share this post


Link to post
Share on other sites
On 2/23/2019 at 2:37 PM, wgphoto said:

I would love to try the macros in the iOS version, whenever the 1.7 beta comes around

Me too. Is there a reason these don't show up in the iPad version currently? They appear to load but don't appear in the menu list?


IPad Pro 10.5 512GB iOS 12.1 Affinity Photo 1.6.11.85 Affinity Design 1.6.4.45

Share this post


Link to post
Share on other sites

As noted in the original post, these macros don’t work in version 1.6.x because of a bug in the Selective Color adjustment. The macros DO work in versions 1.7.x and they were created in the 1.7 beta. As far as I know, there was a change in file format between 1.6 and 1.7, and this seems to apply to ancillary files like .afmacros. Although you can “choose” them when importing macros into the iOS version (which is a version 1.6 app), they don’t show up, presumably because the file format is incompatible.

Share this post


Link to post
Share on other sites
On 3/12/2019 at 2:00 PM, smadell said:

 As far as I know, there was a change in file format between 1.6 and 1.7

Seems so. I tried using 1.7 image in 1.6 and it got refused.


Dave Straker

Cameras: Sony A7R2, RX100V

Computers: Win10: Chillblast Photo with i7-3770 + 16Gb RAM + Philips 40in 4K; Surface Pro 4 i5

Favourite word: Aha. For me and for others.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×