Automated brushes

Description

Creation of automated brushes, erasers, and imaging features will extend the capabilities of the program and reduce user time in exchange for program overhead.


Examples

There are many methods to automate filling structures such as flood fill, linear regression, and expansion methods.


Flood fill

Flood fill checks surrounding pixels and if they are within a threshold the function will highlight them and then check their neighbor pixels until all the neighbors don't fit the threshold leaving behind a highlight surrounded by the border of the structure.

Example

This is a python flood fill function that takes a click event from the mouse, and check the pixel value and neighbors.

def floodfill(event):
    img_x = event.x
    img_y = event.y
    inside = 1
    frontier = [(img_x,img_y, current_image)];
    while len(frontier) > 0:
        img_x, img_y, ci = frontier.pop()
        neighbors = [
            (img_x,img_y, ci + 1), 
            (img_x,img_y, ci - 1),
            (img_x + 1,img_y, ci),
            (img_x - 1,img_y, ci),
            (img_x, img_y + 1, ci), 
            (img_x, img_y - 1, ci)];
        for n in neighbors:
            nx, ny, nz = n
            if nz < 0 or nz >= len(stack):
                continue
            if nx < 0 or nx >= width:
                continue
            if ny < 0 or ny >= height:
                continue
            c = stack[nz].getpixel((nx, ny));
            if(c > 130 and c != 255):
                frontier.append(n)
                stack[nz].putpixel((nx, ny), 255)
                inside += 1
                pix = stack[nz].load()
                pix[nx, ny] = 255
                if inside % 10000 == 0:
                    print "Frontier:  ", len(frontier)
                if inside % 100000 == 0:
                    refresh_image()
        refresh_image()