Beispiel #1
0
def threshold(pixels, image, angle):
    intervals = []

    for y in range(len(pixels)):
        intervals.append([])
        for x in range(len(pixels[0])):
            if util.lightness(pixels[y][x]) < 0.25 or util.lightness(
                    pixels[y][x]) > 0.8:
                intervals[y].append(x)
        intervals[y].append(len(pixels[0]))
    return intervals
Beispiel #2
0
def threshold(pixels, image, angle):
    intervals = []

    
    for y in range(len(pixels)):
        intervals.append([])
        for x in range(len(pixels[0])):
            if util.lightness(pixels[y][x]) < 0.25 or util.lightness(pixels[y][x]) > 0.8:
                intervals[y].append(x)
        intervals[y].append(len(pixels[0]))
    return intervals
Beispiel #3
0
def threshold(image, lower_threshold, upper_threshold, **kwargs):
    intervals = []
    image_data = image.load()
    for y in range(image.size[1]):
        intervals.append([])
        for x in range(image.size[0]):
            level = lightness(image_data[x, y])
            if level < lower_threshold or level > upper_threshold:
                intervals[y].append(x)
    return intervals
Beispiel #4
0
def edge(image, lower_threshold, **kwargs):
    edge_data = image.filter(ImageFilter.FIND_EDGES).convert('RGBA').load()
    intervals = []

    for y in range(image.size[1]):
        intervals.append([])
        flag = True
        for x in range(image.size[0]):
            if lightness(edge_data[x, y]) < lower_threshold:
                flag = True
            elif flag:
                intervals[y].append(x)
                flag = False
    return intervals
Beispiel #5
0
def file_edges(pixels, image, angle):
    img = Image.open(image)
    img = img.rotate(angle, expand=True)
    img = img.resize((len(pixels[0]), len(pixels)), Image.ANTIALIAS)
    edges = img.filter(ImageFilter.FIND_EDGES)
    edges = edges.convert('RGBA')
    edge_data = edges.load()

    filter_pixels = []
    edge_pixels = []
    intervals = []

    
    for y in range(img.size[1]):
        filter_pixels.append([])
        for x in range(img.size[0]):
            filter_pixels[y].append(edge_data[x, y])

    
    for y in range(len(pixels)):
        edge_pixels.append([])
        for x in range(len(pixels[0])):
            if util.lightness(filter_pixels[y][x]) < 0.25:
                edge_pixels[y].append(constants.white_pixel)
            else:
                edge_pixels[y].append(constants.black_pixel)

    
    for y in range(len(pixels) - 1, 1, -1):
        for x in range(len(pixels[0]) - 1, 1, -1):
            if edge_pixels[y][x] == constants.black_pixel and edge_pixels[y][x - 1] == constants.black_pixel:
                edge_pixels[y][x] = constants.white_pixel

    
    for y in range(len(pixels)):
        intervals.append([])
        for x in range(len(pixels[0])):
            if edge_pixels[y][x] == constants.black_pixel:
                intervals[y].append(x)
        intervals[y].append(len(pixels[0]))
    return intervals
Beispiel #6
0
def file_edges(pixels, image, angle):
    img = Image.open(image)
    img = img.rotate(angle, expand=True)
    img = img.resize((len(pixels[0]), len(pixels)), Image.ANTIALIAS)
    edges = img.filter(ImageFilter.FIND_EDGES)
    edges = edges.convert('RGBA')
    edge_data = edges.load()

    filter_pixels = []
    edge_pixels = []
    intervals = []

    for y in range(img.size[1]):
        filter_pixels.append([])
        for x in range(img.size[0]):
            filter_pixels[y].append(edge_data[x, y])

    for y in range(len(pixels)):
        edge_pixels.append([])
        for x in range(len(pixels[0])):
            if util.lightness(filter_pixels[y][x]) < 0.25:
                edge_pixels[y].append(constants.white_pixel)
            else:
                edge_pixels[y].append(constants.black_pixel)

    for y in range(len(pixels) - 1, 1, -1):
        for x in range(len(pixels[0]) - 1, 1, -1):
            if edge_pixels[y][x] == constants.black_pixel and edge_pixels[y][
                    x - 1] == constants.black_pixel:
                edge_pixels[y][x] = constants.white_pixel

    for y in range(len(pixels)):
        intervals.append([])
        for x in range(len(pixels[0])):
            if edge_pixels[y][x] == constants.black_pixel:
                intervals[y].append(x)
        intervals[y].append(len(pixels[0]))
    return intervals
Beispiel #7
0
def lightness(pixel):
    return util.lightness(pixel)