Jump to content

Recommended Posts

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:

BottleLabel.png.1d2894599db84a705c9b938417def987.png

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.)

GreatWestWindow08.thumb.png.8607fc085b696a8181d42a2e2b08c48c.png

And here is the image after the filter:

GreatWestWindowWrap.thumb.png.051d85fa4411f6e55bcb7f596fd7ba54.png

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.

WrapAround.afmacro

 

John


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

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

Share this post


Link to post
Share on other sites

Such lovely sums!

Gouraud shading next?


Dave Straker

Cameras: Sony A7R2, RX100V

Computers: Win10: Chillblast Photo with i7-3770 + 16Gb RAM + Philips 40in 4K; Surface Pro 4 i5

Favourite word: Aha. For me and for others.

Share this post


Link to post
Share on other sites
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


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

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

@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


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

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

Share this post


Link to post
Share on other sites

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

 

 

May-15-2018 13-17-40.gif

Share this post


Link to post
Share on other sites

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

 

bottles.jpg


Due to the ongoing Brexit negotiations, punctuation, spelling and grammar will be used sparingly until further notice.

Share this post


Link to post
Share on other sites
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


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

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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


Please be aware that NSA/GCHQ are probably admiring my sent images

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.


Please be aware that NSA/GCHQ are probably admiring my sent images

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×