Mobile app version of vmapp.org
Login or Join
Bethany839

: Script to color parts of image based on input data I have a picture of a map of Europe with proper borders. I need to color each country in different shades of color according to certain

@Bethany839

Posted in: #Automation

I have a picture of a map of Europe with proper borders.
I need to color each country in different shades of color according to certain properties of the country. This is trivial manually in PS or GIMP with the Fill tool. However, I need to do it many times over, with different colors for different use cases, so I would want to automate it. I'm comfortable programming, but have zero experience in scripting graphical tools.

Any hints on what the best way to do it would be? Imagemagick, Gimp? If at all possible, I would prefer free tools (since it's a one off thing, i dont want to invest into PS).

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Bethany839

2 Comments

Sorted by latest first Latest Oldest Best

 

@Sims5801359

I'd be tempted to write my own code in my favourite language using the ImageMagick library.

You could create a lookup table with names of countries linked to a point (or points if there are islands) within their borders, then you can pass the name of the country to flood fill it.

Handling anti-aliased edges might be difficult though.

10% popularity Vote Up Vote Down


 

@Cofer715

If I were to do this "from the ground up," I might make each country shape its own layer black only, with the layers named uniquely, and apply a layer effect "color overlay." To achieve the desired color, and a stroke to define the outline. If there is more detail to the map, and you only want to alter the background color, you can overlay other items with a different layer.

Flood fill can be tricky depending on non-contiguous areas and anti-aliasing of the item, so the layer effect would probably give you an easier time.

To view all countries, you toggle all layers visible. To programmatically change a color, you can now reference the layer by its unique ID, and then alter the color overlay property.

The specifics of how to do this will depend on your need and the program you use. I know that both GIMP and PS are scriptable (and AFAIK, support color overlay and stroke).

With Photoshop, you can use vbscript and then have access to the OS file system (I don't think javascript allows this?). The benefit of this is that you could create a data file with the country's layer name and color info (etc) and possibly calculate different things on the fly. It also supports variables and data files IIRC (the limits of which I am not familiar).

Knowing open source, GIMP probably gives you deeper access to the backend for scripting.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme