26 lines
1.1 KiB
Python
26 lines
1.1 KiB
Python
import numpy as np
|
|
from PIL import Image
|
|
|
|
ref = Image.open(r'C:\PF\flash-logo-block-dark.png').convert('RGB')
|
|
out = Image.open(r'C:\PF\flash-logo-block-dark-4x.png').convert('RGB')
|
|
|
|
ref_g = np.asarray(ref.convert('L')) > 60
|
|
small = out.resize(ref.size, Image.BOX)
|
|
out_g = np.asarray(small.convert('L')) > 100
|
|
|
|
lost = ref_g & ~out_g # ink in original that disappeared
|
|
extra = out_g & ~ref_g # ink that appeared where the original had none
|
|
|
|
vis = np.zeros(ref_g.shape + (3,), dtype=np.uint8)
|
|
vis[ref_g] = (90, 90, 90) # kept/still ink -> grey
|
|
vis[extra] = (0, 255, 60) # new ink -> green
|
|
vis[lost] = (255, 40, 40) # lost ink -> red
|
|
img = Image.fromarray(vis)
|
|
img.save(r'C:\PF\tools\diff_full.png')
|
|
img.resize((1600, round(ref.size[1] * 1600 / ref.size[0])), Image.LANCZOS).save(r'C:\PF\tools\diff_small.png')
|
|
|
|
# text zoom, 2x for inspection
|
|
img.crop((80, 120, 700, 310)).resize((1240, 380), Image.NEAREST).save(r'C:\PF\tools\diff_text.png')
|
|
img.crop((0, 60, 200, 340)).resize((400, 560), Image.NEAREST).save(r'C:\PF\tools\diff_cap.png')
|
|
print('lost px', int(lost.sum()), 'extra px', int(extra.sum()), 'ink', int(ref_g.sum()))
|