GithubHelp home page GithubHelp logo

nuno-faria / tiler Goto Github PK

View Code? Open in Web Editor NEW
5.8K 59.0 423.0 13.33 MB

πŸ‘· Build images with images

License: MIT License

Python 100.00%
mosaic-images image-processing python tiling lego minecraft cross-stitch image-builder opencv

tiler's Introduction

title

πŸ‘· Build images with images.

About

Tiler is a tool to create an image using all kinds of other smaller images (tiles). It is different from other mosaic tools since it can adapt to tiles with multiple shapes and sizes (i.e. not limited to squares).

An image can be built out of circles, lines, waves, cross stitches, legos, minecraft blocks, paper clips, letters, ... The possibilities are endless!

Installation

  • Clone the repo: git clone https://github.com/nuno-faria/tiler.git;
  • Install Python 3;
  • Install pip (optional, to install the dependencies);
  • Install dependencies: pip install -r requirements.txt

Usage

  • Make a folder with the tiles (and only the tiles) to build the image;
    • The script gen_tiles.py can help in this task; it builds tiles with multiple colors based on the source tile (note: its recommended for the source file to have an RGB color of (240,240,240)). It is used as python gen_tiles.py path/to/image and creates a folder with a 'gen_' prefix in the same path as the base image.
  • Run python tiler.py path/to/image path/to/tiles_folder/.

Configuration

All configurations can be changed in the conf.py file.

gen_tiles.py

  • DEPTH - number of divisions in each color channel (ex: DEPTH = 4 -> 4 * 4 * 4 = 64 colors);
  • ROTATIONS - list of rotations, in degrees, to apply over the original image (ex: [0, 90]).

tiler.py

  • COLOR_DEPTH - number of divisions in each color channel (ex: COLOR_DEPTH = 4 -> 4 * 4 * 4 = 64 colors);
  • IMAGE_SCALE - scale to apply to the image to tile (1 = default scale);
  • RESIZING_SCALES - scale to apply to each tile (ex: [1, 0.75, 0.5, 0.25]);
  • PIXEL_SHIFT - number of pixels shifted to create each box (ex: (5,5)); if None, shift will be the same as the tile dimension);
  • OVERLAP_TILES - if tiles can overlap;
  • RENDER - render image as its being built;
  • POOL_SIZE - multiprocessing pool size;
  • IMAGE_TO_TILE - image to tile (ignored if passed as the 1st arg);
  • TILES_FOLDER - folder with tiles (ignored if passed as the 2nd arg);
  • OUT - result image filename.

Examples

Circles

Various sizes

Original cake image by pongsakornred from FLATICON.

Fixed

  • 10x10

- 25x25

- 50x50

Paper clips

Cross stitch (times)

Hearts

Legos

Minecraft blocks

Stripes (lines)

At

tiler's People

Contributors

jpcoenen avatar naelsondouglas avatar nuno-faria avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tiler's Issues

conf of examples

Thank you for your job!

Could you share the different args with the examples?

Looking forward to your reply.

[Error] - Running tiler.py

Hi all,

I've tried, and here's the traceback:
image

Here' my Python version:
image

Hope it's usefull !

Thank you.

stuck at "Getting and processing boxes"

when I run python tiler.py path/to/image path/to/tiles_folder/, stuck at "Getting and processing boxes".

Loading tiles
100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 125/125 [00:03<00:00, 32.19it/s]
Getting and processing boxes
0%|

Error running the tiler.py

Get the following error. Missing anything in my usage?

`

python tiler.py images/cake_lego.png ./tiles/clips/
Loading tiles
0%| | 0/2 [00:00<?, ?it/s]path
0%| | 0/2 [00:00<?, ?it/s]
Traceback (most recent call last):
File "tiler.py", line 225, in
main()
File "tiler.py", line 218, in main
tiles = load_tiles(tiles_paths)
File "tiler.py", line 87, in load_tiles
tile = read_image(path + tile_name)
File "tiler.py", line 38, in read_image
img = color_quantization(img.astype('float'), COLOR_DEPTH)
AttributeError: 'NoneType' object has no attribute 'astype'
`

