示例#1
0
def makeImage(height, width, imageName):
    k = 4
    numSamples = 100000000

    imageWidth = min(width, height)
    imageHeight = max(width, height)

    data = [0] * imageHeight * imageWidth

    cx = imageWidth / 2
    cy = imageHeight / 2
    radius = imageWidth / 2 * .85

    for i in range(numSamples):
        theta = uniform(0, 2 * pi)

        pA_x, pA_y = rose(theta, radius, 4, cx, cy)
        pB_x, pB_y = rose(k * theta, radius, 4, cx, cy)

        # pick a random point on the line segment [pA, pB]
        r = uniform(0, 1)
        pC_x = (1 - r) * pA_x + r * pB_x
        pC_y = (1 - r) * pA_y + r * pB_y

        i = int(pC_x + .5)
        j = int(pC_y + .5)

        data[j * imageWidth + i] += 1

    saveImage(data, imageName, imageWidth, imageHeight, fg=[128, 0, 64])
示例#2
0
def makeImage(height, width, imageName):
    kA = 4
    kB = 7
    numSamples = 100000000

    imageWidth = min(width, height)
    imageHeight = max(width, height)

    data = runDataCalculations(imageWidth, imageHeight, numSamples, kA, kB)

    saveImage(data, imageName, imageWidth, imageHeight, fg=[0, 128, 128])
示例#3
0
def labellizeImage(filePath, savePath, nbFrag, client):
    image = getImage(filePath)
    labels = []

    for n in range(1, nbFrag):
        fragments = cut(image, n)
        #print("Image découpée en " + str((n+1)*(n+1)))

        w, h = image.size
        dw = w / n
        dh = h / n
        x = y = 0
        for fragment in fragments:
            newLabels = labellize(fragment, client)

            for label in newLabels:
                vertices = label.bounding_poly.normalized_vertices
                for vertex in vertices:
                    vertex.x += x
                    vertex.y += y
            y += dh
            if y >= h:
                y = 0
                x += dw

            labels.extend(newLabels)


#		print("Fragments labellisés, " + str(len(labels)) + " labels")
#	lbls = []

#	for label in labels:
#		lbls.append(Label(label.name, label.bounding_poly, label.score))

#	labels = connectLabels(labels)
#	print("Fragements connectés : " + str(len(labels)) + " fragments restants")
#print (json.dumps(lbls))
#	text = jsonpickle.encode(labels[0])
#	print(text)
#print(dir(labels[0]))
    drawn = drawImage(image, labels)
    #print("Image dessinée")

    saveImage(drawn, savePath)
    json = listToJson(labels)
    savePath = savePath[:-4]
    savePath += ".json"
    with open(savePath, 'w') as file:
        file.write(json)
示例#4
0
def makeImage(height, width, imageName):
    kA = 5
    kB = 2
    numSamples = 100000000

    imageWidth = width
    imageHeight = height

    data = [0] * imageHeight * imageWidth

    cx = imageWidth / 2
    cy = imageHeight / 2
    radius = imageWidth / 2 * .07

    outerRadius = 8
    innerRadius = 1
    d = 7

    for i in range(numSamples):
        # need to increase range for complete curve
        theta = uniform(0, 30 * pi)

        pA_x, pA_y = hypotrochoid(kA * theta, radius, outerRadius, innerRadius,
                                  d, cx, cy)
        pB_x, pB_y = hypotrochoid(kB * theta, radius, outerRadius, innerRadius,
                                  d, cx, cy)

        # pick a random point on the line segment [pA, pB]
        r = uniform(0, 1)
        pC_x = (1 - r) * pA_x + r * pB_x
        pC_y = (1 - r) * pA_y + r * pB_y

        i = int(pC_x + .5)
        j = int(pC_y + .5)

        data[j * imageWidth + i] += 1

    saveImage(data,
              imageName,
              imageWidth,
              imageHeight,
              bg=[255, 255, 255],
              fg=[15, 15, 0],
              alphaMultiplier=10)
示例#5
0
def makeImage(height, width, imageName):
    kA = 101
    kB = 2
    numSamples = 1000000000

    imageWidth = width
    imageHeight = height

    data = [0] * imageHeight * imageWidth

    cx = imageWidth / 2
    cy = imageHeight / 2
    radius = imageWidth / 2

    circRadius = radius * .9
    hypoRadius = radius * .0275

    for i in range(numSamples):
        theta = uniform(0, 2 * pi)

        pA_x, pA_y = circle(kA * theta, circRadius, cx, cy)
        pB_x, pB_y = hypotrochoid(kB * theta, hypoRadius, hypoRadius,
                                  1 / 17 * hypoRadius, 1.1 * hypoRadius, cx,
                                  cy)

        # pick a random point on the line segment [pA, pB]
        r = uniform(0, 1)
        pC_x = (1 - r) * pA_x + r * pB_x
        pC_y = (1 - r) * pA_y + r * pB_y

        i = int(pC_x + .5)
        j = int(pC_y + .5)

        data[j * imageWidth + i] += 1

    saveImage(data,
              imageName,
              imageWidth,
              imageHeight,
              bg=[255, 255, 255],
              fg=[[0, 0, 159], [228, 171, 0]],
              alphaMultiplier=4)
