from PIL import Image
import os
def RGB_compare(base_layer_path, min_size_path, max_size_path, save_path):
min_size = Image.open(min_size_path)
min_size = min_size.convert('RGBA')
max_size = Image.open(max_size_path)
max_size = max_size.convert('RGBA')
base_layer = Image.open(base_layer_path)
base_layer = base_layer.convert('RGBA')
both = 0
max_min = 0
min_max = 0
heigh, width = min_size.size
for i in range(heigh):
for j in range(width):
min_r, min_g, min_b, min_a = min_size.getpixel((i, j))
max_r, max_g, max_b, max_a = max_size.getpixel((i, j))
if max_r == 128:
if min_r == 128:
both += 1
min_size.putpixel((i, j), (255, 0, 0, 255))
if min_r == 0:
max_min += 1
min_size.putpixel((i, j), (255, 255, 255, 255))
elif max_r == 0:
if min_r == 0:
min_size.putpixel((i, j), (0, 0, 0, 0))
if min_r == 128:
min_max += 1
min_size.putpixel((i, j), (0, 255, 0, 255))
print('both:{},max_min:{},min_max:{}'.format(both, max_min, min_max))
base_layer.paste(min_size, (0, 0), min_size)
base_layer.save(save_path + "/" + "1024_1280.png")
if __name__ == "__main__":
base_layer_path = r''
min_size_path = r''
max_size_path = r''
save_path = r''
RGB_compare(base_layer_path, min_size_path, max_size_path, save_path)
|