You are not logged in.

#1 2008-10-03 14:58:50

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Scripted, fast, 3D-ish image manipulation/animation

Hi there. I'm looking for a way to generate animation of a sort - more along the lines of scripted image manipulation.

My problem isn't the fact that I don't know how; I could easily learn a graphics-oriented programming language tomorrow. It's more of a math illiteracy than anything else.

So, I need something that is able to take images and, without requiring I specify mathematical formula but rather just the applicable angle, distance, lighting etc values, manipulate them QUICKLY (it must be fast, a few seconds or less on a single-core 2GHz system with a low amount of RAM) so they look like the following examples (taken off google image search). I need something that will output to a PNG file, not my screen.

Examples:

http://labs.trolltech.com/blogs/wp-cont … nsform.png
http://www.codeproject.com/KB/WPF/Trans … o/Skew.JPG
http://library.creativecow.net/articles … _group.jpg

Being able to do this sort of thing too - http://www.blargh.com/~danlehen/Boing.PNG - would be awesome.

I don't mind what I use to achieve this goal, as long as it isn't C and its ability to process many frames very quickly is very good. So probably not Java.

-dav7


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#2 2008-10-03 16:30:18

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Scripted, fast, 3D-ish image manipulation/animation

It can be done with GIMP, Python and/or Script-FU (Tiny Scheme). The setup is probably more of a hassle than you want. Blender can be run from the command line and output PNG, but there again the setup may be too much work.

Offline

#3 2008-10-03 16:33:38

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Scripted, fast, 3D-ish image manipulation/animation

I see.

I don't mind "heavy" setup - once it's all configured, if I can run it cleanly and easily, cool. And I hate lisp, so script-fu is (are?) OUT.

Blender... hmm?

-dav7


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#4 2008-10-03 16:58:54

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Scripted, fast, 3D-ish image manipulation/animation

dav7 wrote:

I see.

I don't mind "heavy" setup - once it's all configured, if I can run it cleanly and easily, cool. And I hate lisp, so script-fu is (are?) OUT.

Blender... hmm?

-dav7

GIMP's Python interface is awesome. A basic GIMP Python script would be something like this. It reads in image files of some GIMP readable format, sorts them (image_001.png, image_002.png, .. , image_n.png). Applies the levels filter, then saves the image on top of itself. I wrote this to do some color correction in a directory full of images:

#! /usr/bin/env python
from gimpfu import *
import glob

def levels(file_pattern):

    file_list=glob.glob(file_pattern)

    for file_name in file_list:

        image = pdb.gimp_file_load(file_name, file_name)
        drawable = pdb.gimp_image_get_active_layer(image)

        pdb.gimp_levels(drawable, 0, 127, 255, 1.0, 0, 255)

        pdb.gimp_file_save(image, drawable, file_name, file_name )

        pdb.gimp_image_delete(image)


register(
  "levels", "", "", "", "", "",
  "<Toolbox>/Filters/Python-Fu/_levels", "",
  [
  (PF_STRING, "file_suffix", "file_suffix", "file_suffix")
  ],
  [],
  levels
  )

main()

This is the command to run it (assuming your images are in the current directory and png format). GIMP will process with no GUI using this method.

gimp -inbdf '(python-fu-levels RUN-NONINTERACTIVE "*.png")''(gimp-quit 1)'

In GIMP > 2.4, if you go to Filters-->Python-FU-->Console, it will bring you to the console (imagine that). From there if you go to Browse, you can search for any filter. In your case the perspective tool will be what you need (gimp-drawable-transform-perspective). On the side it will tell you all of the functions as well as their data types. If you double click on that, it will paste the generic form of the function in the console. Copy, paste, and edit from there. All of these values are mutable, which is to say, they can be scripted to change whenever you want them to.

I forgot to mention that GIMP needs to be able to find your scripts. Edit-->Preferences-->Folders-->Plug-Ins is where you define the path.

Last edited by skottish (2008-10-03 17:03:48)

Offline

#5 2008-10-03 17:10:48

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Scripted, fast, 3D-ish image manipulation/animation

Aw, awesome. Very concise and precise big_smile

I am sooo trying this out tomorrow.... big_smile

