| | import arc_json_model as ajm |
| | import numpy as np |
| | from simple_image import image_new, set_pixel, draw_rect, draw_box |
| |
|
| | |
| | IMAGE_SIZE = 32 |
| |
|
| | |
| |
|
| | |
| | COLOR_OUTSIDE = 10 |
| |
|
| | |
| | COLOR_PADDING = 11 |
| |
|
| | |
| | |
| | COLOR_HIGHLIGHT = 12 |
| |
|
| | class ExportTaskToImage: |
| | def __init__(self, task: ajm.Task): |
| | self.task = task |
| | self.pixels = ExportTaskToImage.image_from_task(task) |
| |
|
| | @classmethod |
| | def image_from_task(cls, task: ajm.Task) -> np.ndarray: |
| | |
| | |
| | image_width = IMAGE_SIZE * len(task.pairs) |
| |
|
| | |
| | |
| | |
| | image_height = IMAGE_SIZE * 2 |
| | |
| | pixels = image_new(image_width, image_height, COLOR_OUTSIDE) |
| |
|
| | |
| | for pair_index, pair in enumerate(task.pairs): |
| | for row_index, rows in enumerate(pair.input.pixels): |
| | for column_index, pixel in enumerate(rows): |
| | x = IMAGE_SIZE * pair_index + 1 + column_index |
| | y = IMAGE_SIZE * 0 + 1 + row_index |
| | set_pixel(pixels, x, y, pixel) |
| |
|
| | |
| | for pair_index, pair in enumerate(task.pairs): |
| | for row_index, rows in enumerate(pair.output.pixels): |
| | for column_index, pixel in enumerate(rows): |
| | x = IMAGE_SIZE * pair_index + 1 + column_index |
| | y = IMAGE_SIZE * 1 + 1 + row_index |
| | set_pixel(pixels, x, y, pixel) |
| |
|
| | |
| | for pair_index, pair in enumerate(task.pairs): |
| | x = IMAGE_SIZE * pair_index |
| | draw_box(pixels, x, 0, IMAGE_SIZE, IMAGE_SIZE, COLOR_PADDING) |
| | draw_box(pixels, x, IMAGE_SIZE, IMAGE_SIZE, IMAGE_SIZE, COLOR_PADDING) |
| |
|
| | |
| | |
| | for pair_index, pair in enumerate(task.pairs): |
| | if pair.pair_type != ajm.PairType.TEST: |
| | continue |
| | x = IMAGE_SIZE * pair_index |
| | width = pair.output.pixels.shape[1] |
| | height = pair.output.pixels.shape[0] |
| | draw_rect(pixels, x, IMAGE_SIZE, width + 2, height + 2, COLOR_OUTSIDE) |
| | draw_box(pixels, x, IMAGE_SIZE, width + 2, height + 2, COLOR_HIGHLIGHT) |
| | return pixels |
| |
|
| | def image_with_mark(self, test_index: int, x: int, y: int) -> np.ndarray: |
| | pixels = self.pixels.copy() |
| | for pair_index, pair in enumerate(self.task.pairs): |
| | if pair.pair_type != ajm.PairType.TEST: |
| | continue |
| | if pair.pair_index != test_index: |
| | continue |
| | set_x = IMAGE_SIZE * pair_index + 1 + x |
| | set_y = IMAGE_SIZE + 1 + y |
| | set_pixel(pixels, set_x, set_y, COLOR_HIGHLIGHT) |
| | return pixels |
| |
|
| | if __name__ == '__main__': |
| | filename = 'testdata/af902bf9.json' |
| | task = ajm.Task.load(filename) |
| | |
| | exporter = ExportTaskToImage(task) |
| | |
| | pixels = exporter.image_with_mark(0, 3, 3) |
| | print("pixels.shape", pixels.shape) |
| | |
| |
|