项目作者: MrEliptik

项目描述 :
Recreate a target images bymaking a mosaic out of multiple input images
高级语言: Python
项目地址: git://github.com/MrEliptik/PyMosaic.git
创建时间: 2019-06-26T19:06:34Z
项目社区:https://github.com/MrEliptik/PyMosaic

开源协议:MIT License

下载


PyMosaic

Recreate a target images by making a mosaic out of multiple input images.

Examples


bond grayscale mosaic examples


bond3 grayscale mosaic examples

Note: Images have been scale down to take less space

Quickstart

To get started quickly you can use the provided example input and target images. The example is using the --grayscale option as it yields better results. Also, the --multithreading option is really important to get sufficient speed. The algorithm is quite long, and without multithreading you’ll wait for a long time, especially if the image is big.

Simply run

  1. make lena_grayscale_multithreading

or use the equivalent script call

  1. python mosaic.py --target_im=images/target/lena.jpg \
  2. --inputs=images/input/ --resize_factor=1 --pixel_density=0.25 \
  3. --grayscale --output_size_factor=5 --contrast \
  4. --multithreading --num_workers=12 --save

To get a detailed list of the arguments, head to How to use section.

  • --resize_factor=1 ensures the initial image size is kept the same when going through it
  • --pixel_density=0.25 tells how big the pixel scanning must be
  • --grayscale to use grayscale mode (yields better results)
  • --output_size_factor=5 the output image will be 5 times the initial image size
  • --contrast applies CLAHE to the image to enhance the constrat before using it

Resulting image


mosaic examples

Note: Image has been scale down to take less space

How to use

You need to run python mosaic.py with the arguments described beneath. Take a look at the makefile to see well working examples.

Makefile

If you want to use the Makefile provided, please change the first line

  1. python-bin = ~/.pyenv/versions/3.6.7/envs/pymosaic/bin/python

to your python bin path.

Required arguments

  • --target_im : Path to target image
  • --inputs : Path to input images

Optional arguments

  • --output_size_factor : How much times the output should be bigger than the target
  • --resize_factor : Factor to resize target image
  • --grayscale : Convert to grayscale
  • --contrast : Apply auto contrast to target image
  • --color_filter : Apply color filters to get closer to the desired color
  • --pixel_density : Path to target image
  • --multithreading : Use multiple thread to create the mosaic
  • --num_workers : Number of workers to use in multithreading
  • --save : Save the output mosaic in results/
  • --show : Show output mosaic

From what I’ve experienced, using --contrast in combination with --grayscale yields the best results. To keep the process short enough, use --multithreading with the highest --num_workers for your machine.

Don’t forget --save to actually save the created mosaic!

How does it work?

I’m in the process of writing a post on my blog to give a detailed tutorial on that.

Requirements

Simply run

  1. pip install -r requirements.txt

TODO

  • [X] Add argument parsing
  • [X] B&W support
  • [X] Be able to select output resolution
  • [X] Add option to save mosaic
  • [X] Add/test contrast increasing before mosaic
  • [X] Use pixel density argument
  • [X] Add color filtering option (for smoother results)
  • [X] Add option to choose to display the output or not
  • [] Add script to download input images (from ImageNet)
  • [] Handle case where kernel size = 1
  • [] Handle case where kernel size is > 1 and < to kmean clusters (3)
  • [] Improve color filtering
  • [] Add web interface

Authors

Want to support me? Buy me a coffee!

Buy Me A Coffee