ch22 Posted February 8, 2020 Share Posted February 8, 2020 By November 2017, dmstraker was asking for information about Contrast Negate (https://forum.affinity.serif.com/index.php?/topic/49811-your-big-friendly-guide-to-layer-blend-modes/&tab=comments#comment-250891) . As I found nothing about this point in more recent posts, I give my opinion. I think that the luminosities of the two layers are analyzed, but in the sense of lumas, i.e. L'=0.3R'+0.59G'+0.11B' where all quantities are normalized quantities varying in the (0,1) interval. First a selection is built of areas where lumas are both below 0.5 ou both above 0.5. Then, the upper layer is replaced with its negative within the selection. I enclose a macro, simu_Contrast_Negate.afmacro which (hopefully) does this job —to be imported in the Macro panel. Select the upper layer and run it. An Invert adjustment should be created above the upper layer (allowing to recover the selection from the adjustment mask) simu_Contrast_Negate.afmacro dmstraker 1 Quote Link to comment Share on other sites More sharing options...
dmstraker Posted February 8, 2020 Share Posted February 8, 2020 Much appreciated, @ch22. Ran the macro -- similar but different results - see attached. Am I using it as expected? contrast_negate_test.afphoto Quote 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 More sharing options...
dmstraker Posted February 8, 2020 Share Posted February 8, 2020 6 hours ago, ch22 said: think that the luminosities of the two layers are analyzed, but in the sense of lumas, i.e. L'=0.3R'+0.59G'+0.11B' where all quantities are normalized quantities varying in the (0,1) interval. First a selection is built of areas where lumas are both below 0.5 ou both above 0.5. Then, the upper layer is replaced with its negative within the selection. Wondering if this can be done with a single Apply Image... Quote 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 More sharing options...
ch22 Posted February 8, 2020 Author Share Posted February 8, 2020 Sorry, Dave, I cannot open your file with my current version (1.7.3) —I got the warning “The file includes features from a later version of Affinity“. As for the right operating process, I join a short video demo_contrast_negate.mp4 Quote Link to comment Share on other sites More sharing options...
dmstraker Posted February 9, 2020 Share Posted February 9, 2020 Nice, though I'm still confused. My Contrast Negate doesn't work like this (in fact, strangely, it looks rather like a straight invert). I've tried it on 1.7.1 and 1.7.3. Which version of Affinity Photo are you using. The macro loads ok but only results in an invert layer. There's a whole bunch of Deletes at the bottom, are you deleting one too many or missing a Merge Image? Just trying to do what you're doing in Filters/Apply Image (click Use Current Layer as Source, then Equations), try this: DR=(roundup(0.5-(0.3*SR+0.59*SG+0.11*SB))*SR)+(roundup((0.3*SR+0.59*SG+0.11*SB)-0.5)*(1-SR)) DG=(roundup(0.5-(0.3*SR+0.59*SG+0.11*SB))*SG)+(roundup((0.3*SR+0.59*SG+0.11*SB)-0.5)*(1-SG)) DB=(roundup(0.5-(0.3*SR+0.59*SG+0.11*SB))*SB)+(roundup((0.3*SR+0.59*SG+0.11*SB)-0.5)*(1-SB)) The 0.5 subtraction throws half below zero which rounds up to zero. Otherwise it rounds up to 1. In other words, the subtraction and roundup are used as a conditional operator. Does this work in the same way? Quote 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 More sharing options...
ch22 Posted February 9, 2020 Author Share Posted February 9, 2020 Indeed, the macro results only in the invert adjustment through the selection about luma comparisons (this can be seen in the video). Its purpose was simply to give the same display as the investigated blend mode, without modifying the RGB components of the layer; additionally, the selection can be recovered for any other fanciful operation you could imagine on this layer. My current version is 1.7.3 Let me some time to consider your formulas —so far, I never walked through this menu in my exploration of Affinity Photo (my personal project consists in in-depth explanations of the software for French photographers through a set of video tutorials, french speaking, of course! The job is not ended. See http://www.oitregor.com/numeric/affinity_photo/contenu.html ) Quote Link to comment Share on other sites More sharing options...
dmstraker Posted February 9, 2020 Share Posted February 9, 2020 Wow! Good work there. Hope your efforts are appreciated. You may know my InAffinity YouTube channel: https://www.youtube.com/channel/UCOnLUmyPHr2rayOHVHWsHVw Quote 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 More sharing options...
Cecil Posted February 9, 2020 Share Posted February 9, 2020 6 hours ago, ch22 said: Indeed, the macro results only in the invert adjustment through the selection about luma comparisons (this can be seen in the video). Its purpose was simply to give the same display as the investigated blend mode, without modifying the RGB components of the layer; additionally, the selection can be recovered for any other fanciful operation you could imagine on this layer. My current version is 1.7.3 Let me some time to consider your formulas —so far, I never walked through this menu in my exploration of Affinity Photo (my personal project consists in in-depth explanations of the software for French photographers through a set of video tutorials, french speaking, of course! The job is not ended. See http://www.oitregor.com/numeric/affinity_photo/contenu.html ) Wow! Wish the Web Site had English conversion, looks great. Quote Cecil iMac Retina 5K, 27”, 2019. 3.6 GHz Intel Core 9, 40 GB Memory DDR4, Radeon Pro 580X 8 GB, macOS,iPad Pro iPadOS Continuous improvement is better than delayed perfection Link to comment Share on other sites More sharing options...
ch22 Posted February 10, 2020 Author Share Posted February 10, 2020 First, thanks to dmstraker and Cecil for their encouragements. As for the English conversion... sorry, but that's another story ! Now, returning to the dmstraker's experiments with the Apply Image menu, I tried too. And incredibly —but VERY painfully— I succeeded in emulating the Contrast Negate blend mode. The issue is that equations to be entered are fairly long (see below) so that entering them by hand without errors is nearly impossible. You must prepare these equations on a separate text editor and then copy and paste them into the right box in Affinity Photo. Using word processors (such as Word or Text Edit) is a poor idea as the pasted formulas are not understood when they are too long — I suspect they are ruined by undesirable hidden formatting characters. Better to use a true text editor ; unfortunately, I use a very old one (AlphaX), and the copy and paste from it to AP does not run ! Eventually, I mixed parts of copy and paste with parts of manual typing, and finally I reached the holy Graal, I mean the identity between the blend mode and its emulation... The pseudo-code for the equations to be entered is as follows : DR=(1-DR) * SEL + DR * (1 – SEL) ; DG=(1-DG) * SEL + DG * (1 – SEL) ; DB=(1-DB) * SEL + DB * (1 – SEL) where SEL is the logical expression ((SL<0.5) AND (DL<0.5)) OR ((SL>0.5) AND (DL>0.5)) , where SL and DL stand for the luminosities (lumas) in the source and target layers, that is SL=0.3*SR+0.59*SB+0.11*SB and DL=0.3*DR+0.59*DB+0.11*DB. Then, as pointed by dmstraker, replace the conditional expressions such as (SL<0.5) or (SL>0.5) by numerical evaluations roundup(0.5-SL) or roundup(SL-0.5), then replace AND operator with a mere product , and OR with a mere addition (this is valid in this special case). We thus get DR= (1-DR) * ( roundup(0.5-0.3*SR-0.59*SB-0.11*SB)*roundup(0.5-0.3*DR-0.59*DB-0.11*DB) +roundup(0.3*SR+0.59*SB+0.11*SB -0.5)*roundup(0.3*DR+0.59*DB+0.11*DB -0.5)) + DR * (1 – ( roundup(0.5-0.3*SR-0.59*SB-0.11*SB)*roundup(0.5-0.3*DR-0.59*DB-0.11*DB) +roundup(0.3*SR+0.59*SB+0.11*SB -0.5)*roundup(0.3*DR+0.59*DB+0.11*DB -0.5))) and similarly for green and blue components. These are the real formulas to be entered into AP If you get to this point and AP is not grumbling about your formulas, congratulations! You should have reproduced the result of the Contrast Negate blend mode! Quote Link to comment Share on other sites More sharing options...
dmstraker Posted February 11, 2020 Share Posted February 11, 2020 14 hours ago, ch22 said: DR= (1-DR) * ( roundup(0.5-0.3*SR-0.59*SB-0.11*SB)*roundup(0.5-0.3*DR-0.59*DB-0.11*DB) +roundup(0.3*SR+0.59*SB+0.11*SB -0.5)*roundup(0.3*DR+0.59*DB+0.11*DB -0.5)) + DR * (1 – ( roundup(0.5-0.3*SR-0.59*SB-0.11*SB)*roundup(0.5-0.3*DR-0.59*DB-0.11*DB) +roundup(0.3*SR+0.59*SB+0.11*SB -0.5)*roundup(0.3*DR+0.59*DB+0.11*DB -0.5))) Gosh, well done! I did cut and paste but it stayed red. A couple of questions. I'm not sure how DR evaluated in the equation? As Destination Red it would seem to be a result and suggests recursion. roundup(0.5-0.3*SR-0.59*SB-0.11*SB) Should that be 0.59*SG? Merci! Quote 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 More sharing options...
ch22 Posted February 11, 2020 Author Share Posted February 11, 2020 I'm not sure how DR evaluated in the equation? This is not a real equation, but a kind of pseudo-code. DR is the previous DR in the right hand side and the new one in the left side. For instance, the product blend mode would be obtained with DR=DR*SR (to be understood as DR_new=DR_previous*SR). Only the right hand side is to be entered into the AP box roundup(0.5-0.3*SR-0.59*SB-0.11*SB) Should that be 0.59*SG? Of course. I suffered from many mistakes in the process, I corrected a lot of them directly in the AP box and I did not always reported these corrections in my text processor... and unfortunately I used this text version to prepare my post. Sorry! Actually, I did not dare to directly deal with color pictures. I began the work with grey pictures, where the code is far simpler. Not that simple to get it right the first time, but I succeeded fast enough to be reasonably confident to tackle the color case. Now, I want to emphasize that my misadventures are not at all a condemnation of this Apply Image menu. Simply, in case of complex equations, better to have a true text editor at hand with a compatible copy and paste function! John Rostron 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.