Page 1 of 1

how to get quick and dirty Jacobian adaptive blended resize

Posted: 2013-05-13T10:42:13-07:00
by NicolasRobidoux
(To Anthony, especially.)
I need to do something more or less like the following.
I figure that this should be easy with the new IM7 API, but I'm fine with IM6 too. (Custom compile in HDRI, either way.)
Command line or PERL (had to learn this language that many use to put together useful obfuscated abominations). Either way, this will sit inside a PERL script.

Eventual goal:

I want to get quick and dirty Jacobian adaptive blended resize through ImageMagick, in such a way that I get the following:

If the transformation enlarges or keeps dimensions the same (in which case, it's basically no-op), use pure -resize wxh or wxh^ or wxh> (whichever is "asked").

If the transformation shrinks, figure out the resize ratio, which is then automatically less than 1. (For example, if I am doing -resize 50x100 to an image which is 200x400, this ratio is .25.) Let's call this ratio "r".

Then, the output (a ppm, after cropping and a few other shenanigans) is r * [result of -resize] + (1-r) * [result of -distort Resize through linear RGB].

In other words, I'm blending the result of -resize with the result of -distort Resize (through linear light) with a weight that's set up so that if you don't shrink, you get pure -resize, and if you shrink a lot, you almost get pure -distort Resize through linear light.

First step:

Is there an easy way to figure out the Jacobian matrix that corresponds to an aspect ratio preserving operation which could be -resize wxh or wxh> or wxh^?

This Jacobian matrix is a 2x2 diagonal one with the same entry all along the diagonal, because this is a plain resize. Really, I want to know this entry. When the image is halved (50%), it's .5. When it's enlarged by a factor or 2, it's 2.

Of course, the relationship between the output image width and height and the input can be found in the source code for all three of -resize wxh, -resize wxh> and -resize wxh^. I'm hoping I can be lazy.

Re: how to get quick and dirty Jacobian adaptive blended res

Posted: 2013-05-13T10:44:56-07:00
by NicolasRobidoux
Note that in GEGL (the new compute engine of GIMP), I use r^2 as blending factor, not r. For my current work, I want r.

Re: how to get quick and dirty Jacobian adaptive blended res

Posted: 2013-05-13T10:52:53-07:00
by NicolasRobidoux
I'm also not particularly concerned about using the exact value of the ratio. If things are complicated, I may do a dirty estimate.

Re: how to get quick and dirty Jacobian adaptive blended res

Posted: 2013-05-13T20:07:35-07:00
by NicolasRobidoux
I think I found another way to deal with my issues, so I probably will not explore this further.

Re: how to get quick and dirty Jacobian adaptive blended res

Posted: 2013-05-13T23:20:41-07:00
by anthony
I'll wait.

Re: how to get quick and dirty Jacobian adaptive blended res

Posted: 2013-05-21T13:43:56-07:00
by NicolasRobidoux
Turns out my client discards all images that result from enlargement, so this is not needed (by me).