Coder Social home page Coder Social logo

map-coloring's Introduction

map-coloring

Map coloring, using four colors

This program gets a map image as an input and produces all possible valid colorings of that map using backtracking.

The input image background and borders should be white.

Some Basic Stuff to Know

  1. Map coloring
  2. Four color theorem

Algorithm

  1. Detecting all non-white regions (eg. provinces or states).
  2. Converting the input map to a simple planar graph: There will be a node for each region. Two nodes will be adjacent, if and only if their corresponding regions have a common border on the map.
  3. Using backtracking for coloring that graph (it's a recursive function that produces all valid colorings).
  4. Displaying all produced colorings on the given map.

Dependencies

Install numpy, matplotlib and opencv using pip.

pip install -r requirements.txt

Run

python3 map_coloring.py map_image_file_name

Samples

python3 map_coloring.py iran.jpg

The original image:

A part of the program output:

python3 map_coloring.py tehran_province.jpg

The original image:

A part of the program output:

python3 map_coloring.py usa.png

The original image:

A part of the program output:

Notes

It runs slowly on large images. It can be improved by changing the second part of its algorithm (about setting the graph edges). Some computational geometry knowledge about polygons may be needed for this part.

Any contributions are welcomed.

map-coloring's People

Contributors

erfaniaa avatar arturlange avatar

Stargazers

Matthew Truth avatar Muhammad Abhyasa Santoso avatar  avatar  avatar Mingpei Cang avatar Huỳnh Minh Thuận avatar  avatar  avatar  avatar  avatar Liangliang avatar  avatar  avatar Mahdi Darvish avatar Carlos Eduardo Cassimiro avatar Tom Rigal avatar Yash Jain avatar  avatar Soumik Kumar Baithalu avatar Saeid Amiri avatar G.Y Feng avatar ArmanAminian avatar MohammadHasan Pourghannad avatar Amir Hosseini avatar Quentin avatar Shahir Abdullah avatar Daniel Moshayof avatar Acampbell avatar long.chen avatar Dániel Varga avatar Typical Engineer avatar Newton avatar İlker Işık avatar Péterson Sampaio Procópio Júnior avatar Ye Min Htut avatar  avatar Jason Luo avatar Kaung Htet avatar  avatar  avatar Adam Howard avatar Hamit Özdemir avatar Tim Parker avatar Saman Khamesian avatar  avatar Shayan Hosseini avatar Alireza Heydari avatar Mohammad Sadegh avatar Meysam Shirdel avatar Mohammadhossein Zarei avatar Mirmohammad Saadati avatar Toan Tran avatar Arsalan Sefidgar avatar Yahya SayadArbabi avatar

Watchers

 avatar  avatar

map-coloring's Issues

No module named 'resource'

  File "C:\Users\Smkgames\Desktop\map-coloring-master\map_coloring.py", line 3, in <module>
    import resource, sys
ModuleNotFoundError: No module named 'resource'```

Making The Used Algorithm Faster #hacktoberfest

As it's noted on the README page:
It runs slowly on large images. It can be improved by changing the second part of its algorithm (about setting the graph edges). Some computational geometry knowledge about polygons may be needed for this part.

The second part of the algorithm is converting the input map to a simple planar graph: There will be a node for each region. Two nodes will be adjacent, if and only if their corresponding regions have a common border on the map.

If two regions like A and B have N and M vertices respectively, checking whether their corresponding graph nodes should have an edge between them or not takes O(N * M) time complexity. If anyone reduces this complexity by changing the used algorithm, he/she will gain some #hacktoberfest credits.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.