@@ -285,6 +285,41 @@ def _decode_symbols(ct, img):
285
285
yield i , best_bits , best_cell
286
286
287
287
288
+ def _calc_ccm (ct , color_lookups , cc_setting ):
289
+ splits = 2 if cc_setting in (6 , 7 ) else 0
290
+ if cc_setting in (3 , 4 , 5 ):
291
+ possible = possible_colors (ct .dark , BITS_PER_COLOR )
292
+ #if len(color_lookups[0]) < len(possible):
293
+ # return
294
+ exp = [color for i ,color in enumerate (possible ) if i in color_lookups [0 ]]
295
+ exp = numpy .array (exp )
296
+ observed = numpy .array ([v for k ,v in sorted (color_lookups [0 ].items ())])
297
+ from colour .characterisation .correction import matrix_colour_correction_Cheung2004
298
+ der = matrix_colour_correction_Cheung2004 (observed , exp )
299
+
300
+ # not sure which of this would be better...
301
+ if ct .ccm is None or cc_setting == 4 :
302
+ ct .ccm = der
303
+ else : # cc_setting == 3,5
304
+ ct .ccm = der .dot (ct .ccm )
305
+
306
+ if splits :
307
+ from colour .characterisation .correction import matrix_colour_correction_Cheung2004
308
+ exp = numpy .array (possible_colors (ct .dark , BITS_PER_COLOR ))
309
+ ccms = list ()
310
+ i = 0
311
+ while i < splits :
312
+ observed = numpy .array ([v for k ,v in sorted (color_lookups [i ].items ())])
313
+ der = matrix_colour_correction_Cheung2004 (observed , exp )
314
+ ccms .append (der )
315
+ i += 1
316
+
317
+ if ct .ccm is None or cc_setting == 7 :
318
+ ct .ccm = ccms
319
+ else :
320
+ ct .ccm = [der .dot (ct .ccm ) for der in ccms ]
321
+
322
+
288
323
def _decode_iter (ct , img , color_img , state_info = {}):
289
324
decoding = sorted (_decode_symbols (ct , img ))
290
325
if use_split_mode ():
@@ -306,39 +341,7 @@ def _decode_iter(ct, img, color_img, state_info={}):
306
341
#matrix_colour_correction_Cheung2004
307
342
#matrix_colour_correction_Finlayson2015
308
343
309
- if cc_setting in (3 , 4 , 5 ):
310
- exp = numpy .array (possible_colors (ct .dark , BITS_PER_COLOR ))
311
- observed = numpy .array ([v for k ,v in sorted (color_lookups [0 ].items ())])
312
- from colour .characterisation .correction import matrix_colour_correction_Cheung2004
313
- der = matrix_colour_correction_Cheung2004 (observed , exp )
314
-
315
- # not sure which of this would be better...
316
- if ct .ccm is None or cc_setting == 4 :
317
- ct .ccm = der
318
- else : # cc_setting == 3,5
319
- ct .ccm = der .dot (ct .ccm )
320
-
321
- if splits :
322
- from colour .characterisation .correction import matrix_colour_correction_Cheung2004
323
- exp = numpy .array (possible_colors (ct .dark , BITS_PER_COLOR ))
324
- ccms = list ()
325
- i = 0
326
- while i < splits :
327
- observed = numpy .array ([v for k ,v in sorted (color_lookups [i ].items ())])
328
- der = matrix_colour_correction_Cheung2004 (observed , exp )
329
- ccms .append (der )
330
- i += 1
331
-
332
- if ct .ccm is None or cc_setting == 7 :
333
- ct .ccm = ccms
334
- else :
335
- ct .ccm = [der .dot (ct .ccm ) for der in ccms ]
336
-
337
- if cc_setting == 5 :
338
- ct .colors = color_lookups [0 ]
339
- if cc_setting == 10 :
340
- ct .disable_color_scaling = True
341
- ct .colors = color_lookups [0 ]
344
+ _calc_ccm (ct , color_lookups , cc_setting )
342
345
343
346
print ('beginning decode colors pass...' )
344
347
midX = conf .TOTAL_SIZE // 2
0 commit comments