"invalid syntax" or "AttributeError: 'Pool' object has no attribute 'starmap'"

Hi, I can't get your program to work. Indeed,
if I try
D:\Programs\Tiler\tiler-master>python tiler.py images/cake/cake.png tiles/circles/gen_circle_100

I get the message:

Loading tiles
100%|##########| 125/125 [00:02<00:00, 59.44it/s]
Gettting and processing boxes
  0%|          | 0/5 [00:00<?, ?it/s]Traceback (most recent call last):
  File "tiler.py", line 223, in <module>
    main()
  File "tiler.py", line 217, in main
    boxes, original_res = get_processed_image_boxes(image_path, tiles)
  File "tiler.py", line 158, in get_processed_image_boxes
    most_similar_tiles = pool.starmap(most_similar_tile, zip(modes, [ts for x in range(len(modes))]))
AttributeError: 'Pool' object has no attribute 'starmap'
  0%|          | 0/5 [00:17<?, ?it/s]

and if i try D:\Programmes\Tiler\tiler-master>python gen_tiles.py images/cake/cake.png
i get

File "gen_tiles.py", line 45
    f'{out_folder}/{img_name}_{round(r,1)}_{round(g,1)}_{round(b,1)}_r{rotation}.{ext}',
                                                                                      ^
SyntaxError: invalid syntax

It's a bug or I didn't understand the instructions?

AttributeError: 'NoneType' object has no attribute 'shape'

Traceback (most recent call last):
File "tiler.py", line 223, in
main()
File "tiler.py", line 216, in main
tiles = load_tiles(tiles_paths)
File "tiler.py", line 85, in load_tiles
tile = read_image(os.path.join(path, tile_name))
File "tiler.py", line 34, in read_image
if img.shape[2] == 3:

IndexError: tuple index out of range

Traceback (most recent call last):
File "/home/kali/tiler/tiler.py", line 223, in
main()
File "/home/kali/tiler/tiler.py", line 217, in main
boxes, original_res = get_processed_image_boxes(image_path, tiles)
File "/home/kali/tiler/tiler.py", line 151, in get_processed_image_boxes
img = read_image(image_path)
File "/home/kali/tiler/tiler.py", line 34, in read_image
if img.shape[2] == 3:
IndexError: tuple index out of range

No module name cv2

Keep getting this error

Traceback (most recent call last):
File "tiler.py", line 1, in
import cv2
ImportError: No module named cv2

Config details for example output

Hello there and thanks for this awesome repo.

I am trying to manipulate the config parameters to get the awesome results in the readme ,but I can not make that happen.

Can you provide details config for each example ?

TypeError: flip() missing 1 required positional argument: 'axis'

WHEN I RUN :"python tiler.py images/gypsophila.png tiles/at/gen_at" , GET:
File "tiler.py", line 188, in create_tiled_image
place_tile(img,box)
File "tiler.py", line 173, in place_tile
p1 = np.flip(box['pos'])
TypeError: flip() missing 1 required positional argument: 'axis'

Feature : Use vector image or input and output

Hi !
I find this project very attractive artisticly-wise, and I was wondering how big of a deal it would be to use SVGs images as an input in order to have scalable vector graphics at the output.

I know it might sound far-fetched, but are you (or can you) consider it ?

Thanks for your great work,

Cheers !

AttributeError on tiler

Running on VirtualBox. LinuxMint w/ Python 3.7.4

typing

python tiler.py images/myimage.png tiles/lines/gen_line_h

gives me the following:

Loading tiles 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 125/125 [00:00<00:00, 285.37it/s] Gettting and processing boxes 0%| | 0/5 [00:00<?, ?it/s]Traceback (most recent call last): File "tiler.py", line 223, in <module> main() File "tiler.py", line 217, in main boxes, original_res = get_processed_image_boxes(image_path, tiles) File "tiler.py", line 158, in get_processed_image_boxes most_similar_tiles = pool.starmap(most_similar_tile, zip(modes, [ts for x in range(len(modes))])) AttributeError: 'Pool' object has no attribute 'starmap' 0%| | 0/5 [00:33<?, ?it/s]

