Breaking an image down into it's component tiles

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?".
Post Reply
ProgrammingAce

Breaking an image down into it's component tiles

Post by ProgrammingAce »

I've been messing around with this for a bit, and i haven't come up with a good solution yet...

I have a bitmap that's composed of 16x16 px tiles, the bitmap is 256x240 px. I need to break image down into a text file with the tile numbers labeled.

I hope i'm allowed to link an example picture (caution, it's a 1.5 mb bitmap): http://programmingace.com/images/BioForceApe/Level1.bmp

You can see the 4 images are made up of the smaller tiles on the bottom. I need to break them into text data that identifies which tile goes where so I can redraw the screen. I'm thinking I can crop the images into 240 16x16 tiles, then use the -compare option to flag which tiles are identical, but i haven't gotten it to work yet.

So far i've been doing this by hand on paper, but it's taking me about 2 hours per screen. Any help in the right direction would be appreciated.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Breaking an image down into it's component tiles

Post by fmw42 »

If you crop the image and keep the virtual canvas (don't add +repage), then you can do identify on each tile and it will tell you the offsets of each tile and in fact you can rebuild the original image without having to identify the offsets.

see http://www.imagemagick.org/Usage/crop/#crop_tile
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Breaking an image down into it's component tiles

Post by anthony »

If you know the number of tiles in the image, and your IM is very recent you can use a new cropping option that I added at the start of the year....
http://www.imagemagick.org/Usage/crop/#crop_equal

It can also handle the extraction of space separated tiles, such as from a 'montage', or generate overlapping tile images.

Alternativally if you just want to find the tiles that are in an image, you could compare the image against a particular sub tile, so as to locate the position of those tiles in the image. Sorry no examples in IM examples yet, though it has been looked at a number of times on this forum.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply