最近在github中发现了一个有趣的小工具,tiler
github链接https://github.com/nuno-faria/tiler
具体介绍请直接去github,这里只分享一下它的使用方法。
需要安装的库在requirements.txt中
可以在cmd中定位到此文下直接使用命令
pip3 install -r requirement.txt安装所需要的库.
如果安装报timeout错误的话可以使用命令此(设置超时为30s)
pip3 install –timeout 30 -r requirements.txt
使用方法非常简单
打开文件夹下的conf.py文件
修改主要的三个参数
python;gutter:true;
out file name
OUT = 'out.png'
image to tile (ignored if passed as the 1st arg)
IMAGE_TO_TILE = None
folder with tiles (ignored if passed as the 2nd arg)
TILES_FOLDER = None</p>
<pre><code>
OUT是输出图片的文件名,可以为默认。
IMAGE_TO_TILE是需要自己修改的,输入图片路径不可以有中文字符,cv2无法打开此图片文件导致之后加载图片报错
TILES_FOLDER参数,是tiles文件夹下文件夹路径
![tiler--python实现的有趣的自定义马赛克图像拼接工具](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20230605/1571794-20190912011512924-1112524658.png)
TILES_FOLDER参数可以是此文件夹下的这些,当然你也可以自己添加一些。
不过要注意的是conf.py是py文件注意字符串要加' '或" "
例如:
TILES_FOLDER = "E:/workSpace/python_bug/tiler-master/tiles/times/gen_times"
测试了一下,我的电脑CPU 酷睿i5 7300U 8GB内存,输入命令运行程序
>python tiler.py
运行中内存占用比较高,原始图片1319x742像素
![tiler--python实现的有趣的自定义马赛克图像拼接工具](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20230605/1571794-20190912093735095-837325833.png)
总共跑了大约1分钟。最终效果:
![tiler--python实现的有趣的自定义马赛克图像拼接工具](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20230605/1571794-20190912093928596-1045339613.png)
最终成品还是比较不错的。
测试图片(图片来自百度图片,侵删)
![tiler--python实现的有趣的自定义马赛克图像拼接工具](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20230605/1571794-20190912104310923-354953069.png)
参数设置:
;gutter:true;
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 = 4
out file name
OUT = ‘min.png’
image to tile (ignored if passed as the 1st arg)
IMAGE_TO_TILE = ‘E:/workSpace/python_bug/tiler-master/in1.jpg’
folder with tiles (ignored if passed as the 2nd arg)
TILES_FOLDER = "E:/workSpace/python_bug/tiler-master/tiles/minecraft"
生成效果
参数设置
python;gutter:true;
number of divisions per color (R, G and B)
DEPTH = 4 -> 4 * 4 * 4 = 64 colors
DEPTH = 128
list of rotations, in degrees, to apply over the original image
ROTATIONS = [0]</p>
<h6></h6>
<p>TILER CONFS</p>
<p>number of colors per image
COLOR_DEPTH = 128
tiles scales (1 = default resolution)
RESIZING_SCALES = [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 = None
if tiles can overlap
OVERLAP_TILES = False
render image as its being built
RENDER = False
multiprocessing pool size
POOL_SIZE = 4</p>
<p>out file name
OUT = 'min2.png'
image to tile (ignored if passed as the 1st arg)
IMAGE_TO_TILE = 'E:/workSpace/python_bug/tiler-master/in1.jpg'
folder with tiles (ignored if passed as the 2nd arg)
TILES_FOLDER = "E:/workSpace/python_bug/tiler-master/tiles/minecraft"
生成效果
可以看出DEPTH,COLOR_DEPTH 是控制图片颜色主要参数。
Original: https://www.cnblogs.com/lingdurebing/p/ldrb-python.html
Author: 零度热冰
Title: tiler–python实现的有趣的自定义马赛克图像拼接工具
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/599339/
转载文章受原作者版权保护。转载请注明原作者出处!