PapaSmurf's Wesnoth Map Making Tool (1.3.1)

Discussion of all aspects of multiplayer development: unit balancing, map development, server development, and so forth.

Moderator: Forum Moderators

User avatar
PapaSmurfReloaded
Posts: 841
Joined: November 17th, 2007, 1:10 pm
Location: Argentina

PapaSmurf's Wesnoth Map Making Tool (1.3.1)

Post by PapaSmurfReloaded »

Hello everyone! I created a small python tool that allows you to quickly transform images into Wesnoth map files. It was designed to work with bmp images, but jpg, png, gif, webp files work and others formats may also work. All you need is some software to run python code (for reference, I use Spyder installed via the Anaconda Navigator) and an image of your choice, it's not very complicated. For the most part, it will get the shape about right and save you some time. :D
Attachments
Main code ("menu")
Main code ("menu")
Africa (200 x 200)
Africa (200 x 200)
Pikachu (200 x 200)
Pikachu (200 x 200)
PapaSmurf's Wesnoth Map Making Tool.rar
1.3.1
(6.49 KiB) Downloaded 70 times
Last edited by PapaSmurfReloaded on September 23rd, 2024, 2:38 pm, edited 23 times in total.
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2475
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: PapaSmurf's Wesnoth Map Making Tool

Post by Lord-Knightmare »

Woah. Amazing. I am definitely going to try this out.

Bravo! Well done!
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
Gothyoba
Posts: 112
Joined: December 11th, 2022, 11:20 am
Location: Somewhere along the Multiverse, possibly on Earth

Re: PapaSmurf's Wesnoth Map Making Tool

Post by Gothyoba »

What do I do when it shows the processed image window? It seems to be stuck showing it with the text "Processed Image". Closing the window leads to a crash.

I also have another general question: If I were to make a Wesnoth map using this tool, would I be allowed to publish it on the add-ons server? If so, on what conditions? Thanks!
Whitefang Orc
User avatar
PapaSmurfReloaded
Posts: 841
Joined: November 17th, 2007, 1:10 pm
Location: Argentina

Re: PapaSmurf's Wesnoth Map Making Tool

Post by PapaSmurfReloaded »

Posted v1.1 with a couple nice improvements for user-friendliness and more accurate color to terrain mapping. :eng:
Gothyoba wrote: September 7th, 2024, 7:15 pm What do I do when it shows the processed image window? It seems to be stuck showing it with the text "Processed Image". Closing the window leads to a crash
No idea what might be the issue, did you check if the map actually got generated? In this new version I added an option to not plot the processed image (in case that causes the crash, somehow).
Gothyoba wrote: September 7th, 2024, 7:15 pm I also have another general question: If I were to make a Wesnoth map using this tool, would I be allowed to publish it on the add-ons server? If so, on what conditions? Thanks!
No issue on my part, go for it.
Last edited by PapaSmurfReloaded on September 23rd, 2024, 10:04 pm, edited 2 times in total.
User avatar
Gothyoba
Posts: 112
Joined: December 11th, 2022, 11:20 am
Location: Somewhere along the Multiverse, possibly on Earth

Re: PapaSmurf's Wesnoth Map Making Tool (1.1)

Post by Gothyoba »

I get this error when running _1_main.py after filtering the image:

Traceback (most recent call last):
File "C:\Users\****\_1_main.py", line 111, in <module>
transform_image_to_wesnoth_map(
File "C:\Users\****\_2_code_execution.py", line 51, in transform_image_to_wesnoth_map
terrain_map = classify_color_to_terrain(filtered_image, terrain_color_values, color_dominance_factors)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\****\_3_utils.py", line 93, in classify_color_to_terrain
red, green, blue = image_array[i, j]
^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 3)
Whitefang Orc
User avatar
PapaSmurfReloaded
Posts: 841
Joined: November 17th, 2007, 1:10 pm
Location: Argentina

Re: PapaSmurf's Wesnoth Map Making Tool (1.1)

Post by PapaSmurfReloaded »

