Skip to content

Commit

Permalink
A few permutations of things to try...
Browse files Browse the repository at this point in the history
  • Loading branch information
sz3 committed Dec 3, 2023
1 parent 5f4f989 commit d787d48
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
30 changes: 18 additions & 12 deletions cimbar/cimbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,17 +270,22 @@ def _decode_iter(ct, img, color_img, state_info={}):
print('color lookups:')
print(color_lookups)

exp = numpy.array(possible_colors(True, BITS_PER_COLOR))
observed = numpy.array([v for k,v in sorted(color_lookups.items())])
from colour.characterisation.correction import matrix_colour_correction_Cheung2004
der = matrix_colour_correction_Cheung2004(observed, exp)

# not sure which of this would be better...
if ct.ccm is not None:
ct.ccm = der.dot(ct.ccm)
else:
ct.ccm = der
# ct.update_colors()
if state_info['color_correct'] in (3, 4):
exp = numpy.array(possible_colors(ct.dark, BITS_PER_COLOR))
observed = numpy.array([v for k,v in sorted(color_lookups.items())])
from colour.characterisation.correction import matrix_colour_correction_Cheung2004
der = matrix_colour_correction_Cheung2004(observed, exp)

# not sure which of this would be better...
if ct.ccm is not None:
ct.ccm = der.dot(ct.ccm)
else:
ct.ccm = der
if state_info['color_correct'] == 4:
ct.colors = color_lookups
if state_info['color_correct'] == 5:
ct.disable_color_scaling = True
ct.colors = color_lookups

print('beginning decode colors pass...')
for i, bits, cell in decoding:
Expand Down Expand Up @@ -338,7 +343,7 @@ def decode(src_images, outfile, dark=False, ecc=conf.ECC, fountain=False, force_
conf.CELLS_OFFSET, conf.MARKER_SIZE_X, conf.MARKER_SIZE_Y)
interleave_lookup, block_size = interleave_reverse(cells, conf.INTERLEAVE_BLOCKS, conf.INTERLEAVE_PARTITIONS)
dstream, fount = _get_decoder_stream(outfile, ecc, fountain)
if color_correct == 3 and not fount:
if color_correct >= 3 and not fount:
dupe_stream, fount = _get_decoder_stream('/dev/null', ecc, True)
with dstream as outstream:
for imgf in src_images:
Expand Down Expand Up @@ -374,6 +379,7 @@ def decode(src_images, outfile, dark=False, ecc=conf.ECC, fountain=False, force_
iw = second_pass
if fount:
state_info['headers'] = fount.headers
state_info['color_correct'] = color_correct
continue
block = interleave_lookup[i] // block_size
iw.write(bits, block)
Expand Down
3 changes: 3 additions & 0 deletions cimbar/encode/cimb_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def __init__(self, dark, symbol_bits, color_bits=0, color_correct=DEFAULT_COLOR_

self.color_correct = color_correct
self.ccm = ccm
self.disable_color_scaling = False

all_colors = possible_colors(dark, color_bits)
self.colors = {c: all_colors[c] for c in range(2 ** color_bits)}
Expand Down Expand Up @@ -140,6 +141,8 @@ def _scale_adjust(self, c, adjust, down):
return c

def scale_color(self, r, g, b):
if self.disable_color_scaling:
return r, g, b
if self.dark:
max_val = max(r, g, b, 1)
min_val = min(r, g, b, max_val-100)
Expand Down

0 comments on commit d787d48

Please sign in to comment.