Jump to content
Kronpano

support for percent resize in macros and input boxes

Recommended Posts

At the moment it is AFAIK impossible to write image size independent macros if you want to use "resize canvas/document" because these operations work on pixels.

Problem:
Affinity photo should be 360 aware but it isn't really - local adjustment filters and tonemapping leave visible seams.

Workaround:
One easy way to get around that is to increase the canvas width by 20% (<- this is the problem),
   use equations to fill the right and left border,
   make the adjustment and
resize the width of the canvas back to the original size - shrink width by 16.66% (<-again a problem)

At them moment this can't really be done independent of the image size because a size increase/decrease will be calculated to pixels - so there will be a fixed pixel number in the macro

Solutions:

  • The easiest solution would be if Affinity Photo would support resize by percent properly - by that I mean also in macros
  • support expressions in input fields also in macros -> if you put "*1.2" in an input field this expression will also be used in the macro
  • support variables in macros - reading image size into variables which can be used in later operations


To give an example - I have written a macro which increases a 360 panorama by 10% on each side and fills the properly BUT it will only work properly with a 10000 x 5000 px panorama (my main publishing size).

Would be really good for Affinity photo if the macro capabilities got better - it can really speed up a workflow and make repetitive tasks a lot easier but for that it needs to be possible to do pretty much everything independent of the image size and in a way - that's where percentages come in really handy.

 

10kBy5kPlus10%eachSide.afmacro

Share this post


Link to post
Share on other sites

I agree there doesn't seem to be a way to do this with macros, but do note that you can do this directly in the various resize dialogs using expressions like "+=20%" - just in case you had missed that...

Share this post


Link to post
Share on other sites

This probably can be done, but it will require that you use Filters > Distort > Equations... in your macro to perform the resizing operation.

For an example:

For more information on using Equations, there are some topics in the Tutorials forum.


-- Walt

Windows 10 Home, version 1909 (183623.476), 16GB memory, Intel Core i7-6700K @ 4.00Gz, GeForce GTX 970
Affinity Photo 1.7.3.481 and 1.8.0.514 Beta   / Affinity Designer 1.7.3.481 and 1.8.0.514 Beta  / Affinity Publisher 1.7.3.481 and 1.8.0.518 Beta

Share this post


Link to post
Share on other sites
18 hours ago, Kronpano said:

One easy way to get around that is to increase the canvas width by 20% (<- this is the problem),

The attached macro should do that

It adds a transparent canvas width of 10% to each side of the document 

Tested on 2000px - 20000px width documents

In multiples of 500px (e.g. 2500px, 3000px, 3500px etc) you "should" get accurate resizing results but due to rounding (up/down) in the macros and equation filter, the resize can be 2-4 pixels off if you use totally random widths to start with.

It works at the layer level, not the document level so either start with a jpg/png file etc or merge (flatten?) all layers into one in your document first.

To run just select the layer  then run the macro

 

add-10%-each-side.afmacro


Due to the fact that Boris Johnson is now our Prime Minister, punctuation, spelling and grammar will never be worried about ever again.  We now have far bigger problems to be concerned about.

Share this post


Link to post
Share on other sites

OK, thanks for that.
I see - I did pretty much the same BUT I didn't think of using a "dummy" layer, then resizing the canvas, clipping it and throw away the dummy.

So close and yet so far.

Thanks again.

Will try to incorporate it into my macro.
If I can't get there are you happy to share the equation??

Share this post


Link to post
Share on other sites
6 hours ago, carl123 said:

It adds a transparent canvas width of 10% to each side of the document 

When you say "each side" do you mean "right and left sides"? That's what I get, but I wasn't sure if you meant to include all 4 sides.


-- Walt

Windows 10 Home, version 1909 (183623.476), 16GB memory, Intel Core i7-6700K @ 4.00Gz, GeForce GTX 970
Affinity Photo 1.7.3.481 and 1.8.0.514 Beta   / Affinity Designer 1.7.3.481 and 1.8.0.514 Beta  / Affinity Publisher 1.7.3.481 and 1.8.0.518 Beta

Share this post


Link to post
Share on other sites

Yes, just "right and left sides" which was the OP's requirement.

More specifically the ability to do this as a percentage value on any size image rather than a hardcoded pixel value which will only work on images of the same dimensions


Due to the fact that Boris Johnson is now our Prime Minister, punctuation, spelling and grammar will never be worried about ever again.  We now have far bigger problems to be concerned about.

Share this post


Link to post
Share on other sites

Yes, left and right side.

The whole idea is to overcome Affinity photos inability to treat 360 panoramas properly.
A 360 panorama is usually a file with a 2:1 ratio - 360 degrees around and 180 degrees up/down - so a full sphere.
The problem are the right and left "edges" of the file. When looking at a panorama (example here on kuula ) the right and left side need to fit together seamlessly otherwise there will be a vertical line visible in the panorama.
General changes in brightness, colours... don't affect that BUT local changes (like clarity, local contrast, tonemapping) cause a problem because if I apply them to the original image the edges have no neighbour - so the left edge will be treated differently from the right edge and when I put them together there is a visible seam.
This can be prevented by by extending the original image (basically give each edge neighbours) - this is possible because the 360 panorama can just be wrapped around so it will fit seamlessly.

My macro I provided in the post at the top does just that - BUT it is size dependent.

Now I had a go with the macro @carl123 posted yesterday and I am not sure it helps.
Yes - it adds 10% to each side - so that problem is solved BUT once I have done that (manually or in a macro) I have "lost" my original width of the panorama and don't know how far to shift the image to extend the right/side because the width w is now the extended width.

