John Rostron Posted March 4, 2018 Posted March 4, 2018 In a recent post in Questions, @Maxxxworld asked how he could warp an image to apparently wrap it around a bottle. I posted a solution to his problem there, which I expand upon here. Consider the facing semicircle of the bottle as seen in this diagram: The visible part of the label extends from -90 degrees (on the left, not shown) to 90 degrees on the right. This will correspond to the width of the original image. This will project onto the final width of the image (the line below). The final width is less than the original width by a factor of pi/2. A bit of trigonometry shows that the sine of the Angle indicated is given by (x-halfwidth)/halfwidth, where halfwidth is both the label and the final image. Putting this together and re-arranging a bit gives us an Equation: x=(asin(2*x/w-1)*w/180)*pi/2+w/2 A bottle is typically viewed from above, so that the label has a curve, typically with a dip in the middle.This can easily be simulated using equations, using: y=y-Const*x*(w-x)/w/w The Constant determines the depth and direction of the curve. I have used the expression w*(0.5-a) as a scaling factor, where a is a parameter chosen at runtime. This will change the curve from negative (curving down) at the default a=1 to positive at a=0. Inserting this into the equation gives: y=y+(0.5-a)*x*(w-x)/w Note that the w in the numerator and denominator cancel out. The value of (0.5-a) determines the curvature as described above. As an example, here is the Great West Window of Chester Cathedral. I chose this because it has lots of verticals to see how the filter affects it. (It has verticals once I had put it through the Mesh Warp.) And here is the image after the filter: Before filtering I cropped it close to the sides of the window and then Rasterized it to remove the invisible sides. I then added space at the top and bottom to allow room for the curvature part to operate. I then followed this by Clip Canvas to remove surplus transparent ends. The calculations for this filter are complicated by the algorithm that Affinity uses to effect these equations, which I explain in this Tutorial here. I have created a macro that effects the filter, and then uses Clip Canvas. By clicking on the cogwheel, you can alter the degree and direction of curvature. EDIT: I have discovered that this macro will only perform once (per Affinity Photo session). I add here a version recorded in version 1.8 which does work properly in Photo 1.8: WrapAround1.8.afmacro I alos onclude here the original macro, recorded in version 1.7: WrapAround.afmacro John dmstraker, superhaschi, Przemysław and 11 others 9 5 Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
dmstraker Posted March 11, 2018 Posted March 11, 2018 Such lovely sums! Gouraud shading next? 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.
John Rostron Posted March 12, 2018 Author Posted March 12, 2018 10 hours ago, dmstraker said: Such lovely sums! Gouraud shading next? I had to look up what Gouraud shading was. I may be good at these lovely sums, but Gouraud shading looks as if it would require me learning how to create and use gradients. Gradients are a technique that I have read about but have yet to use in earnest. So, I think that I will leave Gouraud shading off my bucket list for now. John dmstraker 1 Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
PeteAxford Posted May 15, 2018 Posted May 15, 2018 Hi John, Thanks so much for sharing these equations. Having trawled the web while looking for ways to 'apply' labels to pack shots of bottles in Affinity Photo, this tutorial (and the accompanying equations and macros) are about the only things I've found to achieve this result - and they do it so well! I've been trying to work out how to change the amount of compression (which gives the effect of a 'fall off') on the sides of the 'label'. I understand that changing the variable mentioned (between 0 and 1) gives the effect of looking down/up at the 'label', but I'm wondering if there's a way to change the equation to give the appearance of the 'label' being wrapped around a larger object. Essentially it's a matter of persective, and I'm trying the make the left and right sides of the label compress more (in a smooth fashion), so that I can can achieve a effect of the label falling off as it curves around a round bottle, but with the camera as though it was square on to the bottle. My requirement is that as you get a wider label (that wraps further around the object), the compression applied the label will need to become more extreme as it reaches the 'edge' of the bottle. I hope this makes some kind of sense! Is there something I'm missing, or could you kindly point me in the direction of what I'd need to change in your equations? Many thanks, Pete Quote
John Rostron Posted May 15, 2018 Author Posted May 15, 2018 @PeteAxford, what you are looking for seems to be mapping a label that is less than the half-circumference of the bottle or can. This should be possible and I will look into it. As a fudge, you could resize the canvas (not the document) so that the new width corresponded to the half-diameter. After transforming, you could then remove the excess background (make it transparent and then Clip Canvas) John Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
PeteAxford Posted May 15, 2018 Posted May 15, 2018 Hi John, Thanks for such a prompt reply - I've been having a little play with the canvas sizes to see what effect it has, but can't get the extreme perspective shift I'm after. The effect I'm trying to achieve is that of a label which is almost (or even) 100% of the half-circumference of the bottle, so that the far left and right ends of the label end (or get towards ending) in a compressed mass of ink (as it would appear to camera). Here's a little gif of what I'm thinking about... it's set to 0.5 to give the effect of shooting straight on to the bottle (rather than creating the up or down curve), but I can't get those edges to compress enough to give the sense of the label wrapping around the edges. It's .gif which flips between the before and after - as you can see, there's not much fall off (see the vertical bars) as it is (though there does seem to be more if I get the label to wrap up or down?). Hope this helps clarify?! Thanks again, Pete Quote
carl123 Posted May 16, 2018 Posted May 16, 2018 x+(150*a)*sin(360*x/w) If I understand you correctly the above equation is a good place to start for what you want to achieve. It should effectively reduce the spacing between the characters on the left and right side of the text frame to simulate a label on a curved bottle. 1. Centre the text frame horizontally in your document (Important) 2. Add the equation and adjust Slider A (text will become wider and the effect may look a little strange at times) 3. After you apply the equation, reduce text frame width to desired width which should help the text look more natural You will need to experiment with different values for slider A for different text frame sizes I have no interest in placing labels on bottles but if you (or anyone) can improve on the above please post back with the steps / results Maxxxworld, Tatyana and ESPR 3 Quote To save time I am currently using an automated AI to reply to some posts on this forum. If any of "my" posts are wrong or appear to be total b*ll*cks they are the ones generated by the AI. If correct they were probably mine. I apologise for any mistakes made by my AI - I'm sure it will improve with time.
John Rostron Posted May 16, 2018 Author Posted May 16, 2018 3 hours ago, carl123 said: x+(150*a)*sin(360*x/w) If I understand you correctly the above equation is a good place to start for what you want to achieve. It should effectively reduce the spacing between the characters on the left and right side of the text frame to simulate a label on a curved bottle. 1. Centre the text frame horizontally in your document (Important) 2. Add the equation and adjust Slider A (text will become wider and the effect may look a little strange at times) 3. After you apply the equation, reduce text frame width to desired width which should help the text look more natural You will need to experiment with different values for slider A for different text frame sizes This equation certainly has the desired effect of compressing the marginal parts of the image. It is an empirical solution (that is one that works) but it does not strictly conform to the geometry as shown in my original diagram at the start of this thread. My formula does conform to the geometry, but fails in that it does not perform the appropriate marginal compression. Back, as they say, to the drawing board. John Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
PeteAxford Posted May 17, 2018 Posted May 17, 2018 Hello Gentlemen, Thank you both some much for your input and help on this matter. @carl123 I've plugged in your maths and it's doing the job for me wonderfully. I've combined your 'x' section John's 'y' to create both the more extreme compression in the edges and the gentle curvature of the label. @John Rostron Your response did make me chuckle - I love your turns of phrase and they cheered up my morning no end! I'm not whizz on the fine art of geometry (can I call it an art?!), but I think I follow your point about appropriate marginal compression. I will of course be following this thread, so if you want to keep on experimenting then I will be keen to see where you arrive at. Many thanks again; I wish you both a great day, All the best, Pete Quote
pioneer Posted June 12, 2018 Posted June 12, 2018 I would like to use this macro, however I have downloaded it into a folder named macros, when I try to import (via the AP studio library import )this macro the program does not see it within the folder. Any help on importing this would be helpful. Cheers John Quote AMD Ryzen 7 5800 X. Nvidia GeForce RTX3060 64Gb Ram Affinity Designer/Photo/Publisher 2.5.5 for Windows • Windows 11 24H2 (OS build 26 100. 2033) Home Affinity Designer/Photo/Publisher 2.5.5 for iPad Pro 10.5 • iPad OS 17.7
Staff MEB Posted June 12, 2018 Staff Posted June 12, 2018 Hi pioneer, .afmacro files (without the S at the end of macro) are the steps of a single macro and must be imported from the Macro panel clicking the last icon on the top right of the panel. .afmacros (with a S at the end) is a set of macros which are imported through the Library panel. pioneer and ESPR 1 1 Quote A Guide to Learning Affinity Software
pioneer Posted June 12, 2018 Posted June 12, 2018 Wow. that was a speedy response and a great answer. I had tried this but the icon was greyed out. Have now discovered you have to have an image loaded for this button to be visible. thanks once again John. Quote AMD Ryzen 7 5800 X. Nvidia GeForce RTX3060 64Gb Ram Affinity Designer/Photo/Publisher 2.5.5 for Windows • Windows 11 24H2 (OS build 26 100. 2033) Home Affinity Designer/Photo/Publisher 2.5.5 for iPad Pro 10.5 • iPad OS 17.7
Mr Lucky Posted February 7, 2019 Posted February 7, 2019 On 3/4/2018 at 11:32 AM, John Rostron said: x=(asin(2*x/w-1)*w/180)*pi/2+w/2 A bottle is typically viewed from above, so that the label has a curve, typically with a dip in the middle.This can easily be simulated using equations, using: y=y-Const*x*(w-x)/w/w Looks great but... When I put either of these into the Distortion > Equation, do nothing. The text of the equation turns red though. Does anyone know what I'm doing wrong, thanks Quote
John Rostron Posted February 7, 2019 Author Posted February 7, 2019 The text will turn red if there is an error and it cannot parse the expression (usually a typo). Have you tried downloading and running the macro given near the beginning of the thread? John Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
MaximusNZ Posted April 30, 2020 Posted April 30, 2020 (edited) On 3/5/2018 at 12:32 AM, John Rostron said: Consider the facing semicircle of the bottle as seen in this diagram: The visible part of the label extends from -90 degrees (on the left, not shown) to 90 degrees on the right. This will correspond to the width of the original image. This will project onto the final width of the image (the line below). The final width is less than the original width by a factor of pi/2. A bit of trigonometry shows that the sine of the Angle indicated is given by (x-halfwidth)/halfwidth, where halfwidth is both the label and the final image. Putting this together and re-arranging a bit gives us an Equation: x=(asin(2*x/w-1)*w/180)*pi/2+w/2 @John Rostron John I am truely in awe of your math! I have a similar yet inverse problem, I’ve shot 360 photos but want remove the vertical distortion from the equirectangular format. Which looks like an image is rolled over a tube vertically. A friend showed me a photoshop plug in that can do this, and it looks great to make an equirectangular photo look like a panaorama (with top and bottom cut off). But I thought the equation editor in Affinity must be able to do this.... i have tried to reverse your equation.... but I am a math loser😰 Can I beg your help to figure out how to adjust images as I’m suggesting (sorry I’m new to these forums too so not yet too good on how to quote and add images). The Origonal unaltered 360 images are 6080 x 3040. Edited April 30, 2020 by MaximusNZ Quote
John Rostron Posted April 30, 2020 Author Posted April 30, 2020 @MaximusNZ, as far as I can tell, you are seeking an equation that will expand the image vertically more at the top and bottom than in the middle. There is no pre-determined geometry that you or I could follow, so an empirical solution would be in order (that is one that just looks right). Let me have a think about it and do a trial and I will get back to you. John MaximusNZ 1 Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
John Rostron Posted April 30, 2020 Author Posted April 30, 2020 @MaximusNZ. Try this macro. It applies a simple sine curve and expands to top and bottom, whilst squeezing the centre. I have uploaded both the single Macro and a Macro library containing this one macro. Expand Top and Bottom.afmacro Expand Top and Bottom.afmacros If you find that it is stretching/squeezing too much, let me know and I will see if I can add a parameter to reduce the effect. John MaximusNZ and pruus 1 1 Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
MaximusNZ Posted April 30, 2020 Posted April 30, 2020 8 hours ago, John Rostron said: If you find that it is stretching/squeezing too much, let me know and I will see if I can add a parameter to reduce the effect. @John Rostron That’s looking amazing! At first I found it was not quite right, then I realised I need to resize the canvas before applying the macro. Then squeeze it a bit to look nicer. And in the end I’ve ended up with a set of actions to make it look good: Resize Canvas - Centered - Y axis to 6040 pxRun “ Expand Top and Bottom” MacroTransform - Y scale 92% Y offset 506 px Transform - Y scale 91% Y offset 45.7 px Crop to look better top and Bottom What I end up with is almost the same. The top and bottom could do with a bit more stretch, but the middle bit the same.... yeah sounds hard. I’ve created side by sides of my final result from the steps above versus the PS workflow. BTW what is the equation you ended up using? Is there a way to use the “a” slider to adjust the outer stretch? And do you have a Patron / way to buy you a coffee? (I live in New Zealand, where are you?) John Rostron 1 Quote
John Rostron Posted May 3, 2020 Author Posted May 3, 2020 @MaximusNZ, you may like to look at my revised version of this macro posted as a separate thread here. John Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
John Rostron Posted May 3, 2020 Author Posted May 3, 2020 On 4/30/2020 at 11:38 PM, MaximusNZ said: And do you have a Patron / way to buy you a coffee? (I live in New Zealand, where are you? I am a retired biology lecturer living in Essex, UK. I do this sort of thing for pleasure. We will be enjoying a glass of Oyster Bay Sauvignon Blanc with Sunday lunch and think about New Zealand. John Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
John Rostron Posted May 13, 2020 Author Posted May 13, 2020 @catloverhad discovered that my original macro (recorded in Photo v1.7) will only perform once when using with v1.8. I have recorded that same macro in Photo v1.8 which is included here, as well as in the original posting. It now seems to work as expected. WrapAround1.8.afmacro John Cecil 1 Quote Windows 11, Affinity Photo 2.4.2 Designer 2.4.2 and Publisher 2.4.2 (mainly Photo). CPU: Intel Core i5 8500 @ 3.00GHz. RAM: 32.0GB DDR4 @ 1063MHz, Graphics: 2047MB NVIDIA GeForce GTX 1050
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.