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

Conditional expressions in Apply Image


Recommended Posts

I've been tinkering with conditional expressions in Apply Image. Ideally you'd do something like (conditional-expression?A:B) so if conditional-expression (eg x>0.5) evaluates as true then the result is A otherwise B.

But they are not natural, so my current thinking is:

roundup(clamp(expression,0,1))

If expression evaluates as negative, then the result is 0 otherwise 1 (including if it is >1), so you then multiply the whole thing by what you want to actually end up with. The 'else' alternative would be found by adding a similar term with the expression reversed.

eg. DR=roundup(clamp(SR-0.5,0,1))*SG+roundup(clamp(0.5-SR,0,1))*SB

This should set red pixels to equal to green pixel if the red pixel < 0.5, otherwise it should be blue.

This, for example, lets you play with DIY blend modes which flip formula either side of 0.5.

Untidy, I know. Does it make sense? Any improvements?

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

The conditional- or ternary operator is something often found in common prog-languages ...

  • condition ? value1 : value2      // where condition has to be a  boolean expression

  • variable = condition ? value1 : value2
  • int k = i == 10 ? 12 : 5; ... System.out.print(i == 10 ? 12 : 5);

Since I'm used to those things from programming it makes sense to me. - Though the way you can only apply/do such things at all in APh is primitive and poor. With some real scripting language support there should be instead much more things possible.

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

7 hours ago, v_kyr said:

The conditional- or ternary operator is something often found in common prog-languages ...

  • condition ? value1 : value2      // where condition has to be a  boolean expression

  • 
    variable = condition ? value1 : value2
  • 
    int k = i == 10 ? 12 : 5; ... System.out.print(i == 10 ? 12 : 5);

Since I'm used to those things from programming it makes sense to me. - Though the way you can only apply/do such things at all in APh is primitive and poor. With some real scripting language support there should be instead much more things possible.

Yup. I was a programmer too. Assembler, C, ... And good scripting would be fab. Maybe in 2.0?

Meanwhile the round/clamp algorithm seems a feasible option (unless anyone cares to shoot in down in flames).

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

36 minutes ago, dmstraker said:

Yup. I was a programmer too. Assembler, C, ... And good scripting would be fab. Maybe in 2.0?

Meanwhile the round/clamp algorithm seems a feasible option (unless anyone cares to shoot in down in flames).

Scripting in 2.0, maybe who knows (?).

Quote

In computer graphics, clamping is the process of limiting a position to an area. Unlike wrapping, clamping merely moves the point to the nearest available value. To put clamping into perspective, pseudocode for clamping is as follows:

Pseudocode (clamping):

function clamp(x, min, max):
    if (x < min) then
        x = min;
    else if (x > max) then
        x = max;
    return x;
end clamp

Uses

In general, clamping is used to restrict a value to a given range. For example, in OpenGL the glClearColor function takes four GLfloat values which are then 'clamped' to the range [0,1].

Y = clamp(X, 1, 5)
X Y
X < 1 1
1 1
1.5 1.5
2 2
3 3
4 4
5 5
X > 5 5

One of the many uses of clamping in computer graphics is the placing of a detail inside a polygon—for example, a bullet hole on a wall. It can also be used with wrapping to create a variety of effects. - (Note also the right side table there -->)

 

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

  • 3 weeks later...

@dmstraker,  I have used a similar formulation in Filter > Distort > Equations and it does work. I would also like to see some scripting available in Photo.

John

 

Windows 10, Affinity Photo 1.10.5 Designer 1.10.5 and Publisher 1.10.5 (mainly Photo), now ex-Adobe CC

CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630

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.