def create_photomosaic(save_photo_dir, background_photo): # 读取背景图片 bg_photo = pm.imread(background_photo) # 读取好友头像图片,定义图片库 pool = pm.make_pool(os.path.join(save_photo_dir, '*.jpg')) # 制作 50*50 的拼图马赛克 image = pm.basic_mosaic(bg_photo, pool, (50, 50)) # 保存结果 pm.imsave('马赛克好友头像图片.jpg', image)
def mosaic(filename, dirname): from skimage.io import imread image = imread(filename) import photomosaic as pm # Analyze the collection (the "pool") of images. pool = pm.make_pool(dirname + '/*.jpg') print(image.shape) mos = pm.basic_mosaic(image, pool, (30, 30), depth=1) from skimage.io import imsave imsave(filename[:-4] + '_mosaic' + filename[-4:], mos)
def basic_mosaic(filename): from skimage.io import imread image = imread(filename) import photomosaic as pm # Generate a collection of solid-color square images. pm.rainbow_of_squares('pool/') # Analyze the collection (the "pool") of images. pool = pm.make_pool('pool/*.png') mos = pm.basic_mosaic(image, pool, (30, 30), depth=1) from skimage.io import imsave imsave(filename[:-4] + '_basic_mosaic' + filename[-4:], mos)
def cat_mosaic(directory): #key image c_image = mpimg.imread(directory) c_image = img_as_float(c_image) #pool of images for mosaic tiles c_pool = pm.make_pool('../Data/folders/train/cat/*.jpg') #mosaic of 250x250 tiles c_mos = pm.basic_mosaic(c_image, c_pool, (100, 100), depth=1) #return mosaic return st.image(c_mos)
def dog_mosaic(directory): #key image #d_image = mpimg.imread(directory) d_image = img_as_float(img) #pool of images for mosaic tiles d_pool = pm.make_pool('Data/folders/train/dog/*.jpg') #mosaic of 250x250 tiles d_mos = pm.basic_mosaic(d_image, d_pool, (100, 100), depth=1) #return mosaic return st.image(d_mos)
def Montage(): """ 将所有的王者荣耀皮肤合并在一张图片上 :return: """ img = cv2.imread('./1.jpg') #所需要拼图的原图 print(img.shape) res = cv2.resize(img, (1100, 1200)) #修改原图的大小并保存, cv2.imwrite('./1.jpg', res) image = pm.imread('./1.jpg') pool = pm.make_pool('./王者荣耀/*.jpg', sample_size=10000) #读取文件夹下的所有图片 mosaic = pm.basic_mosaic(image, pool, (100, 100)) pm.imsave('2s.jpg', mosaic) #保存拼图图片
def gen_pic(): target = '28387.jpg' image = imread(target) dims_list = [(150, 150,), ] # Analyze the collection (the "pool") of images. # pool = pm.make_pool('guinnesscaps/*.jpg') # Generate a collection of solid-color square images. pm.rainbow_of_squares('pool/', range_params=(0, 256, 128)) # Analyze the collection (the "pool") of images. pool = pm.make_pool('pool/*.png') for dims in dims_list: mos = pm.basic_mosaic(image, pool, dims, depth=1) imsave('mosaic_{}.png'.format(target), mos)
def mosaic_batch(test_dirname, dirname): from skimage.io import imread from skimage.io import imsave import photomosaic as pm # Analyze the collection (the "pool") of images. pool = pm.make_pool(dirname + '/*.jpg') filenames = os.listdir(test_dirname) for filename in filenames: if 'mosaic' not in filename and filename.endswith('.jpg'): filename = os.path.join(test_dirname, filename) image = imread(filename) mos = pm.basic_mosaic( image, pool, (int(image.shape[0] / 50), int(image.shape[1] / 50)), depth=1) imsave(filename[:-4] + '_mosaic' + filename[-4:], mos)
import os import photomosaic as pm here = os.path.dirname(__file__) POOL_PATH = '/tmp/photomosaic-docs-pool/pool.json' pool = pm.import_pool(os.path.join(POOL_PATH)) # Load a sample image from skimage import data img = data.chelsea() # cat picture! # Create a mosiac with 15x15 tiles. mos = pm.basic_mosaic(img, pool, (30, 30), depth=1) from skimage.io import imsave imsave( os.path.join(here, '..', '_static', 'generated_images', 'basic-depth1.png'), mos)
import os import photomosaic as pm here = os.path.dirname(__file__) POOL_PATH = '/tmp/photomosaic-docs-pool/pool.json' pool = pm.import_pool(os.path.join(POOL_PATH)) # Load a sample image from skimage import data img = data.chelsea() # cat picture! # Create a mosiac with 15x15 tiles. mos = pm.basic_mosaic(img, pool, (30, 30), depth=1) from skimage.io import imsave imsave(os.path.join(here, '..', '_static', 'generated_images', 'basic-depth1.png'), mos)
def test_basic_mosiac(image, pool): "a smoke test of the integrated workflow" pm.basic_mosaic(image, pool, (5, 5))
import os import photomosaic as pm here = os.path.dirname(__file__) POOL_PATH = '/tmp/photomosaic-docs-pool/pool.json' pool = pm.import_pool(os.path.join(POOL_PATH)) # Load a sample image from skimage import data img = data.chelsea() # cat picture! # Create a mosiac with 15x15 tiles. mos = pm.basic_mosaic(img, pool, (30, 30)) from skimage.io import imsave imsave(os.path.join(here, '..', '_static', 'generated_images', 'basic.png'), mos)
savepath = foldername if not os.path.exists(savepath): os.makedirs(savepath) img.save(saveimgname, "JPEG") trainImgNum += 1 # In[7]: def main(): filename = 'cifar-100-python/train' foldername = "train" saveImage(filename, foldername) if __name__ == "__main__": main() # In[1]: import cv2 img = cv2.imread("hh.jpg") print(img.shape) res = cv2.resize(img, (2400, 1800)) cv2.imwrite("hh_1.jpg", res) # In[10]: import photomosaic as pm image = pm.imread("hh_1.jpg") pool = pm.make_pool('train/*.jpg', sample_size=5000) mosaic = pm.basic_mosaic(image, pool, (480, 360)) pm.imsave('montage2.jpg', mosaic)
from skimage.io import * #read and write images in various formats import sys # for runtime environment import photomosaic as pm from skimage import data #standard test images (image processing) image = data.chelsea()# get chelsea.png #change the img as needed imsave('image.png',image) mosaicSize=(int (sys.argv[1]),int(sys.argv[2])) pm.rainbow_of_squares('square/') #Generate 5832 small solid-color tiles for experimentation and testing into folder 'square/' squarePool=pm.make_pool('square/*.png') mosaic=pm.basic_mosaic(image,squarePool,mosaicSize) outputFile= sys.argv[3] if len(sys.argv)==4 else 'mosaic.png' imsave(outputFile,mosaic)
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/1/2 14:00 # @Author : LiangJiangHao # @Software: PyCharm import photomosaic as pm from PIL import Image imgPath = 'F:\\1.jpg' # im = Image.open(imgPath).convert('RGB') # # 图片的宽度和高度 # w, h = im.size # print(w,h) image = pm.imread(imgPath) # print(image) pool = pm.make_pool('F:\ACimg\*.jpg') print(type(pool)) mosaic = pm.basic_mosaic(image, pool, (10, 10)) pm.imsave('save.jpg', mosaic)