Jump to content
You must now use your email address to sign in [click for more info] ×

Saturation Masks - a simple method


smadell

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

Affinity Photo 2, Affinity Publisher 2, Affinity Designer 2 (latest retail versions) - desktop & iPad
Culling - FastRawViewer; Raw Developer - Capture One Pro; Asset Management - Photo Supreme
Mac Studio with M2 Max (2023}; 64 GB RAM; macOS 13 (Ventura); Mac Studio Display - iPad Air 4th Gen; iPadOS 17

Link to comment
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 i9 Custom + Philips 40in 4K & Benq 23in; Surface Pro 4 i5; iPad Pro 11"

Favourite word: Aha. For me and for others.

Link to comment
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

Affinity Photo 2, Affinity Publisher 2, Affinity Designer 2 (latest retail versions) - desktop & iPad
Culling - FastRawViewer; Raw Developer - Capture One Pro; Asset Management - Photo Supreme
Mac Studio with M2 Max (2023}; 64 GB RAM; macOS 13 (Ventura); Mac Studio Display - iPad Air 4th Gen; iPadOS 17

Link to comment
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 i9 Custom + Philips 40in 4K & Benq 23in; Surface Pro 4 i5; iPad Pro 11"

Favourite word: Aha. For me and for others.

Link to comment
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 i9 Custom + Philips 40in 4K & Benq 23in; Surface Pro 4 i5; iPad Pro 11"

Favourite word: Aha. For me and for others.

Link to comment
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?

Affinity Photo 2, Affinity Publisher 2, Affinity Designer 2 (latest retail versions) - desktop & iPad
Culling - FastRawViewer; Raw Developer - Capture One Pro; Asset Management - Photo Supreme
Mac Studio with M2 Max (2023}; 64 GB RAM; macOS 13 (Ventura); Mac Studio Display - iPad Air 4th Gen; iPadOS 17

Link to comment
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 i9 Custom + Philips 40in 4K & Benq 23in; Surface Pro 4 i5; iPad Pro 11"

Favourite word: Aha. For me and for others.

Link to comment
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 i9 Custom + Philips 40in 4K & Benq 23in; Surface Pro 4 i5; iPad Pro 11"

Favourite word: Aha. For me and for others.

Link to comment
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

Affinity Photo 2, Affinity Publisher 2, Affinity Designer 2 (latest retail versions) - desktop & iPad
Culling - FastRawViewer; Raw Developer - Capture One Pro; Asset Management - Photo Supreme
Mac Studio with M2 Max (2023}; 64 GB RAM; macOS 13 (Ventura); Mac Studio Display - iPad Air 4th Gen; iPadOS 17

Link to comment
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 i9 Custom + Philips 40in 4K & Benq 23in; Surface Pro 4 i5; iPad Pro 11"

Favourite word: Aha. For me and for others.

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...
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?

M1 IPad Air 10.9/256GB   lpadOS 17.1.1 Apple Pencil (2nd gen).
Affinity Photo 1.10.5 Affinity Design 1.10.5 
Affinity Publisher 2, Affinity Designer 2, Affinity Photo 2 and betas.

Official Online iPad Help documents (multi-lingual) here: https://affinity.https://affinity.help/ 

 

Link to comment
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.

Affinity Photo 2, Affinity Publisher 2, Affinity Designer 2 (latest retail versions) - desktop & iPad
Culling - FastRawViewer; Raw Developer - Capture One Pro; Asset Management - Photo Supreme
Mac Studio with M2 Max (2023}; 64 GB RAM; macOS 13 (Ventura); Mac Studio Display - iPad Air 4th Gen; iPadOS 17

Link to comment
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 i9 Custom + Philips 40in 4K & Benq 23in; Surface Pro 4 i5; iPad Pro 11"

Favourite word: Aha. For me and for others.

Link to comment
Share on other sites

  • 2 weeks later...

Unfortunately developers appear to have forgotten Serif released an iPad version. We are still on a very buggy 1.6. Release.:(

M1 IPad Air 10.9/256GB   lpadOS 17.1.1 Apple Pencil (2nd gen).
Affinity Photo 1.10.5 Affinity Design 1.10.5 
Affinity Publisher 2, Affinity Designer 2, Affinity Photo 2 and betas.

Official Online iPad Help documents (multi-lingual) here: https://affinity.https://affinity.help/ 

 

Link to comment
Share on other sites

  • 2 months later...

Because of changes in the way some Adjustment Layers are coded, I have posted updated versions of this macro category (and of one other). While the existing macros, downloaded from this page, still work, the updated macros are a little bit cleaner and do not display the "nag screen" about updating a legacy adjustment.

Download the updated version here:

 

Affinity Photo 2, Affinity Publisher 2, Affinity Designer 2 (latest retail versions) - desktop & iPad
Culling - FastRawViewer; Raw Developer - Capture One Pro; Asset Management - Photo Supreme
Mac Studio with M2 Max (2023}; 64 GB RAM; macOS 13 (Ventura); Mac Studio Display - iPad Air 4th Gen; iPadOS 17

Link to comment
Share on other sites

  • 1 year later...
On 1/14/2019 at 6:34 PM, smadell said:

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

@smadell

Thank you for this work I really miss so much the Tony Kuyper panel in Affinity Photo

Link to comment
Share on other sites

  • 7 months later...
  • Staff

The purity of a colour can be computed by converting from RGB to HSV and then multiplying S by V (which is effectively what the Selective Colour adjustment does), where S and V are defined as follows:

min = min(r,g,b)

max = max(r,g,b)

S = (max - min) / max

V = max

Therefore,

S * V =  (max - min) * max / max = max - min

That's why the same effect can be achieved with Affinity Photo's Apply Image filter.

DR = max(SR,SG,SB) - min(SR,SG,SB)

DG = max(SR,SG,SB) - min(SR,SG,SB) 

DB = max(SR,SG,SB) - min(SR,SG,SB) 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.