-dav7


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#6 2008-10-03 17:24:47

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Scripted, fast, 3D-ish image manipulation/animation

dav7 wrote:

Aw, awesome. Very concise and precise big_smile

I am sooo trying this out tomorrow.... big_smile

-dav7

If I can be any help, post back here. I love to do this stuff. In fact, it's the only reason why I've learned any Python!

Offline

#7 2008-10-03 18:27:57

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Scripted, fast, 3D-ish image manipulation/animation

I'm having issues with this method, likely because I'm tired (it isn't tomorrow yet, I was too excited), I've never used Python before, and... meh.

I was hoping I'd be able to say something as simple as (in pseudocode):

image = load_image("...")
save_image(rotate_image(image, 30, 0, 0))

Where the 0, 30, 0 indicate I want it to rotate 30 degrees on the X axis and 0 degrees on the Y and Z axis', producing a slanted-in-sideways effect. I have no idea what x1, y1, .. x4, y4 are supposed to do sad

I get 1x1 image from doing the following guesswork.

>>> image = pdb.gimp_file_load("gimp-test.png", "gimp-test.png")
>>> drawable = pdb.gimp_image_get_active_layer(image)
>>> pdb.gimp_drawable_transform_perspective(drawable, 0, 0, 100, 100, 200, 200, 300, 300, TRANSFORM_FORWARD, INTERPOLATION_LINEAR, True, 3, TRANSFORM_RESIZE_CROP_WITH_ASPECT)
<gimp.Layer 'Background'>
>>> pdb.gimp_file_save(image, drawable, "gimp-test2.png", "gimp-test2.png")
>>>

Also, what am I supposed to save my script to? In your case, "python-fu-levels"?

On a side note, loading the whole of GIMP to modify the perspective of a few images isn't very realtime to me. Isn't there a more lightweight, fast[-starting] way that doesn't involve me using C or being exposed math? hmm A while ago a Google search on the subject turned up 3Drotate, a bash script that performs a bunch of math in the shell then fires some stuff at imagemagick. It's very impressive, but it's only ideal for small images. To rotate a 1400x1050 picture of my desktop took, get this, 30 seconds! So yeah, it was definitely off my list of "tools that will let me create animations"... yikes

Lastly, maybe I'm being a bit hard on Lisp. If Script-Fu makes this easier, I'd like to hear about it. wink

-dav7

Last edited by dav7 (2008-10-03 18:45:55)


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#8 2008-10-03 18:49:28

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Scripted, fast, 3D-ish image manipulation/animation

It's easier to understand what the values mean if you're playing with the filter at the same time. In GIMP 2.6, it's Tools-->Transform Tools-->Perspective. The {x,y} variables associate to the handles at the edge of the image. The other variables correspond to the default settings for other tools. Happily for the most part they're fairly self-explanatory.

Sorry about omitting details about the file. I have a folder in my home directory call gimp_python, and I have GIMP searching it for plug-ins (as described above).

The GIMP-Python naming convention is this. The 'levels' script is called 'levels.py' and is in the above mentioned folder. The calling convention for anything Python is the very ugly 'python-fu-' prefix. The 'py' suffix is omitted from the script file by default. So, 'levels.py' becomes 'python-fu-levels' when you call it. You'll save yourself many headaches if you name the script the same as the file, as well with the plug-in registry (see how many times 'levels' appears in the script to see what I mean. Also, if you use underscores in your script's name, it has to be replaced with a dash when calling it. So 'adjust_levels.py' would be 'python-fu-adjust-levels'.

Another thing that you should know is the 'RUN-NONINTERACTIVE' switch. This is implicitly passed to GIMP, not to your scripts. Everything after it is passed to the Python script like it normally would be. This is necessary if you want to run scripts in batch mode and don't want to control it manually. There are two other values you can pass: RUN-INTERACTIVE and RUN-WITH-LAST-VALS.

Last edited by skottish (2008-10-03 18:51:01)

Offline

#9 2008-10-03 18:52:53

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Scripted, fast, 3D-ish image manipulation/animation

Thanks a heap for that, that cleared up quite a bit.

Now, for take #2...

-dav7


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#10 2008-10-03 19:04:45

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Scripted, fast, 3D-ish image manipulation/animation

I forgot something else extremely important. If your editor of choice is backing up files in the current directory, i.e., levels.py and the last copy is levels.py~, GIMP will always take the last one it finds. File extensions are ignored by Linux, so GIMP will systemically find every file in your plug-ins directory that's registering the plug-in name.

Offline

#11 2008-10-04 03:44:24

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Scripted, fast, 3D-ish image manipulation/animation

Oh ouch. Well thanks for that bit of helpful info!

-dav7


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#12 2008-10-04 03:59:58

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Scripted, fast, 3D-ish image manipulation/animation

Last question: Given one or more degrees and axis, how do I precalculate the x0 .. y4 values relative (if required) to the size of the image?

-dav7

Last edited by dav7 (2008-10-04 04:00:25)


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#13 2008-10-04 04:46:35

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Scripted, fast, 3D-ish image manipulation/animation

I looks as if this about to get into some heavy duty math. So, we can continue with this possible solution and try to draw some math wizards in (I can do this. It's just been 13 years since I looked a problem like this).

Or...

Something like this may work better. It will almost certainly be faster:

http://www.fmwconcepts.com/imagemagick/ … /index.php

Offline

#14 2008-10-04 04:48:33

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Scripted, fast, 3D-ish image manipulation/animation

That script takes 30 seconds to calculate all the offsets for a SINGLE IMAGE!!!! mad

See http://bbs.archlinux.org/viewtopic.php?id=55212.

-dav7

Last edited by dav7 (2008-10-04 04:56:14)


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#15 2008-10-04 05:36:40

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Scripted, fast, 3D-ish image manipulation/animation

dav7 wrote:

That script takes 30 seconds to calculate all the offsets for a SINGLE IMAGE!!!! mad

See http://bbs.archlinux.org/viewtopic.php?id=55212.

-dav7

Holy shit! I had no idea. GIMP is way, seriously, severely faster than that. Plan A it is.

I got to get some sleep. I'll be back in the morning.

Offline

#16 2008-10-04 06:37:18

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Scripted, fast, 3D-ish image manipulation/animation

lol

I agree.

Of course, that 30 second delay is relative to large images like 1400x1050 etc, but since that's the target resolution I'd typically be using... hmm

-dav7


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#17 2008-10-04 09:55:32

bwalk
Member
Registered: 2007-03-21
Posts: 177

Re: Scripted, fast, 3D-ish image manipulation/animation

I still don't exactly know what you are talking about. But you seem to be execced by speed issues so I really recommend writing something of your own. The overhead by invoking existing tools like gimp/convert/mencoder/whatever just crashed your plans.

As I am a graphics guy myself, I recommend OpenGL since it has all your so sophisticated maths builtin. You can render to a file, you can manipulate the framebuffer, you can transform your canvas. Since you don't like C, good news, there are about 231434143 billion bindings for other languages (I wouldn't even be surprised for an ill-designed php-binding).

Oh yeah, cross-posting is considered rude in most forums.

Offline

#18 2008-10-04 11:41:15

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Scripted, fast, 3D-ish image manipulation/animation

bwalk: Well, I'm not concerned about speed except for the fact that I want to generate this stuff quickly, on a slow-ish computer. I'm slowly toning my "SPEED > * !!!!!11356935873" view about everything down and am not really concerned about what I use in the long run, as long as it doesn't take too long to process/complete.

I've wondered if I should use OpenGL, and now you say that... it has all the math built in. Wow, cool. And rendering to a file. Hm. What about... rendering to a fullscreen window? I get 10-13fps from a maximized glxgears window, is there any way I can speed rendering up? Maybe I can prerender all the images to buffers, then play the buffers back in quick succession?

I don't need to manipulate the framebuffer (which is too slow on here anyway). "Transform my canvas"? Perspective transform, you mean? How?

So OpenGL has been ported to 324987569438 other languages. If, however, I write an application in <insert specific langage here> will it run faster? Would using a specific language make the rendering/animation/playback process... slower?

And yes, there apparently is a PHP binding - an ill-documented one, at http://phpopengl.sourceforge.net/ tongue

Thanks to everyone for their help up to this point, by the way.

-dav7

Last edited by dav7 (2008-10-04 11:42:55)


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#19 2008-10-04 12:00:51

bwalk
Member
Registered: 2007-03-21
Posts: 177

Re: Scripted, fast, 3D-ish image manipulation/animation

I'm still confused. Either you can render your stuff in realtime and output it on the screen or render your animation to files and mencode them to a nice movie.

Yeah, by canvas transformation I meant perspective transformations like the ones in your posted links. Just generate the desired matrix for your transformation and apply it to your object/scene/whatever.

The speed you can get with whatever language depends on the overhead the language generates. You can get decent and excellent speed out of top-level languages if your problem fits well to that language, but you have more power and control, the more low-level you go.

Maybe you should describe your project a bit more in detail so we have an imagination what you want to do. Then we can think about a decent solution without tapping through the dark.

Offline

#20 2008-10-04 12:35:58

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Scripted, fast, 3D-ish image manipulation/animation

Ah, perfect. Detailed explanations are one of my finer points big_smile

A toplevel generalized perspective of what I want:

Animation
Both real-time and scheduled (ie dispatched to a render farm for completion in a matter of days or weeks), both simple basic moving of images around on a canvas) and advanced (complex image manipulation functions being exposed to a long, already highly detailed animation), without using math. Since my stronger points don't include math, an animation toolkit that is largely visual or flow-oriented would be awesome here.

