Jump to content
John Rostron

A Macro to perform Affine Transformations

Recommended Posts

In a recent posting @skitchy  enquired about shifting pixels using Procedural Textures. I was not able to help, but I realised that you could perform an Affine Transformation (Filters > Distort > Affine) using Equations (Filters > Distort > Equations) instead. I used two parameters which control the horizontal shift and the vertical shift.

Here is a photo before applying the macro:
Before.png.4e0cc6f257fcf0d77251fddbac79e9e5.png

and after applying the macro:

After.png.427b01b8e99a762e848fa8202d01872b.png

The horizontal shift was around a half, and the vertical shift about 0.8.

Here are the equations:

 

x=   irem(x+a*w,w)
y=   irem(y+b*h,h)

As I said, they do not do anything that the Affine Transformation would not do (in a macro), but I offer them here as an alternative which might be more convenient within the context of a  more extended procedure. Here is the macro, and the macro library:

Macro: Affine Transform.afmacro

Library: Affine Transform.afmacros

John


Windows 10, Affinity Photo 1.8,3 Designer 1.8.3 and Publisher 1.8.3 (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,   Try this:  fixes the wrap...thanks for introducing me to Affine!  - T V

x = irem(x+a*h,h)

y = irem(y+b*w,w)

 

 correction...this only works on vertical document format...

Share this post


Link to post
Share on other sites

Use the Channels Panel to switch the channels you don’t want to affect OFF, then perform the Equation Distort.
See my attached image where the Red channel has been moved by 100 pixels to the right (Channels Panel settings shown bottom-right).

Annotation 2020-04-21 100251.png

Share this post


Link to post
Share on other sites
14 hours ago, T V said:

Hi John,   Try this:  fixes the wrap...

x = irem(x+a*h,h)

y = irem(y+b*w,w)

No, that will not work. This shifts the horizontal axis a fraction of the height and the vertical axis a fraction of the width. You try it and see!

My original shifts the horizontal axis by a fraction of the width etc.

14 hours ago, T V said:

thanks for introducing me to Affine!  - T V

@T V, I would appreciate any input you might have in performing an Affine Transformation using Procedural Textures.

John


Windows 10, Affinity Photo 1.8,3 Designer 1.8.3 and Publisher 1.8.3 (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
1 hour ago, John Rostron said:

No, that will not work. This shifts the horizontal axis a fraction of the height and the vertical axis a fraction of the width. You try it and see!

My original shifts the horizontal axis by a fraction of the width etc.

@T V, I would appreciate any input you might have in performing an Affine Transformation using Procedural Textures.

John

John, Seems that only works correctly if w = h.  I would like to be able to create these kind of effects in PT also.  Not sure the underlying structure of functioning the x, y.  If Equations were a live filter it would be much easier to work with...I will put on my tin foil hat and see if anything come to me. - T V   

Share this post


Link to post
Share on other sites
10 minutes ago, T V said:

Seems that only works correctly if w = h. 

Clearly this is true. You do not actually say what 'that' is. My version or yours? My version works for any values of w or h.

John


Windows 10, Affinity Photo 1.8,3 Designer 1.8.3 and Publisher 1.8.3 (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
1 hour ago, John Rostron said:

Clearly this is true. You do not actually say what 'that' is. My version or yours? My version works for any values of w or h.

John

Sorry, the macro applied differently to horizontal format and vertical format images for me.  By changing the w & h seemed to fix.  

Share this post


Link to post
Share on other sites
1 hour ago, T V said:

Sorry, the macro applied differently to horizontal format and vertical format images for me.  By changing the w & h seemed to fix.  

I have just tried my version on a portrait image and it works fine.

John


Windows 10, Affinity Photo 1.8,3 Designer 1.8.3 and Publisher 1.8.3 (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
3 hours ago, John Rostron said:

I have just tried my version on a portrait image and it works fine.

John

389717154_affinevertexample.jpg.7db674c841ef9105504314ff859bec01.jpg

This is what happens on a vertical image...works perfect on horizontal.  I am updated to current version, not beta. ????? - T V 

Share this post


Link to post
Share on other sites

I created a portrait image, with the height about twice the width, and it works perfectly for me.

John


Windows 10, Affinity Photo 1.8,3 Designer 1.8.3 and Publisher 1.8.3 (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
6 hours ago, John Rostron said:

I created a portrait image, with the height about twice the width, and it works perfectly for me.

John

John,  I opened a RAW(.cr2) file by chance to try it on the same photo instead of .jpg file and it works.  My horiz .jpg and .cr2 no problems.  Somehow my .jpg vertical format causes problems.  I am at a loss to understand what is happening as this is the first time I have encountered an issue of any kind.  Your macro works as it should.  Sorry for the confusion...this kind of thing does not help my math foundation... - T V  

Share this post


Link to post
Share on other sites
4 hours ago, T V said:

Somehow my .jpg vertical format causes problems

I wonder if you cropped your image to the vertical format.  If you apply Layer > Rasterise and trim, then it should work OK.

John


Windows 10, Affinity Photo 1.8,3 Designer 1.8.3 and Publisher 1.8.3 (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
1 hour ago, John Rostron said:

I wonder if you cropped your image to the vertical format.  If you apply Layer > Rasterise and trim, then it should work OK.

John

It's right out of the flash card.  I did try cropping and everything I could think.   I usually shoot RAW & .JPG and have the RAW for images I really want to play with and usually just grab the .jpg and go.  The camera is a Canon 6d mkII...my brain was telling me to take a couple more days off and everything would fix itself, but, no.  I did crop the RAW conversion and no problems...just tried images from D80 and same problem.  It is as if the pixel information on the horizontal images is being fooled into starting at a different fixed point throwing the calculation off.   Otherwise, life is good my friend!

+++ok, rasterize worked.  Good call.  Here is a new one.  Cropped and rasterized to original ratio I have to turn to 1's to get the divisions instead of .5.  Why rasterize on vertical format and not on horizontal?  Please make some more macros using distortions!  I wonder if it is all of the equations or just certain ones that act like that.  Is rasterize something to think about when creating a macro? Lots of interesting or not good interesting stuff came out of this...my brain is feeling sort of squishy.

Share this post


Link to post
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

Please note the Annual Company Closure section in the Terms of Use. These are the Terms of Use you will be asked to agree to if you join the forum. | 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.