Gothyoba wrote: September 8th, 2024, 2:21 pm
Spoiler:
ValueError: too many values to unpack (expected 3)
What format is the image you are trying to convert? Try turning it into a .bmp (24 bit) with Paint.
I think the program is trying to get the Red, Green, Blue values for each pixel, but that image in particular has more info in each pixel than just RGB values, that's why "too many to values unpack".
User avatar
PapaSmurfReloaded
Posts: 841
Joined: November 17th, 2007, 1:10 pm
Location: Argentina

Re: PapaSmurf's Wesnoth Map Making Tool (1.2)

Post by PapaSmurfReloaded »

Posted v1.2: Fixed compatibility with image formats other than bmp.
Last edited by PapaSmurfReloaded on September 23rd, 2024, 10:04 pm, edited 2 times in total.
User avatar
Gothyoba
Posts: 112
Joined: December 11th, 2022, 11:20 am
Location: Somewhere along the Multiverse, possibly on Earth

Re: PapaSmurf's Wesnoth Map Making Tool (1.1)

Post by Gothyoba »

PapaSmurfReloaded wrote: September 8th, 2024, 2:54 pm
Gothyoba wrote: September 8th, 2024, 2:21 pm
Spoiler:
ValueError: too many values to unpack (expected 3)
What format is the image you are trying to convert? Try turning it into a .bmp (24 bit) with Paint.
I think the program is trying to get the Red, Green, Blue values for each pixel, but that image in particular has more info in each pixel than just RGB values, that's why "too many to values unpack".
I will try this again on the new update, but the image was originally a .png converted to .bmp using gimp.

Edit: This works now! I will be getting to work on making something with this! Thanks for making this!
Whitefang Orc
User avatar
PapaSmurfReloaded
Posts: 841
Joined: November 17th, 2007, 1:10 pm
Location: Argentina

Re: PapaSmurf's Wesnoth Map Making Tool (1.3)

Post by PapaSmurfReloaded »

Posted v1.3: Upon classifying the pixel into colors and terrains, the user now also gets to see a pixel classification map.
Last edited by PapaSmurfReloaded on September 23rd, 2024, 10:04 pm, edited 3 times in total.
User avatar
Atreides
Posts: 1243
Joined: March 30th, 2019, 10:38 pm
Location: On the 2nd story of the centre village in Merwuerdigliebe turning the lights on and off

Re: PapaSmurf's Wesnoth Map Making Tool (1.3)

Post by Atreides »

Stupid question. How do you run .py files? (I do have the "snake" on my system)
User avatar
PapaSmurfReloaded
Posts: 841
Joined: November 17th, 2007, 1:10 pm
Location: Argentina

Re: PapaSmurf's Wesnoth Map Making Tool (1.3)

Post by PapaSmurfReloaded »

Atreides wrote: September 10th, 2024, 3:30 pm Stupid question. How do you run .py files? (I do have the "snake" on my system)
From the command prompt, you may also need to install the packages if you don't have them.
Personally, I've always worked with Python using Anaconda + Spyder, it seems easier to me.
User avatar
Elvish_Hunter
Posts: 1600
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: PapaSmurf's Wesnoth Map Making Tool (1.3)

Post by Elvish_Hunter »

I haven't tested the script yet, but this is really a neat concept. Good job!
However, I read the script and noticed two things.
First: you're using the numpy, scipy and matplot libraries. I never needed to use them until now, so can you tell me why did you choose to use them?
Second: if I understood your algorithm correctly, first you scale the image to match the desired map's size (that's the easy part), then you choose the terrain based on each pixel's RGB value. How did you came up with this idea?
As you can see, I'm interested in the reasoning process, because more often than not good ideas are the most important thing :)
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Atreides
Posts: 1243
Joined: March 30th, 2019, 10:38 pm
Location: On the 2nd story of the centre village in Merwuerdigliebe turning the lights on and off

Re: PapaSmurf's Wesnoth Map Making Tool (1.3)

Post by Atreides »

