Skip to content

Instantly share code, notes, and snippets.

@agness
Created July 7, 2023 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agness/d85cf2655567c0c331ff90c573dcbdf2 to your computer and use it in GitHub Desktop.
Save agness/d85cf2655567c0c331ff90c573dcbdf2 to your computer and use it in GitHub Desktop.
Combines an array of image files into a single bitmap with union (logical OR).
#!/usr/bin/env python3
# Combines an array of image files into one bitmap with union (logical OR).
# Requirements
# pip3 install opencv-python
import cv2
import numpy as np
infiles = [
'colour-7.png',
'colour-8.png',
'colour-9.png'
]
outfile = 'colour-789.png'
o = None
for i in infiles:
im = cv2.imread(i,cv2.IMREAD_GRAYSCALE) # load image
p = np.array(im) >= 255 # binarize
print(f'Opening file {i}:')
print(p)
if (o is None):
o = p
else:
o = p + o # Logical OR
# Save to outfile.
cv2.imwrite(outfile, o * 255)
print(f'Wrote file {outfile}.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment