Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - denilsonsa

Pages: [1]
1
Mapping Tips/Guides / Python code to stitch together many screenshots
« on: November 24, 2023, 05:10:17 am »
As part of the creation of one specific map, I wrote a Jupyter Notebook with some Python code to try to semi-automatically crop and align and stitch screenshots. The code isn't perfect, but worked well enough for my needs. It may require a lot of RAM and a lot of patience if you have too many screenshots.

Here → https://gist.github.com/denilsonsa/2922060be4fcddcf7a4e3745a78b5752 ← here!

This notebook is provided as-is. It requires tinkering to make it work! You need to adapt it to your own needs.

If you want to use it, go ahead! No support is provided. Make sure you have Python on your machine, and you know how to use it. It is wise to use virtual environments to install additional packages. Jupyter is optional (you can just use Python code by itself) but recommended, as it provides a very nice notebook interface that aids with debugging and viewing images.

The provided notebook includes the following functions:

  • load_image() → Loads an image from the disk, optionally cropping a known amount of the image (to remove HUD or the player character). Please adapt it to your needs.
  • diff_images() → Given two images and one (x,y) offset, it computes the amount of differences between those images. While that naïve formula worked well enough for my use-case, you may need to tweak it to your needs.
  • find_best_offset() → Given two images, on initial (x,y) offset, and ranges of X and Y variations, it tries to find the best alignment of those two images. It works by nudging the initial offset around, and picking the best match.
  • compute_all_offsets() → You certainly need to edit this function. I used it to iterate over all my screenshots and compute the offset of each one. If you have a multi-core machine, you may want to try to parallelize this function (which is left as an exercise to the reader).
  • save_composite_image() → Given a list of "layers", writes an OpenRaster image. You may need to tweak the image-loading logic in this function.
  • make_batches() and composite_last_image() → You certainly need to edit these functions. They overlay multiple cropped screenshots onto one larger multi-layer image. I decided to split it in multiple batches to prevent having too many layers at once. I'm also skipping a few screenshots to further reduce the amount of layers.
The end result of the code was an OpenRaster image that can be loaded in GIMP. Afterwards I did some manual cleaning up. Since there were many overlapping layers of screenshots, it was easy to discard one of the screenshots in favor of another (due to different animation frames on each screenshot, or any similar issue).

Enjoy!

2
Mapping Tips/Guides / Re: Something to try for image smushing
« on: April 18, 2015, 01:48:57 pm »
I know this topic is a bit old, but I see no reason to install WordPress and that plugin just to losslessly optimize images.

It is possible to just run "optipng" (or "pngcrush", or any tool) through "find" and "xargs", even using all cores available in the machine.

Here is a list of tools I've found (some of them are also used by the WordPress plugin mentioned above):

  • ImageOptim - GUI for Mac OS X that uses several other tools
  • ImageOptim-CLI - command-line tool for Mac OS X
  • PNGGauntlet - GUI for Windows that uses several other tools
  • Trimage - GUI for Linux that uses several other tools
  • PNGOUT and PNGOUTWin - command-line and GUI for Windows
  • OptiPNG - command-line tool, known to be one of the best
  • Pngcrush - command-line tool (one of the oldest for this purpose)
  • PNGOptim - command-line tool for Windows that uses PNGOUT and Zopflipng
  • zopfli - command-line tool, supposedly the best available
  • zopflipng_in_place - script around zopflipng
  • Jpegoptim - command-line lossless and lossy JPEG optimization tool
  • mozjpeg - optimized JPEG compression library
  • scour - command-line tool to optimize SVG files
Of course, there may be others, but I hope this list is useful.

Pages: [1]