def computeField(strokesList, rows, cols):
    heightMap = support.loadImage(heightMap_f) / 255.0
    opacityMap = support.loadImage(opacityMap_f) / 255.0
    mapRows, mapCols = support.getSize(heightMap)

    heightField = support.makeMatrix(rows, cols, 0)
    colorField = support.makeVecMatrix(rows, cols, 3)

    # for each stroke
    print "Total = %d" % len(strokesList)
    for index, stroke in enumerate(strokesList):
        ##    if index%20 == 0:
        ##      os.system("pkill -f display")
        ##      support.showImage( heightField )
        if index % 100 == 0:
            print index
        samples = stroke.length

        # compute corner point r and coordinate system
        dirL = stroke.end2 - stroke.end1
        dirW = rotateCW(dirL)
        dirL = impress.normalizeVector(dirL)
        dirW = impress.normalizeVector(dirW)
        r = stroke.end1 - dirW * (stroke.width / 2)

        # step sizes
        stepL = float(stroke.length) / samples
        stepW = float(stroke.width) / samples

        mapStepL = float(mapCols) / samples
        mapStepW = float(mapRows) / samples

        i = 0
        while i < samples:
            j = 0
            while j < samples:
                x = r + dirL * i * stepL + dirW * j * stepW
                if not impress.isOutOfBounds(rows, cols, x):
                    f = impress.interpolate(x[0], x[1], heightField)
                    map_c = i * mapStepL
                    map_r = j * mapStepW
                    h = impress.interpolate(map_r, map_c, heightMap)
                    t = impress.interpolate(map_r, map_c, opacityMap)
                    x = x.astype(int)
                    heightField[x[0], x[1]] = f * (1 - t) + h * t
                    heightField[x[0], x[1]] += fixedHeight
                    colorField[x[0], x[1]] = colorField[x[0], x[1]] * (
                        1 - t) + stroke.color * t
                j = j + 1
            i = i + 1

    heightField = normalizeMatrix(heightField)

    return heightField, colorField
Beispiel #2
0
def lineDrawing(image):
    # load image and create slightly smaller image due to gradients being smaller
    image_mat = support.loadImage(image)
    r, c = support.getSize(image_mat)
    image_mat = image_mat[1:r - 1, 1:c - 1]
    #print(image_mat[0:5,0:5])
    #image_mat = image_mat / 255
    #print(image_mat[0:5,0:5])

    Kx, Ky = utils.makeKernel('sobel')
    Kx, Ky = normalizeMatrix(Kx), normalizeMatrix(Ky)
    Gx, Gy, G, D = utils.getEdges(image, Kx, Ky)

    Tx, Ty = gradientTangents(Gx, Gy)
    print(Tx[0:10, 0:10])
    print(Ty[0:10, 0:10])
    Tx_p, Ty_p = computeETF(Tx, Ty, G)
    print(Tx_p[0:10, 0:10])
    print(Ty_p[0:10, 0:10])
    print("Saving...")
    support.saveImage(Tx, "Tx_p_test")
    support.saveImage(Ty, "Ty__p_test")
    print("Saved")

    return computeFDoG(image_mat, Tx_p, Tx_p)
def testNormFields():
  image = images[image_num]
  heightField = support.loadImage(image[1])
  heightField = heightField / 255.0
  colorField = support.loadImageRGB(image[0])/255.0
  normalField = emboss.computeNormals(heightField)
  emboss.renderFields(normalField, colorField)
def getEdges(image, kernelX, kernelY):
    pixels = support.loadImage(image)
    Gx = convolve(image, kernelX)
    Gy = convolve(image, kernelY)
    G = np.sqrt(Gx * Gx + Gy * Gy)
    D = np.arctan2(Gy, Gx)
    return Gx, Gy, G, D
Beispiel #5
0
def testEagle():  # 500/2000
    image = support.loadImage('eagle.pgm')
    resultPoints, resultCells = stipple.stipple(image)

    image = support.loadImageRGB('eagle.png')
    image = image / 255
    image = colorutils.assignColors(image, resultCells)
    #support.showImage(image)
    support.saveImage(image, "eagle_2000_0.5")
Beispiel #6
0
def testTiffany():  #500/2000
    image = support.loadImage('tiffany.pgm')
    resultPoints, resultCells = stipple.stipple(image)

    image = support.loadImageRGB('tiffany.png')
    image = image / 255
    image = colorutils.assignColors(image, resultCells)
    #support.showImage(image)
    support.saveImage(image, "tiffany_2000_0.65")
Beispiel #7
0
def testTable():  #1500/5000
    image = support.loadImage('table.pgm')
    resultPoints, resultCells = stipple.stipple(image)

    image = support.loadImageRGB('table.png')
    image = image / 255
    image = colorutils.assignColors(image, resultCells)
    #support.showImage(image)
    support.saveImage(image, "table_1500_0.65")
def convolve(image, kernel):
    image_matrix = support.loadImage(image)
    image_rows, image_cols = support.getSize(image_matrix)
    kernel_rows, kernel_cols = support.getSize(kernel)
    kernel_rows, kernel_cols = kernel_rows / 2, kernel_cols / 2

    # A new matrix of zeros of final size of new image
    new_image = support.makeMatrix(image_rows, image_cols)
    # for each row in new image
    for r in range(kernel_rows, image_rows - kernel_rows, 1):
        # for each col in new image
        for c in range(kernel_cols, image_cols - kernel_cols, 1):
            # current matrix of image values
            conveq_matrix = image_matrix[r - kernel_rows:r + kernel_rows + 1,
                                         c - kernel_cols:c + kernel_cols +
                                         1]  # convolve image values and kernel
            new_image[r, c] = conveq(conveq_matrix, kernel)
    return new_image[kernel_rows:image_rows - kernel_rows,
                     kernel_cols:image_cols - kernel_cols]