PapaSmurfReloaded wrote: September 11th, 2024, 12:13 am
Atreides wrote: September 10th, 2024, 3:30 pm Stupid question. How do you run .py files? (I do have the "snake" on my system)
From the command prompt, you may also need to install the packages if you don't have them.
Personally, I've always worked with Python using Anaconda + Spyder, it seems easier to me.
Command prompt, yeah I'm an old MS-DOS user, I know it well. So .py files run just like .bat .com & .exe files? Type the name (sans the extension) and off it runs? I'd be surprised because I've not yet seen any Linux files that work like that other than script files made executable (and they don't need any extension, it's the permission bit that does it).
User avatar
PapaSmurfReloaded
Posts: 841
Joined: November 17th, 2007, 1:10 pm
Location: Argentina

Re: PapaSmurf's Wesnoth Map Making Tool (1.3)

Post by PapaSmurfReloaded »

Elvish_Hunter wrote: September 11th, 2024, 10:25 am I haven't tested the script yet, but this is really a neat concept. Good job!
However, I read the script and noticed two things.
First: you're using the numpy, scipy and matplot libraries. I never needed to use them until now, so can you tell me why did you choose to use them?
Second: if I understood your algorithm correctly, first you scale the image to match the desired map's size (that's the easy part), then you choose the terrain based on each pixel's RGB value. How did you came up with this idea?
As you can see, I'm interested in the reasoning process, because more often than not good ideas are the most important thing :)
1) Full disclosure, I had AI assistance in making the code, and when it come to raster data manipulation and plotting, ChatGPT defaults to those. Also, they are very commonly used in raster manipulation.

2) IRL I work with satellite data on a daily basis so I am quite familiar with raster data (grids) work. At first I actually somewhat more "sophisticated" statistical methods used for optical data classification, but they didn't actually work that nicely for this. Then I went to the basics:
"Why does a pixel look red?" Because it has a higher value in the red channel compared to the blue and green channels, and by somewhat significant a margin.
"Well, then, how can I make sure it is bigger by a significant margin while comparing it to others?" Multiply/divide by something.

That's what the color dominance factors are.
For example, if the factor is 1 and the red channel is, let's say, 201, and green and blue channels are 200, it will test if 201/1 is higher than 200, and is gonna be classified as a "red" terrain because it has a higher value in red. Such a pixel in reality would look light gray in reality because the difference in values is negligible.
However, if the factor is 1.25, it will test if the red channel(201) / 1.25 is > than 200 (which isn't in this case).
To pass as a red pixel with such a factor, the red channel value needs to be significantly higher than the others channels.

In the default values, I put red as 1.25 and green and blue 1, because blue surfaces and green surfaces don't normally have a lot of overlap in values in satellite imagery, however red and yellow (made up of red+green) have a lot of overlap. If red's factor was 1, a lot of sand (yellow) would be classified as red, so in red's case I have to be more strict regarding how significantly higher the value has to be, to be considered actually, visually, red.

As for cyan and magenta, Wesnoth doesn't really have much going on the terrain department for those colors, so their color dominance factor is 1.5 to avoid classifying pixel in their single terrain category unless they are REALLY cyan or magenta.

Lastly, there is the gray scale to catch any pixels that failed to classify in any of the previous categories.

Depending on the image, users may need to toy around with the color dominance values to see what works better in their case.
Atreides wrote: September 11th, 2024, 3:21 pm
PapaSmurfReloaded wrote: September 11th, 2024, 12:13 am
Atreides wrote: September 10th, 2024, 3:30 pm Stupid question. How do you run .py files? (I do have the "snake" on my system)
From the command prompt, you may also need to install the packages if you don't have them.
Personally, I've always worked with Python using Anaconda + Spyder, it seems easier to me.
Command prompt, yeah I'm an old MS-DOS user, I know it well. So .py files run just like .bat .com & .exe files? Type the name (sans the extension) and off it runs? I'd be surprised because I've not yet seen any Linux files that work like that other than script files made executable (and they don't need any extension, it's the permission bit that does it).
how to run a py file
Post Reply