It takes a long time

I'm working with a 960 * 960 pixel image with circle_100 tile, it takes me about 20 mins. Is it because of the poor performance of my computer? Can I accelerate it with GPU? Looking forward your reply.

Creating tiles with multiple arbitrary Objects?

Just wondering whether the algorithm would still work if you use let's say paperclips and minecraft blocks, that would give a lot more creative freedom, but not sure how the algorithm would hold up with many different shapes.

Can I batch convert?

I want to batch convert several images instead of selecting them one by one, and I don't know how to do it.

AttributeError: 'NoneType' object has no attribute 'astype'

$ python tiler.py path/to/image path/to/tiles_folder/
0it [00:00, ?it/s]
Loading tiles
Gettting and processing boxes
Traceback (most recent call last):
File "tiler.py", line 221, in
main()
File "tiler.py", line 215, in main
boxes, original_res = get_processed_image_boxes(image_path, tiles)
File "tiler.py", line 149, in get_processed_image_boxes
img = read_image(image_path)
File "tiler.py", line 34, in read_image
img = color_quantization(img.astype('float'), COLOR_DEPTH)
AttributeError: 'NoneType' object has no attribute 'astype'
how to deal thanks!

AttributeError: 'NoneType' object has no attribute 'shape'

This is the error
python tiler.py
./images/logo.png ./tiles/minecraft
Loading tiles
99%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Š| 150/151 [00:52<00:00, 2.96it/s]Traceback (most recent call last):
File "tiler.py", line 223, in
main()
File "tiler.py", line 216, in main
tiles = load_tiles(tiles_paths)
File "tiler.py", line 85, in load_tiles
tile = read_image(os.path.join(path, tile_name))
File "tiler.py", line 34, in read_image
if img.shape[2] == 3:
AttributeError: 'NoneType' object has no attribute 'shape'
99%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Š| 150/151 [00:52<00:00, 2.85it/s]

[Solved] AttributeError: 'NoneType' object has no attribute 'astype'

Hello

I am following the usage instructions, but get some trouble.

Firstly, I download the image "https://www.flaticon.com/free-icon/cake_1102780", then use the script:

$ python tiler.py ~/Downloads/1102780.svg ~/Downloads
Loading tiles
  0%|                                                                                                                                                                                                                                                     | 0/7 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "tiler.py", line 221, in <module>
    main()
  File "tiler.py", line 214, in main
    tiles = load_tiles(tiles_paths)
  File "tiler.py", line 83, in load_tiles
    tile = read_image(os.path.join(path, tile_name))
  File "tiler.py", line 34, in read_image
    img = color_quantization(img.astype('float'), COLOR_DEPTH)

And my env:

$ pip freeze
numpy==1.17.2
opencv-python==4.1.1.26
tqdm==4.35.0

Thanks @nuno-faria,I got it

Here is the solution

python tiler.py ~/Downloads/tmp/cake.png tiles/circles/gen_circle_100/

I though the first parameter is my input image, and second parameter as output directory. But it is not, the second parameter is also input, as basic element.

Continually receive IndexError: index 3 is out of bounds for axis 2 with size 3

When trying to generate tiles I receive this with a standard image.

Traceback (most recent call last):
File "tiler.py", line 221, in
main()
File "tiler.py", line 216, in main
img = create_tiled_image(boxes, original_res, render=conf.RENDER)
File "tiler.py", line 186, in create_tiled_image
place_tile(img, box)
File "tiler.py", line 173, in place_tile
mask = box['tile'][:, :, 3] != 0
IndexError: index 3 is out of bounds for axis 2 with size 3

gen_tiles.py fails on certain images

Certain images seem to work, but most fail with a very similar message to the example below

All commands run from tiler's root directory (tiler/)
Run command with .jpg version of image

python3 gen_tiles.py images/test2/test2.jpg

Output

  0%|                                                     | 0/5 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "gen_tiles.py", line 31, in <module>
    new_img = img * [b, g, r, 1]
