Chained "compare", then removal.

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
agamemnus
Posts: 6
Joined: 2013-09-03T08:34:15-07:00
Authentication code: 6789

Chained "compare", then removal.

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Chained "compare", then removal.

Post 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.
snibgo's IM pages: im.snibgo.com
agamemnus
Posts: 6
Joined: 2013-09-03T08:34:15-07:00
Authentication code: 6789

Re: Chained "compare", then removal.

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Chained "compare", then removal.

Post 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
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Chained "compare", then removal.

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Chained "compare", then removal.

Post by snibgo »

Splendid. It wasn't in the Windows 6.8.6-9 release I downloaded a week ago.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Chained "compare", then removal.

Post 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
agamemnus
Posts: 6
Joined: 2013-09-03T08:34:15-07:00
Authentication code: 6789

Re: Chained "compare", then removal.

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Chained "compare", then removal.

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Chained "compare", then removal.

Post 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.
snibgo's IM pages: im.snibgo.com
agamemnus
Posts: 6
Joined: 2013-09-03T08:34:15-07:00
Authentication code: 6789

Re: Chained "compare", then removal.

Post 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..
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Chained "compare", then removal.

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Chained "compare", then removal.

Post 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.
agamemnus
Posts: 6
Joined: 2013-09-03T08:34:15-07:00
Authentication code: 6789

Re: Chained "compare", then removal.

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Chained "compare", then removal.

Post 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.
Post Reply