Created
July 7, 2023 06:34
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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