ValueError: operands could not be broadcast together with shapes (1360,1000,3) (4,) 

Convert image to .png, run command again

python3 gen_tiles.py images/test2/test2.png

Output:

Traceback (most recent call last):
  File "gen_tiles.py", line 23, in <module>
    img = img.astype('float')
AttributeError: 'NoneType' object has no attribute 'astype'

System information:

  • Python 3.7.2
  • pip 18.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
  • Mac OS X 10.14.5

Usage from the readme.md doesn't work

Hello, I just install all requirements into virtualenv with py3 on the board and tried to run tiller.py (with raw config from master branch) on the png image from the sample images dir and nothing happen:

$ mkdir result
$ virtualenv -p python3 .env
...
$ source .env/bin/activate
(.env) $ pip install -r requirements.txt
...
(.env) $ python3 tiler.py images/cake_lego.png ./result/
Loading tiles
0it [00:00, ?it/s]
Gettting and processing boxes
0it [00:00, ?it/s]
Creating tiled image
0it [00:00, ?it/s]
(.env) $ ls ./result/
(.env) $

what's wrong with me?

TypeError: flip() missing 1 required positional argument: 'axis'

The tiler.py fails with the following error:

Creating tiled image
  0%|                                                                                                | 0/999990 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "tiler.py", line 225, in <module>
  File "tiler.py", line 220, in main
    if __name__ == "__main__":
  File "tiler.py", line 190, in create_tiled_image

  File "tiler.py", line 175, in place_tile
    mask = mask[:img_box.shape[0], :img_box.shape[1]]
TypeError: flip() missing 1 required positional argument: 'axis'

Tiler should pre-allocate array before loading tiles

If working on a large image it's possible you won't have enough ram to load, but you have to find this out after the tiles load (which can take a bit). Maybe allocate the buffer first to ensure we have space?

Issue generating tiles

➜ tiler git:(master) python gen_tiles.py ../tiles/Glitch_Purple_RGB.png ../tiles/glitch_tiles
File "gen_tiles.py", line 42
f'{out_folder}/{img_name}{round(r,1)}{round(g,1)}_{round(b,1)}_r{rotation}.{ext}',
^
SyntaxError: invalid syntax

AttributeError: 'NoneType' object has no attribute 'shape'

Get this when I tried to run my first time tiler

Error message:

Loading tiles
  0%|                                                                                                                                                 | 0/13 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "tiler.py", line 223, in <module>
    main()
  File "tiler.py", line 216, in main
    tiles = load_tiles(tiles_paths)
  File "tiler.py", line 85, in load_tiles
    tile = read_image(os.path.join(path, tile_name))
  File "tiler.py", line 34, in read_image
    if img.shape[2] == 3:
AttributeError: 'NoneType' object has no attribute 'shape'

My settings are all correct, they look like this:

# GEN TILES CONFS

# number of divisions per color (R, G and B)
# DEPTH = 4 -> 4 * 4 * 4 = 64 colors
DEPTH = 4
# list of rotations, in degrees, to apply over the original image
ROTATIONS = [0]


#############################


# TILER CONFS

# number of colors per image
COLOR_DEPTH = 32
# tiles scales (1 = default resolution)
RESIZING_SCALES = [0.5, 0.4, 0.3, 0.2, 0.1]
# number of pixels shifted to create each box (tuple with (x,y))
# if value is None, shift will be done accordingly to tiles dimensions
PIXEL_SHIFT = (5, 5)
# if tiles can overlap
OVERLAP_TILES = False
# render image as its being built
RENDER = False
# multiprocessing pool size
POOL_SIZE = 8

# out file name
OUT = 'out.png'
# image to tile (ignored if passed as the 1st arg)
IMAGE_TO_TILE = '/home/orion545/Pictures/57570276_p00.jpg'
# folder with tiles (ignored if passed as the 2nd arg)
TILES_FOLDER = '/home/orion545/BT/tiler/'

I'm using Python3, all dependencies are correctly installed

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.