Page 1 of 1

Search and replace tiles in a big image ?

Posted: 2016-09-09T06:32:51-07:00
by Musaran
Greetings.


I have a tiled image, size counting in 100 millions pixels.
Similar to this (684 KB extract), except cleaner.

I want to search-and-replace some tiles.
Like this one.


IM can very probably do that, but how ?


Things to know :
  • All tiles are aligned on a 16×16 grid with no offset, and size 16×16 or some small multiple.
  • Pixel content matches exactly.
  • Searched tile may have binary alpha.
  • Replacement tile can be just a solid color, as long as it's unique per tile searched.
  • Maybe I can scale the source images down, but not much.
  • Resulting image may be scaled down to 1/8.
  • I am using the latest IM on Windows 7 x64.

Reading the doc I see...

IM can extract a coordinate list :
compare -subimage-search -metric AE \
haystack.png needle.png miff:- 2>/dev/null |
convert - -delete 0 txt:- | sed -n '/#FFFFFF/s/:.*//p'
But this may be very slow. visgrep might be a fast alternative, but it's for Linux.

IM can easily replace a tile :
composite -geometry +32+64 replace.png big.png \
result.png
But can it read and process above coordinate list ?


Can these operations be chained ?
Can all search-and-replaces be done in one pass ?

Re: Search and replace tiles in a big image ?

Posted: 2016-09-09T06:54:09-07:00
by snibgo
You say "Pixel content matches exactly." But your tile "like this one" (Smbombbmlock.png) isn't in your "684 KB extract" or the larger image (16896x14336), as far as I can see, so I'm not sure what you want to do.

Re: Search and replace tiles in a big image ?

Posted: 2016-09-10T08:47:44-07:00
by snibgo
I might add: IM doesn't have a "search and replace" operation. It can search, and it can replace, but the operations need to be scripted together.

IM's built-in search method is perfectly correct but slow. Many quicker and "probably correct" methods are possible, such as the one on my "Searching an image" page which is massively faster. I am currently extending that to a new method that is even faster, eg 100 times as fast.

Re: Search and replace tiles in a big image ?

Posted: 2016-09-13T03:58:06-07:00
by Musaran
One tile I would actually search in this extract : Image


I am solving this particular problem at (literally) the source by branching the utility that generates those big images.

More work up-front, much easier afterwards.


But the question still stands as that need is bound to happen again.

Maybe the wise way would be to add search-and replace to GIMP or other open-source editors.

Re: Search and replace tiles in a big image ?

Posted: 2016-09-13T04:07:33-07:00
by snibgo
For that image, Google says "403. That’s an error."

Needle

Posted: 2016-09-13T05:03:27-07:00
by Musaran
Okay, Google does not like direct linking...

Link