lundi 15 avril 2019

How can I Integrate below Two Program to Make new colour-full random image with meaning-full design or patten

Can I Integrate Below two codes to generate Random Meaning full design ???

by passing such images :

sample_1

sample_2

OR, by passing string such as :

-Apple

-@@##$$%

-123

-qwe123!@#

following code generate random meaning-full colours images but, without pattern or design :

import numpy as np, random
from PIL import Image

dX, dY = 512, 512
xArray = np.linspace(0.0, 1.0, dX).reshape((1, dX, 1))
yArray = np.linspace(0.0, 1.0, dY).reshape((dY, 1, 1))

def randColor():
    return np.array([random.random(), random.random(), random.random()]).reshape((1, 1, 3))
def getX(): return xArray
def getY(): return yArray
def safeDivide(a, b):
    return np.divide(a, np.maximum(b, 0.001))

functions = [(0, randColor),
             (0, getX),
             (0, getY),
             (1, np.sin),
             (1, np.cos),
             (2, np.add),
             (2, np.subtract),
             (2, np.multiply),
             (2, safeDivide)]
depthMin = 2
depthMax = 10

def buildImg(depth = 0):
    funcs = [f for f in functions if
                (f[0] > 0 and depth < depthMax) or
                (f[0] == 0 and depth >= depthMin)]
    nArgs, func = random.choice(funcs)
    args = [buildImg(depth + 1) for n in range(nArgs)]
    return func(*args)

img = buildImg()

# Ensure it has the right dimensions, dX by dY by 3
img = np.tile(img, (dX / img.shape[0], dY / img.shape[1], 3 / img.shape[2]))

# Convert to 8-bit, send to PIL and save
img8Bit = np.uint8(np.rint(img.clip(0.0, 1.0) * 255.0))
Image.fromarray(img8Bit).save('./test/output.bmp')


Below code creates a fix-patten using square and circle :

import Tkinter as tk
import tkinter as tk
def get_square(x, y, radius):
    '''
    given the center=(x,y) and radius
    calculate the square for the circle to fit into
    return x1, y1, x2, y2 of square's ulc=(x1,y1) and lrc=(x2,y2)
    '''
    x1 = x - radius
    y1 = y - radius
    x2 = x + radius
    y2 = y + radius
    return x1, y1, x2, y2
# create the basic window, let's call it 'root'
root = tk.Tk()
# create a canvas to draw on
cv = tk.Canvas(root, width=640, height=480, bg='white')
cv.grid()
# draw a series of close spaced circles to create a moire pattern
for k in range(1, 320, 2):
    cv.create_oval(get_square(k, k, k), outline='red')
    cv.create_oval(get_square(640-k, k, k), outline='blue')
    cv.create_oval(get_square(k, 480-k, k), outline='red')
    cv.create_oval(get_square(640-k, 480-k, k), outline='blue')

# start the event loop
root.mainloop()


* Can I mix this two codes to make meaning-full random images by passing any random input as string, special character or number *

Can I add Machine learning to this, to make meaning-full design or pattern.

This is not for Security purpose, this is to make new beautiful pattern using randomness.

Is it possible to train such image to make colourful images ??




Aucun commentaire:

Enregistrer un commentaire