| from PIL import Image, ImageChops |
| import numpy as np |
|
|
| |
|
|
| def resolve_voxel_consistency(img): |
| is_slim = img.getpixel((47,52))[3] == 0 |
| print('is_slim', is_slim) |
| for part_idx, part in enumerate([ |
| |
| [ |
| [ |
| [(8,8,8),(8,8)], |
| [(8,8,8),(24,8)], |
| [(8,8,8),(16,8)], |
| [(8,8,8),(0,8)], |
| [(8,8,8),(8,0)], |
| [(8,8,8),(16,0)], |
| ],(32,0) |
| ], |
|
|
| |
| [ |
| [ |
| [(8,12,4),(20,20)], |
| [(8,12,4),(20+12,20)], |
| [(4,12,8),(28,20)], |
| [(4,12,8),(16,20)], |
| [(8,4,12),(20,16)], |
| [(8,4,12),(20+8,16)], |
| ],(0,16) |
| ], |
|
|
| |
| [ |
| [ |
| [((3 if is_slim else 4),12,4),(32+4,52)], |
| [((3 if is_slim else 4),12,4),(32+12-(1 if is_slim else 0),52)], |
| [(4,12,4),(32+8-(1 if is_slim else 0),52)], |
| [(4,12,4),(32,52)], |
| [((3 if is_slim else 4),4,12),(32+4,48)], |
| [((3 if is_slim else 4),4,12),(32+8-(1 if is_slim else 0),48)], |
| ],(16,0) |
| ], |
|
|
| |
| [ |
| [ |
| [((3 if is_slim else 4),12,4),(40+4,20)], |
| [((3 if is_slim else 4),12,4),(40+12-(1 if is_slim else 0),20)], |
| [(4,12,4),(40+8-(1 if is_slim else 0),20)], |
| [(4,12,4),(40,20)], |
| [((3 if is_slim else 4),4,12),(40+4,16)], |
| [((3 if is_slim else 4),4,12),(40+8-(1 if is_slim else 0),16)], |
| ],(0,16) |
| ], |
|
|
| |
| [ |
| [ |
| [(4,12,4),(16+4,52)], |
| [(4,12,4),(16+12,52)], |
| [(4,12,4),(16+8,52)], |
| [(4,12,4),(16,52)], |
| [(4,4,12),(16+4,48)], |
| [(4,4,12),(16+8,48)], |
| ],(-16,0) |
| ], |
|
|
| |
| [ |
| [ |
| [(4,12,4),(0+4,20)], |
| [(4,12,4),(0+12,20)], |
| [(4,12,4),(0+8,20)], |
| [(4,12,4),(0,20)], |
| [(4,4,12),(0+4,16)], |
| [(4,4,12),(0+8,16)], |
| ],(0,16) |
| ], |
| ]): |
| decor_offset = part[1] |
| (x,y,z) = part[0][4][0] |
| |
| |
| |
| colors = np.zeros((x, y, z, 4)) |
| priorities = np.full((x, y, z), 99) |
|
|
| |
| |
| inverse = {} |
| for idx,(size, offset) in enumerate(part[0]): |
| for dx in range(size[0]): |
| for dy in range(size[1]): |
| img_x = offset[0]+dx+decor_offset[0] |
| img_y = offset[1]+dy+decor_offset[1] |
| c = img.getpixel((img_x, img_y)) |
| new_x = None |
| new_y = None |
| new_z = None |
| if idx == 4: |
| new_x, new_y, new_z = (dx, y-1-dy, z-1) |
| elif idx == 5: |
| new_x, new_y, new_z = (dx, y-1-dy, 0) |
| elif idx == 0: |
| new_x, new_y, new_z = (dx, 0, z-1-dy) |
| elif idx == 1: |
| new_x, new_y, new_z = (x-1-dx, y-1, z-1-dy) |
| elif idx == 2: |
| new_x, new_y, new_z = (x-1, dx, z-1-dy) |
| elif idx == 3: |
| new_x, new_y, new_z = (0, y-1-dx, z-1-dy) |
| if (new_x,new_y,new_z) not in inverse: |
| inverse[(new_x,new_y,new_z)] = [] |
| inverse[(new_x,new_y,new_z)].append((img_x,img_y)) |
|
|
| if c[3] == 0: |
| continue |
| |
| prio = 99 |
| if idx == 0: prio = 0 |
| elif idx == 1: prio = 1 |
| elif idx == 4: prio = 2 |
| elif idx == 5: prio = 3 |
| elif idx == 2: prio = 4 |
| elif idx == 3: prio = 5 |
|
|
| if priorities[new_x, new_y, new_z] > prio: |
| colors[new_x, new_y, new_z] = c |
| priorities[new_x, new_y, new_z] = prio |
|
|
| for dx in range(size[0]): |
| for dy in range(size[1]): |
| for dz in range(size[2]): |
| if (dx,dy,dz) in inverse: |
| if priorities[dx, dy, dz] == 99: |
| continue |
| for i in inverse[(dx,dy,dz)]: |
| existing_c = img.getpixel(i) |
| if existing_c[3] == 0: |
| img.putpixel(i, tuple(colors[dx,dy,dz].astype(int))) |
| return img |
|
|
| def highlight_diff(img1_path, img2_path, output_path): |
| |
| img1 = Image.open(img1_path).convert('RGBA') |
| img2 = Image.open(img2_path).convert('RGBA') |
|
|
| arr1 = np.array(img1) |
| arr2 = np.array(img2) |
|
|
| |
| height, width, _ = arr1.shape |
| result_arr = np.zeros((height, width, 4), dtype=np.uint8) |
|
|
| |
| |
| |
| |
| diff_mask = np.any(arr1 != arr2, axis=-1) |
|
|
| |
| |
| |
| result_arr[diff_mask] = [255, 0, 0, 255] |
| |
| |
| |
| |
|
|
| |
| result_img = Image.fromarray(result_arr, mode='RGBA') |
|
|
| |
| result_img.save(output_path) |
|
|