Log in

View Full Version : Cutter program


Jack_Norton
07-22-2004, 11:26 AM
While doing my games I noticed an operation that I do very often: get 2 images, one with a background, and another with an overlay element changed (example a candle, then 2nd image with the candle lit).
Now I do manually make a rectangle that contain the changes (in the example I do a rectangle with the candle flame inside).
Is there a program that automatically detect changes between 2 images and "cut" the right rectangle out of it (storing x,y coordinates)?

I used such a program years ago while I was working in Italy but was an old VB program and now I lost it... :P

ggambett
07-22-2004, 01:01 PM
I don't know any, but it doesn't sound hard to do at all...

Jack_Norton
07-22-2004, 01:28 PM
yes basically you should check pixel-by-pixel the 2 images, and if you find a change (different pixel) then you set the start of the rectangle to cut...

Ehm too hard for me anyway :D

Nikster
07-22-2004, 03:05 PM
As Jack said, dunno if that "too hard for me" quote followed by the grin was sarcasm tho ;) but yeah, you know your resolutions so do a pixel scan from top left to bottom right comparing pixels and store a top left and bottom right value for changes, quite straight forward, however, if you want to do it over multiple frames, you may want to look at fli encoding as this pretty does the same thing.. storing changed pixels, albeit it's designed for 256 colour anims.

oNyx
07-23-2004, 08:00 AM
Ok, I wrote such a thing. Took me a whopping 15 minutes of my life (more than half of it was just C&P ;))

http://www.kaioa.com/DImage.jar (~3kb)

You'll need a somewhat up to date JRE (http://www.java.com). The source is included (open the jar with a zip programm and take a look in the src directory).

It's a command line tool, because it's more flexible this way.

java -jar DImage.jar img1.png img2.png img3.png

img1 and img2 are the two images, which will be compared and img3 is the image which will be written. The output image is always PNG whereas the imput images can be everything ImageIO supports (right now: gif, jpg and png)... so if they ever add some new readers to ImageIO you'll be able to use em without recompiling the programm. I think using png is the best idea.

The coords are just printed on the command line, because it allows you to use it for batch runs.

Eg:
@echo off
java -jar DImage.jar img1a.png img2a.png img3a.png>>bla.txt
java -jar DImage.jar img1b.png img2b.png img3b.png>>bla.txt
[...]
java -jar DImage.jar img1z.png img2z.png img3z.png>>bla.txt

bla.txt will then contain all the coords. (btw ">>" is append, whereas ">" is just write to)

Hm. Writing this post took longer than writing that thingy :>

Jack_Norton
07-24-2004, 01:39 AM
Thanks a lot! I'll try it as soon as I can :)