Page 1 of 2

Chained "compare", then removal.

Posted: 2013-09-03T08:43:43-07:00
by agamemnus
Hello,

I have used imagemagick to put together some rendered images into a sprite map. The sprite map, on the horizontal axis, has different orientations. On the vertical axis, it has different animations. I want to reduce the file size, so what I need is to find all common points for each column of images and then remove all those points for every image except the first in the column. I started with the "compare" function but I'm running into a few roadblocks to the point where I'm completely stuck. Help!

Here is one sprite map: (each image is 256x256 pixels)
http://capitalopoly.com/images/vehicles ... orward.png

Re: Chained "compare", then removal.

Posted: 2013-09-03T09:39:48-07:00
by snibgo
I don't understand what you want to do. Something you could do is:

1. Crop the image into rows.

2. For each row apart from the top row, paint black all pixels that haven't changed from the row above it.

3. Reassemble the rows into the full picture.

Is that what you want? I don't know if that would reduce the file size.

Re: Chained "compare", then removal.

Posted: 2013-09-03T10:34:44-07:00
by agamemnus
Not black, transparent.

I can fit this into my assembler code, so I can just use source images instead of cropping... just looking for the right commands for this.

I guess I need to chain the compare function, maybe? -- any idea how to chain something like:

compare vehicles/t1.png vehicles/t2.png -compose Src vehicles/t3.png

Then I need to subtract those pixels... don't know how.

Re: Chained "compare", then removal.

Posted: 2013-09-03T11:04:34-07:00
by snibgo
You'll probably need one of the "-compose ... -composite" operations. Or if you want to do a compare within a convert, you'll be able to do that very soon now; see viewtopic.php?f=2&t=23943

Re: Chained "compare", then removal.

Posted: 2013-09-03T11:10:55-07:00
by fmw42
snibgo wrote:You'll probably need one of the "-compose ... -composite" operations. Or if you want to do a compare within a convert, you'll be able to do that very soon now; see viewtopic.php?f=2&t=23943
It is already in 6.8.6-9

Re: Chained "compare", then removal.

Posted: 2013-09-03T12:13:15-07:00
by snibgo
Splendid. It wasn't in the Windows 6.8.6-9 release I downloaded a week ago.

Re: Chained "compare", then removal.

Posted: 2013-09-03T13:51:23-07:00
by fmw42
snibgo wrote:Splendid. It wasn't in the Windows 6.8.6-9 release I downloaded a week ago.
This works for me on IM 6.8.6.9 Q16 Mac OSX

convert rose: \( rose: -blur 0x3 \) -metric RMSE -compare -format "%[distortion]" info:
0.10396026946004832681

Unfortunately, -precision does not work to limit the output


convert -precision 5 rose: \( rose: -blur 0x3 \) -metric RMSE -compare -format "%[distortion]" info:
0.10396026946004832681

Re: Chained "compare", then removal.

Posted: 2013-09-03T15:45:02-07:00
by agamemnus
Hmm.. I think a -compose with xor will work. I guess I just need to compare the first image with the 2nd, 3rd, 4th, 5th, 6th, 7th, and 8th. I am really confused about all this chaining though.. what would be the best way to do this? Here are some parameters--

The image is 2048x2048. (link is in the initial post) There are 8x8 sprites. I need to do the -compose operation 56 times -- 7 times for each column, going down 256 pixels each time.

I could also do this with a copy of the initial input images I suppose.. that is conceptually easier.

Thoughts?

Re: Chained "compare", then removal.

Posted: 2013-09-03T15:50:19-07:00
by fmw42
What exactly are you trying to do? I do not understand your first post about removing points. If user snibgo understands, then I will leave it to him.

Re: Chained "compare", then removal.

Posted: 2013-09-03T16:28:30-07:00
by snibgo
I don't understand what is wanted.

I don't understand the issue about chaining. Perhaps this means the way that multiple commands can be combined. I suggest that this doesn't matter yet. Worry about that only when the details of each step is defined.

In my first post, I identified three possible steps. Here is a Windows script that implements steps 1 and 2.

First, I flatten the image against a white background and split off the first two rows into o1.png and o2.png. Then I find the difference between the rows: pixels that are the same become black; the rest become white. Finally I take o2.png, making most of the pixels (the ones that haven't changed from o1.png) transparent black.

Code: Select all

%IM%convert "osprey-rotors forward.png" ^
  -background White ^
  -layers flatten ^
  ( -clone 0 -crop 2048x256+0+0 +repage -write o1.png ) ^
  ( -clone 0 -crop 2048x256+0+256 +repage -write o2.png ) ^
  NULL:

%IM%convert ^
  o1.png o2.png ^
  -compose MinusSrc -composite ^
  -fill White +opaque Black ^
  od.png

%IM%convert ^
  o2.png ^
  od.png ^
  -compose CopyOpacity -composite ^
  -background Black -alpha background ^
  o2d.png
If this is correct, then the three commands could be repeated for the other rows, and they could all be combined into a single (long) command.

I don't see any need to split each row into its sprites, especially if they are all to be combined into a single image.

Re: Chained "compare", then removal.

Posted: 2013-09-03T16:30:45-07:00
by agamemnus
Ok, thanks for that code.. I guess I need to do some more thinking here. I don't think the earlier mechanism described a few posts above is correct. I really do need to get the common points, then remove them for each image, and save them as a new row.

Edit: not sure about flattening to a white background bit... but I think I see your general idea. I can take the image created after combining the 7th and last row, then xor against all the images, taking the inverse of that and storing it as the new first row for the first time. I think I got it, conceptually and mostly got the syntax..

Re: Chained "compare", then removal.

Posted: 2013-09-03T16:40:48-07:00
by snibgo
I've just seen that my code doesn't do exactly what I think may be wanted. The final command makes pixels from o2.png transparent, but I think it would be better if it worked on the row before it is flattened against white.

Re: Chained "compare", then removal.

Posted: 2013-09-03T18:17:12-07:00
by glennrp
Look at the "-deconstruct" option. It does essentially what you are trying to accomplish, if you run it on each animation sequence separately.

Re: Chained "compare", then removal.

Posted: 2013-09-03T21:01:53-07:00
by agamemnus
glennrp wrote:Look at the "-deconstruct" option. It does essentially what you are trying to accomplish, if you run it on each animation sequence separately.
Just looked at the description of that. It is designed for a more processed set of images in that you already have a base image as the first image, and the others are additions to the first image. In other words, if my first image was a helicopter without the rotors, and the others had the rotors, I could use that. But if all the images have rotors, I first need to find a common base of pixels to start with.

Re: Chained "compare", then removal.

Posted: 2013-09-03T21:29:54-07:00
by fmw42
see -evaluate-sequence with And, Or, Xor whatever you need. http://www.imagemagick.org/script/comma ... e-sequence. Use

convert -list evaluate

to get the full list of options.