Animated user interface design
Heavily inclusive of the previous point, one of my medium- to long-term goals is to design an animation-centric user interface unlike those that exist today. I don't have a very graphically capable PC at the moment, so a system capable of rendering static images to files and then compositing these frames into an animation would be sufficient and preferred, so that I can start with creating some basic mockups.


Some examples:

When I press my printscreen key, I want to merge my screen with and manipulate it as a part of a realtime, live animation that's playing back to demonstrate that a screenshot is being taken.

I have some ideas for window open-close animations that I'd like to do some test renders with.


Of course, the perfect tool for this job would be a hybrid user interface designer / animation timeline editor / image creation system, but I doubt that sort of thing exists. tongue

-dav7


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#21 2008-10-04 13:37:19

bwalk
Member
Registered: 2007-03-21
Posts: 177

Re: Scripted, fast, 3D-ish image manipulation/animation

So basically you want to do what compiz does without the coding?

Offline

#22 2008-10-04 13:50:40

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Scripted, fast, 3D-ish image manipulation/animation

...YEAH! but in a scheduled (render-to-a-movie) kinda way. So I'd want to render to 9436583458274 moderately-sized - like, say, 720x400 - PNG files. Or a 720x400-sized animation.

-dav7

Last edited by dav7 (2008-10-04 13:54:13)


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#23 2008-10-04 15:56:53

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Scripted, fast, 3D-ish image manipulation/animation

