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

need some way to put a limit on saturation


Recommended Posts

I need some way to put a limit on saturation (or some form of non-linear desaturation). I need a filter that basically runs an algorithm that looks like

for every pixel, convert RGB value to HSI value. If the S value is greater than X, set it to X, convert that HSI value back into RGB

I tried replicating this effect using a S shaped curve for AOpponent and BOpponent with a Curve filter in LAB mode, but I can't get the desired effect.

I tried using a normal curve in RGB and then setting the blend mode the Saturation, but the input axis is brightness, so this does not give me the desired effect

I tried the threshold filter but I need the input to be saturation

I can't seem to find a way of mixing channels in the same way that I can convert between RGB and HSV colour spaces within OpenCV/Numpy

 

Link to comment
Share on other sites

Isn't there a correlation between the differences between R and G and B and Saturation? If the differences are too large shrink them.

Caveat: I really do not know that of which I speak.

Mac Pro (Late 2013) Mac OS 12.7.4 
Affinity Designer 2.4.1 | Affinity Photo 2.4.1 | Affinity Publisher 2.4.1 | Beta versions as they appear.

I have never mastered color management, period, so I cannot help with that.

Link to comment
Share on other sites

In theory this could be possible with procedural texture filters.

I succeeded partially and found formulas for the partial steps, e.g. calculating saturation from RGB, or convert HSL back to RGB.

Unfortunately, these  formulas get quite lengthy, as the PT filter lacks some essentials like a building rgb-2-HSL conversion.

Especially transforming essential if/else into equivalent arithmetic formulas makes everything so complex.

I did not try to combine all into one gigantic formula as debugging becomes far too laborious.

Alternative  ideas:

  • use my PT filter to create a selection of overly saturated pixels
  • Use fill layer with given maximum saturation and blend mode saturation (could be one color set by HSL)
  • I need to split into 3 PT filters, one for every dominant primary color (R,G,B). This will eliminate most of the if/else complexity. The colors can be re-combined later.

Could you provide an example document, and the expected result?
i will then provide a file with the PT filters.

 

basic start:

A=var mi=min(R,G,B); var ma=max(R,G,B);var dd=ma-mi; var ll=(ma+mi)/2; var sat=dd/(1-abs(2*ll-1)); sign(sat-a)

with input a=intend saturation maximum level

Edited by NotMyFault
Updated ideas

Mac mini M1 A2348 | Windows 10 - AMD Ryzen 9 5900x - 32 GB RAM - Nvidia GTX 1080

LG34WK950U-W, calibrated to DCI-P3 with LG Calibration Studio / Spider 5

iPad Air Gen 5 (2022) A2589

Special interest into procedural texture filter, edit alpha channel, RGB/16 and RGB/32 color formats, stacking, finding root causes for misbehaving files, finding creative solutions for unsolvable tasks, finding bugs in Apps.

 

Link to comment
Share on other sites

Another idea:

  • add HSL filter and set sat to e.g. +50%
  • add another HSL filter and set sat to -50%
  • This should limit sat to 50%. Pixel with sat <=50% stay unchanged. Pixels with sat >50% get capped at 50%.

The test image seem to work at least for the special case (limit sat to 50%)

limit saturation.afphoto

Edited by NotMyFault

Mac mini M1 A2348 | Windows 10 - AMD Ryzen 9 5900x - 32 GB RAM - Nvidia GTX 1080

LG34WK950U-W, calibrated to DCI-P3 with LG Calibration Studio / Spider 5

iPad Air Gen 5 (2022) A2589

Special interest into procedural texture filter, edit alpha channel, RGB/16 and RGB/32 color formats, stacking, finding root causes for misbehaving files, finding creative solutions for unsolvable tasks, finding bugs in Apps.

 

Link to comment
Share on other sites

Thanks for the hint! I googled around for tutorials about the procedural texture filter and I found this http://changingminds.org/disciplines/photography/affinity_photo/resources/daves_saturation_selection.htm

It doesn't work as well as I'd hope in my situation but I am studying the equation to get a feel for this filter

I honestly didn't even know Affinity had macros...

Wishing Affinity had RGBtoHSI and HSItoRGB equations, would have made this soooo easy

Link to comment
Share on other sites

23 hours ago, NotMyFault said:
  • add HSL filter and set sat to e.g. +50%
  • add another HSL filter and set sat to -50%
  • This should limit sat to 50%. Pixel with sat <=50% stay unchanged. Pixels with sat >50% get capped at 50%.

Wow, how did you get there? Can you explain why this really works? Why is it important that first +50 gets calculated?
I'd expected +/– would cancel each other out, which seems to happen only if the adjustment order gets swapped.

macOS 10.14.6 | MacBookPro Retina 15" | Eizo 27" | Affinity V1

Link to comment
Share on other sites

31 minutes ago, thomaso said:

Wow, how did you get there? Can you explain why this really works? Why is it important that first +50 gets calculated?
I'd expected +/– would cancel each other out, which seems to happen only if the adjustment order gets swapped.

The trick is +50% cannot go over 100%, it gets capped at 100%.

Column1 v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10
old value 0 10 20 30 40 50 60 70 80 90 100
sat +50 0 20 40 60 80 100 100 100 100 100 100
sat -50 0 10 20 30 40 50 50 50 50 50 50

Mac mini M1 A2348 | Windows 10 - AMD Ryzen 9 5900x - 32 GB RAM - Nvidia GTX 1080

LG34WK950U-W, calibrated to DCI-P3 with LG Calibration Studio / Spider 5

iPad Air Gen 5 (2022) A2589

Special interest into procedural texture filter, edit alpha channel, RGB/16 and RGB/32 color formats, stacking, finding root causes for misbehaving files, finding creative solutions for unsolvable tasks, finding bugs in Apps.

 

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.