Ejemplo n.º 1
0
def get_features(img, regs):
    g = rg.get_regions(img, regs)
    res = np.zeros((len(g), 110))
    for i, r in enumerate(g):
        res[i, :3] = get_mean(r)
        res[i, 3:51] = get_hist(r)

    lg = get_lbp_regions(img, regs)
    for i, r in enumerate(lg):
        res[i, 51:] = get_lbp(r)
    return res
Ejemplo n.º 2
0
def build(*filter):
    makedirs("build/labels/embedded")
    makedirs("build/labels/practice")
    makedirs("build/labels/thumbnails")
    regions = get_regions()
    for label in labels():
        if filter and label.canonical not in filter:
            continue
        try:
            source = Image.open(label.source)
            region = regions[label.canonical]
            width, height = source.size

            # embedded images
            outer_size = outer_width, outer_height = [
                int(float(region.diagonal) * WIDTH),
                int(float(region.width) / region.diagonal * region.height * HEIGHT),
            ]
            if width > outer_width:
                inner_size = [
                    int(outer_width),
                    int(float(outer_width) * height / width),
                ]
                embedded = source.resize(inner_size, Image.ANTIALIAS)
            else:
                embedded = source
            embedded.save(label.embedded)

            practice = embedded.resize([dim / 2 for dim in embedded.size], Image.ANTIALIAS)
            practice.save(label.practice)

            # thumbnail
            thumb_size = [
                int(float(width) / height * 100),
                100,
            ]
            thumb = source.resize(thumb_size, Image.ANTIALIAS)
            thumb = darken(thumb, .5)
            thumb.save(label.thumbnail)

            print label.parts, outer_size, source.size, embedded.size, thumb_size, practice.size
        except Exception, reason:
            print>>sys.stderr, label.parts, reason
Ejemplo n.º 3
0
import Image, ImageDraw
from regions import regions as get_regions
from tiles import WIDTH, HEIGHT, TILE_WIDTH, TILE_HEIGHT
regions = get_regions()
import sys

MAP = Image.open(sys.argv[1])

for name, region in regions.items():
    print name
    ax = int(region['x'] * WIDTH)
    ay = int(region['y'] * HEIGHT)
    width = int(region['width'] * WIDTH)
    height = int(region['height'] * HEIGHT)
    bx = ax + width
    by = ay + height
    if width < TILE_WIDTH:
        d = (TILE_WIDTH - width) / 2
        ax = ax - d
        bx = ax + TILE_WIDTH
        width = TILE_WIDTH
    if height < TILE_HEIGHT:
        d = (TILE_HEIGHT - height) / 2
        ay = ay - d
        by = ay + TILE_HEIGHT
        height = TILE_HEIGHT
    if width < height:
        d = (height - width) / 2
        ax = ax - d
        bx = ax + height
Ejemplo n.º 4
0
def get_lbp_regions(img, regs):
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    imglbp = local_binary_pattern(img, 8, 2,
                                  method='nri_uniform').astype(np.uint32)
    g = rg.get_regions(imglbp, regs, raw=False)
    return g
Ejemplo n.º 5
0
PRECISION = 7

try:
    import json
except ImportError:
    try:
        from django.utils import simplejson as json
    except ImportError:
        import simplejson as json
from regions import regions2 as get_regions

from names import names as get_names

names = get_names()

regions = sorted(get_regions().values(), key=lambda region: -min(region.height, region.width))


def quad(regions, prefix, x, y, width, height, depth=0):
    if depth > DEPTH:
        return
    _width, _height = width / SCALE, height / SCALE
    _region = type("region", (), {"x": x, "y": y, "width": width, "height": height})
    _regions = sorted((region for region in regions if intersect(_region, region)), key=keyator(_region))
    yield prefix, list(r.name for r in _regions[:5])

    for _y in range(2):
        for _x in range(2):
            for r in quad(
                _regions, prefix + "0123"[_y * 2 + _x], x + _x * _width, y + _y * _height, _width, _height, depth + 1
            ):