def convolve(image, kernel):
    image_matrix = support.loadImage(image)
    image_rows, image_cols = support.getSize(image_matrix)
    kernel_rows = support.getRows(kernel)
    new_image_rows = image_rows - kernel_rows
    new_image_cols = image_cols - kernel_rows
    # A new matrix of zeros of final size of new image
    new_image = support.makeMatrix(new_image_rows, new_image_cols)
    # for each row in new image
    for r in range(0, new_image_rows, 1):
        end_row = r + kernel_rows
        # for each col in new image
        for c in range(0, new_image_cols, 1):
            # current matrix of image values
            end_col = c + kernel_rows
            conveq_matrix = image_matrix[r:end_row, c:end_col]
            # convolve image values and kernel
            new_image[r, c] = conveq(conveq_matrix, kernel)
    return new_image
Beispiel #10
0
def halftone(image, depth, renderFunc):

    #convert image to numpy matrix
    image_pix = support.loadImage(image)

    #invert the image
    invert_pix = invertImage(image_pix)

    #initialize rectsList (rectangle at 4 corners of image
    rows, cols = support.getSize(invert_pix)
    #print("size", rows, cols)
    rectsList = []
    rectsList.append(
        Rectangle(Vertex(0, 0, "TL"), Vertex(0, cols - 1, "TR"),
                  Vertex(rows - 1, cols - 1, "BR"), Vertex(rows - 1, 0, "BL")))

    #subdivide rectangles
    rectsList = subdivide(invert_pix, depth, rectsList)

    #call the render function
    return renderFunc(rows, cols, rectsList)
Beispiel #11
0
def lineDrawing(image):
    # load image and create slightly smaller image due to gradients being smaller
    image_mat = support.loadImage(image)
    r, c = support.getSize(image_mat)
    image_mat = image_mat / 255.0

    Kx, Ky = utils.makeKernel('sobel')
    Kx, Ky = Kx / 8.0, Ky / 8.0
    Gx, Gy, G, D = utils.getEdges(image, Kx, Ky)
    image_mat = image_mat[1:r - 1, 1:c - 1]
    G = normalizeMatrix(G)

    Tx, Ty = gradientTangents(Gx, Gy)
    support.saveImage(Tx, "Tx_test")
    support.saveImage(Ty, "Ty_test")
    support.saveImage(Gx, "Gx_test")
    support.saveImage(Gy, "Gy_test")
    Tx_p, Ty_p = computeETF(Tx, Ty, G)
    support.saveImage(Tx, "Tx_p_test")
    support.saveImage(Ty, "Ty_p_test")

    return computeFDoG(image_mat, Tx_p, Tx_p)
Beispiel #12
0
def testfig6b():
    image = support.loadImage("originals/fig6b.png")
    mask = support.loadMatrix("originals/fig6b-mask.npy")
    image = restoreGray(image, mask)
Beispiel #13
0
def testAnimate():
    image = support.loadImage("originals/animation.png")
    mask = support.loadMatrix("originals/animation-mask.npy")
    image = restoreGray(image, mask)
    support.saveImage(image, "animation-9999.png")
Beispiel #14
0
def testfig5():
    image = support.loadImage("originals/fig5.png")
    mask = support.loadMatrix("originals/fig5-mask.npy")
    image = restoreGray(image, mask)
    support.saveImage(image, "fig5-9999.png")
Beispiel #15
0
def testRect():
    image = support.loadImage("originals/rect.png")
    mask = support.loadMatrix("originals/rect-mask.npy")
    image = restoreGray(image, mask)
    support.saveImage(image, "rect-9999.png")
Beispiel #16
0
def testImage():
    image = support.loadImage("fig6b-00.png")
    #image = support.loadImage("originals/fig6b.png")
    print(image)
Beispiel #17
0
import halftone
import support

#images to png
support.saveImage(support.loadImage('monalisa.pgm'), 'monalisa')
support.saveImage(support.loadImage('einstein.pgm'), 'einstein')
support.saveImage(support.loadImage('table.pgm'), 'table')
support.saveImage(support.loadImage('butterfly.pgm'), 'butterfly')


def testRenderDots():
    result = halftone.halftone("monalisa.pgm", 14, halftone.renderDots)
    support.saveImage(result, "monalisa_dots")

    result = halftone.halftone("einstein.pgm", 14, halftone.renderDots)
    support.saveImage(result, "einstein_dots")

    result = halftone.halftone("table.pgm", 14, halftone.renderDots)
    support.saveImage(result, "table_dots")

    result = halftone.halftone("butterfly.pgm", 14, halftone.renderDots)
    support.saveImage(result, "butterfly_dots")


def testRenderOutline():
    result = halftone.halftone("monalisa.pgm", 12, halftone.renderOutline)
    support.saveImage(result, "monalisa_outl")

    result = halftone.halftone("einstein.pgm", 12, halftone.renderOutline)
    support.saveImage(result, "einstein_outl")