<commit_before>from os import path

from build_problem import build_problem

from PIL import Image, ImageDraw
from cProfile import Profile
from pstats import Stats


if __name__ == '__main__':
    model_image = Image.open(path.join(path.dirname(__file__), 'rect_model.png'))
    model_image_mask = [p[3] > 0 for p in list(model_image.getdata())]
    model_image_grayscale = model_image.convert('L')

    raw_image = Image.open(path.join(path.dirname(__file__), 'rect_raw.png'))
    raw_image_grayscale = raw_image.convert('L')

    problem = build_problem(model_image_grayscale, raw_image_grayscale,
                            model_image_mask)
    profile = Profile()
    profile.enable()
    solution = problem.solve()
    profile.disable()
    Stats(profile).sort_stats('time').print_stats()
    result = sorted([(v.get_name(), v.get_domain())
                  for v in solution], key=lambda x: x[0][0] * raw_image.size[0] + x[0][1])
    for r in result:
        print 'Model', r[1], 'to', r[0]
<commit_msg>Updated EM RT example: using bigger rectangle and not copying graph<commit_after>from os import path

from build_problem import build_problem

from PIL import Image, ImageDraw
from cProfile import Profile
from pstats import Stats


if __name__ == '__main__':
    model_image = Image.open(path.join(path.dirname(__file__), 'rect_model_10x10.png'))
    model_image_mask = [p[3] > 0 for p in list(model_image.getdata())]
    model_image_grayscale = model_image.convert('L')

    raw_image = Image.open(path.join(path.dirname(__file__), 'rect_big_20x20.png'))
    raw_image_grayscale = raw_image.convert('L')

    problem = build_problem(model_image_grayscale, raw_image_grayscale,
                            model_image_mask)
    profile = Profile()
    profile.enable()
    solution = problem.solve(False)
    profile.disable()
    Stats(profile).sort_stats('time').print_stats()
    result = sorted([(v.get_name(), v.get_domain())
                  for v in solution], key=lambda x: x[0][0] * raw_image.size[0] + x[0][1])
    for r in result:
        print 'Model', r[1], 'to', r[0]

{'fraction_non_alphanumeric': 0.12458233890214797, 'fraction_numerical': 0.012410501193317422, 'mean_word_length': 3.710112359550562, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3747582', 'n_tokens_mistral': 715, 'n_tokens_neox': 681, 'n_words': 156}