Let me explain my macro
Assume a 10000x5000px panorama

Extend the canvas by 20% centred  - this will result in a 12000x5000 canvas with the original panorama in the middle and 10% transparent on each side
Duplicate that layer and shift it to the right by 10000px - this will seamlessly fill the right hand side 10% extension
Duplicate the layer and shift it to the left by 10000px - the same for the left hand side 10% extension
Merge them all down and you are done

You will end up with a 12000x5000px document which has no seams in itself

Apply any local adjustment and the "original" edges will be treated the same because they have the "proper" neighbours
Once you are done with the adjustments you can just resize the canvas back (centred)  to 10000x5000px and you will have again a 360 panorama with no seams.

This is what Affinity photo should probably do in the first place since it claims to be 360 aware so all of that is only to get around the limitations the program shouldn't have in the first place.
I have raised that problem about 18 month ago and after a long silence it was confirmed here

that it will NOT be solved.
A solution provided by @James Ritson relies on as far as I can see on resizing the pixels (squashing and expanding like equation x/0.9 and x/(1/0.9) ) which will deteriorate the image quality since the final expansion is not working on the original pixels but the squashed ones.

So please give us either a % resize that can be used in macros or even better - a macro scripting language (like Mathmap for GIMP) so you can work with variables and stuff and not just one line equations which can't be saved and edited properly.

Not sure it makes sense to anybody who is not working with panoramas but I hope my explanation makes sense.
Cheers.
 

Share this post


Link to post
Share on other sites

OK, I think I am giving up

Just thought I had it - using distort -> affine 
Extend the canvas to really wide (like 20000x100) and then use distort -> affine with 120% and clip the canvas again

Should result in a 10000 scaled to 120% should be 12000 pixels wide 

NOOOOO

it is 12002 pixels wide - internal rounding problem I would guess but that that is out of my control and again - probably size dependent.

Same happens with all my equations - they are all 2 pixels to wide - grrrr:(

Share this post


Link to post
Share on other sites

I'm due a coffee break so give me 10 minutes to have a look at this. 

(I think I understand what the second part of your process is -  if so it should be doable) 


Due to the fact that Boris Johnson is now our Prime Minister, punctuation, spelling and grammar will never be worried about ever again.  We now have far bigger problems to be concerned about.

Share this post


Link to post
Share on other sites

@carl123 - would you be happy to share the equation you have used to calculate and centre 10% extended canvas?
I have tried clamp, round, floor in my equation but I ended up with 12001 - still one pixel too wide :(  

Share this post


Link to post
Share on other sites

The second part - once the canvas has the correct size of EXACTLY 120% (not a pixel more or less) is just x+w/1.2 and x-w/1.2 for duplicated layers and merging them down.
But to get the exact 120% confounds me.

Share this post


Link to post
Share on other sites

Ok, from what I understand after the 20% canvas resize you need to shift copies of the image left and right to fill in the transparent areas.

I can only test on normal images as I don't have one of your 360 panoramas to see if this works on them.

So you will need to let me know what happens if it's incorrect

To run just select the layer then run the macro 

(There is no need to run the previously supplied macro first)

PS Macro may take a minute or 2 to run on very large documents

 

360-panorama-macro.afmacro


Due to the fact that Boris Johnson is now our Prime Minister, punctuation, spelling and grammar will never be worried about ever again.  We now have far bigger problems to be concerned about.

Share this post


Link to post
Share on other sites

OK, so I can use a macro in a macro 
I used you add10% macro and did the rest in this ExtendPanorama macro and it works fine - only ran a couple of tests.

Still would like to know how to solve the 1 or 2 extra pixel problem.

ExtendPanorama.afmacro

Share this post


Link to post
Share on other sites

Yes, that does the same mine does - but I have to call your add-10% macro in mine since I have been unable to fix the extra pixel problem.

Thank you for all the help.

P.S.: Any hint on how to solve the extra pixel problem??:35_thinking:

Share this post


Link to post
Share on other sites
42 minutes ago, Kronpano said:

I have tried clamp, round, floor in my equation but I ended up with 12001 - still one pixel too wide 

I'm afraid you went down the wrong track when analyzing one of my old macros.

It has nothing to do with clamp, round, or floor - it's a lot simpler than that

I wrote down the important specific value I needed in the equation formula but not all of it so I just need to recreate it fully and will post back shortly.

 


Due to the fact that Boris Johnson is now our Prime Minister, punctuation, spelling and grammar will never be worried about ever again.  We now have far bigger problems to be concerned about.

Share this post


Link to post
Share on other sites

Ok, my first equation used the Polar Coordinate System not the Cartesian

Value (1.1999) as shown in the screenshot below


 

equations.jpg


Due to the fact that Boris Johnson is now our Prime Minister, punctuation, spelling and grammar will never be worried about ever again.  We now have far bigger problems to be concerned about.

Share this post


Link to post
Share on other sites

Thanks for that!!!
I had a play with polar but didn't come up with that formula.
Doesn't really seem intuitive but hey - it works.

Still a shame that the cartesian calculations seem to be out by a pixel - if I do floor(x/1.2) - which I would expect to increase my image to 120% I end up with an extra pixel.
Should have done x/1.1999 all along :D

In a way the 1.1999 in your solution is also just solving a problem that shouldn't be there - some internal rounding errors??

Thanks for all the help - now I can use Affinity photo a bit more for my intended purpose - post-processing panoramas. 

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

×

Important Information

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.