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)
예제 #2
0
def pool():
    tempdirname = tempfile.mkdtemp()
    pm.rainbow_of_squares(tempdirname, range_params=(0, 256, 30))
    pool = pm.make_pool(os.path.join(tempdirname, '*.png'))

    def delete_dm():
        shutil.rmtree(tempdirname)

    return pool
예제 #3
0
def pool():
    tempdirname = tempfile.mkdtemp()
    pm.rainbow_of_squares(tempdirname, range_params=(0, 256, 30))
    pool = pm.make_pool(os.path.join(tempdirname, "*.png"))

    def delete_dm():
        shutil.rmtree(tempdirname)

    return pool
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
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)
예제 #8
0
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)
예제 #10
0
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)
예제 #11
0
def detail_mosaic(filename, dirname):
    from skimage.io import imread
    image = imread(filename)
    # Size the image to be evenly divisible by the tiles.
    from skimage import img_as_float
    image = img_as_float(image)
    # Use perceptually uniform colorspace for all analysis.
    import photomosaic as pm
    converted_img = pm.perceptual(image)
    pool = pm.make_pool(dirname + '/*.jpg')
    # Adapt the color palette of the image to resemble the palette of the pool.
    adapted_img = pm.adapt_to_pool(converted_img, pool)
    scaled_img = pm.rescale_commensurate(adapted_img,
                                         grid_dims=(30, 30),
                                         depth=1)
    tiles = pm.partition(scaled_img, grid_dims=(30, 30), depth=1)
    annotated_img = pm.draw_tile_layout(pm.rgb(scaled_img), tiles)
    from skimage.io import imsave
    imsave(filename[:-4] + '_detail_mosaic' + filename[-4:], annotated_img)
예제 #12
0
def create_mosaic(input_img, images_dataset_path, grid_dims):

    # Load a sample image
    image = cv2.imread(img_path)
    image = img_as_float(image)  #ensure image is float ranging from 0 to 1

    # Analyze the collection (the "pool") of images.
    pool = pm.make_pool(images_dataset_path)

    # Use perceptually uniform colorspace for all analysis.
    converted_img = pm.perceptual(image)

    # Adapt the color palette of the image to resemble the palette of the pool.
    #adapted_img = pm.adapt_to_pool(converted_img, pool)
    adapted_img = converted_img

    #scale = 1
    #scaled_img = Image.new('RGB', (adapted_img.shape[0] * scale, adapted_img.shape[1] * scale))
    #scaled_img = Image.new('RGB', (5040, 5040))
    scaled_img = pm.rescale_commensurate(adapted_img,
                                         grid_dims=grid_dims,
                                         depth=0)

    tiles = pm.partition(scaled_img, grid_dims=grid_dims, depth=0)

    # Reshape the 3D array (height, width, color_channels) into
    # a 2D array (num_pixels, color_channels) and average over the pixels.
    tile_colors = [
        np.mean(scaled_img[tile].reshape(-1, 3), 0) for tile in tiles
    ]

    # Match a pool image to each tile.
    match = pm.simple_matcher(pool)
    matches = [match(tc) for tc in tile_colors]

    matches_list = [x[0] for x in matches]

    # Perform neural network object detection to see what classes are on which images
    detect_images(matches_list)

    # Concatenate list of matches images to a single mosaic image
    concatenateImages(matches_list, grid_dims)
예제 #13
0
#!/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)
예제 #14
0
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)
예제 #15
0
import os
import photomosaic.flickr
import photomosaic as pm

if not os.path.isfile(os.path.expanduser('~/pools/cats/pool.json')):
    FLICKR_API_KEY = os.environ['FLICKR_API_KEY']
    pm.set_options(flickr_api_key=FLICKR_API_KEY)

    photomosaic.flickr.from_search('cats', '~/pools/cats/')
    pool = pm.make_pool('~/pools/cats/*.jpg')
    pm.export_pool(
        pool, '~/pools/cats/pool.json')  # save color analysis for future reuse
예제 #16
0
        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)
예제 #17
0
import os
import photomosaic as pm


POOL_DIR = '/tmp/photomosaic-docs-pool/'
pm.rainbow_of_squares(POOL_DIR)
pool = pm.make_pool(os.path.join(POOL_DIR, '*.png'))
pm.export_pool(pool, os.path.join(POOL_DIR, 'pool.json'))
예제 #18
0
import os
import photomosaic.flickr
import photomosaic as pm


if not os.path.isfile(os.path.expanduser("~/pools/cats/pool.json")):
    FLICKR_API_KEY = os.environ["FLICKR_API_KEY"]
    pm.set_options(flickr_api_key=FLICKR_API_KEY)

    photomosaic.flickr.from_search("cats", "~/pools/cats/")
    pool = pm.make_pool("~/pools/cats/*.jpg")
    pm.export_pool(pool, "~/pools/cats/pool.json")  # save color analysis for future reuse