Skip to content

Instantly share code, notes, and snippets.

@charles-l
Created April 26, 2020 00:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charles-l/648446476df66db88f6f864e47793666 to your computer and use it in GitHub Desktop.
Save charles-l/648446476df66db88f6f864e47793666 to your computer and use it in GitHub Desktop.
hexahue decoder
# decodes hexahue images
import cv2
import numpy as np
codewords = {'mrgybc': 'a',
'rmgybc': 'b',
'rgmybc': 'c',
'rgymbc': 'd',
'rgybmc': 'e',
'rgybcm': 'f',
'grybcm': 'g',
'gyrbcm': 'h',
'gybrcm': 'i',
'gybcrm': 'j',
'gybcmr': 'k',
'ygbcmr': 'l',
'ybgcmr': 'm',
'ybcgmr': 'n',
'ybcmgr': 'o',
'ybcmrg': 'p',
'bycmrg': 'q',
'bcymrg': 'r',
'bcmyrg': 's',
'bcmryg': 't',
'bcmrgy': 'u',
'cbmrgy': 'v',
'cmbrgy': 'w',
'cmrbgy': 'x',
'cmrgby': 'y',
'cmrgyb': 'z',
'lwwllw': '.',
'wllwwl': ',',
'wwwwww': ' ',
'lawlaw': '0',
'alwlaw': '1',
'awllaw': '2',
'awlalw': '3',
'awlawl': '4',
'walawl': '5',
'wlaawl': '6',
'wlawal': '7',
'wlawla': '8',
'lwawla': '9',
}
img = cv2.imread('output.png')
crop = img[2:-2, 2:-2]
# BGR
colors = {(0, 0, 255): 'r',
(0, 255, 0): 'g',
(255, 0, 0): 'b',
(0, 255, 255): 'y',
(255, 0, 255): 'm',
(255, 255, 0): 'c',
(255, 255, 255): 'w',
(0, 0, 0): 'l',
(128, 128, 128): 'a'}
s = ''
for j in range(crop.shape[0] // 3):
for i in range(crop.shape[1] // 2):
s += codewords[''.join((colors[tuple(x)] for x in crop[j*3:j*3+3, i*2:i*2+2].reshape((-1, 3))))]
print(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment