How does Shmeppy find the columns & rows in a background image?

Shmeppy tries to figure out how many columns and rows there are in a Background Image when you upload it.

If it succeeds, the image will appear correctly sized in Shmeppy. If it fails you’ll have to size it yourself (either using the popup that appears when you double-click the image or by Shift+Dragging the edges/corners).

Shmeppy tries each of these steps in order until the size of the image is discovered:

  1. Look for dimensions in the filename.
  2. Detect the dimensions via a computer vision algorithm.
  3. Fallback to using a fixed pixel density.

1. Look for dimensions in the filename

Many images contain the row and column counts in their file names. Shmeppy looks for them in the format COLUMNSxROWS (ex: stream crossing 23x16.jpg).

Sometimes an image will contain the resolution in its filename rather than the row and column count (ex: stream crossing 1472x1024.jpg). So Shmeppy will only use these row and column counts if both image_width / columnsand image_height / rows are greater than 3.

If Shmeppy couldn’t find a suitable value from this, it’ll move onto the next step.

2. Detect the dimensions via a computer vision algorithm

Computer vision is a field in math/engineering that deals with extracting information from an image. OCR programs that read text in images are examples of computer vision algorithms.

Shmeppy uses a computer vision algorithm to count the number of columns and rows in the image. This algorithm will give the correct answer for many images, but it may provide an incorrect answer or no answer at all.

If the algorithm provides an answer (incorrect or not) Shmeppy will use it. Otherwise it’ll move onto the next and final step.

3. Fallback to using fixed values

At this point, Shmeppy has no idea how many columns and rows are in the image. But some answer is needed, otherwise Shmeppy can’t place the background image into the map at all. So Shmeppy just assumes each grid cell in the background image is 60 pixels wide.

This means that the number of columns will be image_width / 60 and the number of rows will be image_height / 60. If either value is less than 2, 2 is used instead.

And that’s it! This step can’t fail, it will always provide an answer so Shmeppy never has to fall back to anything else.

Thanks for working on Shmeppy! Super excited for the next update.

1 Like

Awesome, Gonna Copy some of it an maybe, try to refine…

I made it a wiki if you wanna just edit it.