示例#6
0
def makeImage(height, width, imageName):
    kA = 9
    kB = 17
    numSamples = 100000000

    imageWidth = width
    imageHeight = height

    data = [0] * imageHeight * imageWidth

    cxA = imageWidth / 4
    cyA = imageHeight / 4

    cxB = 3 * imageWidth / 4
    cyB = 3 * imageHeight / 4

    radius = imageWidth / 4.5

    for i in range(numSamples):
        theta = uniform(0, 2 * pi)

        pA_x, pA_y = circle(kA * theta, radius, cxA, cyA)
        pB_x, pB_y = circle(kB * theta, radius, cxB, cyB)

        # pick a random point on the line segment [pA, pB]
        r = uniform(0, 1)
        pC_x = (1 - r) * pA_x + r * pB_x
        pC_y = (1 - r) * pA_y + r * pB_y

        i = int(pC_x + .5)
        j = int(pC_y + .5)

        data[j * imageWidth + i] += 1

    saveImage(data,
              imageName,
              imageWidth,
              imageHeight,
              bg=[255, 255, 255],
              fg=[0, 64, 0],
              alphaMultiplier=5)
示例#7
0
def makeImage(height, width, imageName):
    kA = -1
    kB = 4
    numSamples = 100000000

    imageWidth = width
    imageHeight = height

    data = [0] * imageHeight * imageWidth

    cx = imageWidth / 2
    cy = imageHeight / 2
    radius = imageWidth / 2 * .95

    radius1 = radius * .65
    radius2 = radius * .075

    for i in range(numSamples):
        theta = uniform(0, 16 * pi)

        pA_x, pA_y = square(kA * theta, radius1, cx, cy, pi / 4)
        pB_x, pB_y = hypotrochoid(kB * theta, radius2, 12, 3.5, 5.5, cx, cy)

        # pick a random point on the line segment [pA, pB]
        r = uniform(0, 1)
        pC_x = (1 - r) * pA_x + r * pB_x
        pC_y = (1 - r) * pA_y + r * pB_y

        i = int(pC_x + .5)
        j = int(pC_y + .5)

        data[j * imageWidth + i] += 1

    saveImage(data,
              imageName,
              imageWidth,
              imageHeight,
              bg=[255, 255, 255],
              fg=[110, 2, 137],
              alphaMultiplier=4)
示例#8
0
def makeImage(height, width, imageName):
    kA = 9
    kB = 17
    numSamples = 100000000

    imageWidth = width
    imageHeight = height

    data = [0] * imageHeight * imageWidth

    cx = imageWidth / 2
    cy = imageHeight / 2
    radius = imageWidth / 2 * .95

    offsetCx = cx + radius / 3
    offsetRadius = radius / 1.5

    for i in range(numSamples):
        theta = uniform(0, 2 * pi)

        pA_x, pA_y = circle(kA * theta, radius, cx, cy)
        pB_x, pB_y = circle(kB * theta, offsetRadius, offsetCx, cy)

        # pick a random point on the line segment [pA, pB]
        r = uniform(0, 1)
        pC_x = (1 - r) * pA_x + r * pB_x
        pC_y = (1 - r) * pA_y + r * pB_y

        i = int(pC_x + .5)
        j = int(pC_y + .5)

        data[j * imageWidth + i] += 1

    saveImage(data,
              imageName,
              imageWidth,
              imageHeight,
              bg=[255, 255, 255],
              fg=[128, 0, 0],
              alphaMultiplier=10)
示例#9
0
def makeImage(height, width, imageName):
    kA = 7.9
    kB = 11
    numSamples = 100000

    imageWidth = min(width, height)
    imageHeight = max(width, height)

    for numSamples in (100000, 100000000):

        data = [0] * imageHeight * imageWidth

        cx = imageWidth / 2
        cy = imageHeight / 2
        radius = imageWidth / 2 * .95

        for i in range(numSamples):
            theta = uniform(0, 2 * pi)

            pA_x, pA_y = circle(kA * theta, radius, cx, cy)
            pB_x, pB_y = circle(kB * theta, radius, cx, cy)

            # pick a random point on the line segment [pA, pB]
            r = uniform(0, 1)
            pC_x = (1 - r) * pA_x + r * pB_x
            pC_y = (1 - r) * pA_y + r * pB_y

            i = int(pC_x + .5)
            j = int(pC_y + .5)

            data[j * imageWidth + i] += 1

        imageNameCnt = re.sub(r"image", f"image_{numSamples}", imageName)

        saveImage(data,
                  imageNameCnt,
                  imageWidth,
                  imageHeight,
                  bg=[255, 255, 255],
                  fg=[0, 0, 0])