Hey everyone.

I can't remember the form to define a transformation matrix by defined angles for a plane in 3D. I know for rotating in 2D the transform is:

cos(theta)  sin(theta)   0
-sin(theta)  cos(theta)  0
0                 0                0

Knowing the generic form for 3D would make it simple to implement. I also don't remember the generic form for distance.

Offline

#24 2008-10-04 16:58:10

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: Scripted, fast, 3D-ish image manipulation/animation

You mean the formula for distance between two points in Euclidean space?

|| v - w || = sqrt( (v1 - w1)² + (v2 - w2)² + (v3 - w3)² )

I don't firmly understand what transformation you want to perform, do you want to tilt the plane with defined angles?
The most generic form of such a matrix would be an SO(3) matrix (Special Orthogonal Group), but I don't know whether there is a simple formula to deduce the matrix elements, in 3D that doesn't look so trivial to me...

Offline

#25 2008-10-04 17:34:40

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Scripted, fast, 3D-ish image manipulation/animation

For some examples of what I want to achieve, see the screenshots in the thread start.

Edit: Oh, and here's another example (the reflection specifically, although, well, I do want to be able to create the box as well): http://img11.nnm.ru/imagez/gallery/b/7/ … 1_full.jpg

-dav7

Last edited by dav7 (2008-10-04 17:51:40)


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

Board footer

Powered by FluxBB