示例#10
0
def makeImage(height, width, imageName):
    kA = 5
    kB = -3
    numSamples = 100000000
 
    imageWidth = width
    imageHeight = height

    data = [0] * imageHeight * imageWidth

    cx = imageWidth/2
    cy = imageHeight/2
    radius  = imageWidth/2 * .95

    numSquares = 8
    squareRadius = radius/2

    for s in range(numSquares):
        rotAng =  s * pi/4
        cx_s = cos(pi/4 * s) * radius/2 + cx
        cy_s = sin(pi/4 * s) * radius/2 + cy

        for i in range(numSamples):
            theta = uniform(0, 2 * pi)
            
            pA_x, pA_y = circle(kA * theta, radius, cx, cy)
            pB_x, pB_y = square(kB * theta, squareRadius, cx, cy, rotAng)
            
            # pick a random point on the line segment [pA, pB]
            r = uniform(0, 1)
            pC_x = (1 - r) * pA_x + r * pB_x
            pC_y = (1 - r) * pA_y + r * pB_y
            
            i = int(pC_x + .5)
            j = int(pC_y + .5)
            
            data[j * imageWidth + i] += 1
        
    saveImage(data, imageName, imageWidth, imageHeight,
              bg=[255, 255, 255], fg=[0, 110, 137], alphaMultiplier=4)
示例#11
0
def makeImage(height, width, imageName):
    kA = 4
    kB = 3
    numSamples = 100000000

    imageWidth = width
    imageHeight = height

    data = [0] * imageHeight * imageWidth

    cx = imageWidth / 2
    cy = imageHeight / 2
    radius = imageWidth / 2 * .95

    radius2 = radius * .9

    for i in range(numSamples):
        theta = uniform(0, 32 * pi)

        pA_x, pA_y = rose(kA * theta, radius, 4 / 5, cx, cy)
        pB_x, pB_y = rose(kB * theta, radius2, 2 / 5, cx, cy)

        # pick a random point on the line segment [pA, pB]
        r = uniform(0, 1)
        pC_x = (1 - r) * pA_x + r * pB_x
        pC_y = (1 - r) * pA_y + r * pB_y

        i = int(pC_x + .5)
        j = int(pC_y + .5)

        data[j * imageWidth + i] += 1

    saveImage(data,
              imageName,
              imageWidth,
              imageHeight,
              bg=[255, 255, 255],
              fg=[96, 43, 25],
              alphaMultiplier=5)
示例#12
0
def makeImage(height, width, imageName):
    k = 1.9
    numSamples = 100000000

    imageWidth = width
    imageHeight = height

    data = [0] * imageHeight * imageWidth

    cx = imageWidth / 2
    cy = imageHeight / 2
    radius = imageWidth / 2 * .95

    for i in range(numSamples):
        # need to increase range for complete curve
        theta = uniform(0, 10 * pi)

        pA_x, pA_y = lemniscate(theta, radius, cx, cy)
        pB_x, pB_y = lemniscate(k * theta, radius, cx, cy)

        # pick a random point on the line segment [pA, pB]
        r = uniform(0, 1)
        pC_x = (1 - r) * pA_x + r * pB_x
        pC_y = (1 - r) * pA_y + r * pB_y

        i = int(pC_x + .5)
        j = int(pC_y + .5)

        data[j * imageWidth + i] += 1

    saveImage(data,
              imageName,
              imageWidth,
              imageHeight,
              bg=[255, 255, 255],
              fg=[221, 100, 0],
              alphaMultiplier=18)
示例#13
0
def makeImage(height, width, imageName):
    kA = 1
    kB = 2
    numSamples = 100000000

    imageWidth = min(width, height)
    imageHeight = max(width, height)

    data = [0] * imageHeight * imageWidth

    cx = imageWidth / 2
    cy = imageHeight / 2
    radius = imageWidth / 2 * .85

    for i in range(numSamples):
        # Note: using 10 * pi.  If only 2 * pi, whole image is not drawn
        theta = uniform(0, 10 * pi)

        pA_x, pA_y = rose(kA * theta, radius * .9, 1.2, cx, cy)
        pB_x, pB_y = circle(kB * theta, radius, cx, cy)

        # pick a random point on the line segment [pA, pB]
        r = uniform(0, 1)
        pC_x = (1 - r) * pA_x + r * pB_x
        pC_y = (1 - r) * pA_y + r * pB_y

        i = int(pC_x + .5)
        j = int(pC_y + .5)

        data[j * imageWidth + i] += 1

    saveImage(data,
              imageName,
              imageWidth,
              imageHeight,
              fg=[0, 128, 128],
              alphaMultiplier=6)