@@ -200,11 +200,11 @@ def get_matrix(self) -> np.ndarray:
200
200
map (float , et .execute (* ['-icc_profile:BlueMatrixColumn' , '-b' , self .icc_path ]).split (' ' )))
201
201
self ._matrix = np .vstack ([red_column , green_column , blue_column ]).transpose ()
202
202
self ._matrix_missing = False
203
- print (f'using { self ._matrix } for RGB to XYZ' )
203
+ # print(f'using {self._matrix} for RGB to XYZ')
204
204
else :
205
205
self ._matrix = colour .models .rgb .RGB_COLOURSPACE_sRGB .matrix_RGB_to_XYZ
206
206
self ._matrix_missing = True
207
- print (f'profile matrix not found, using sRGB matrix instead' )
207
+ # print(f'profile matrix not found, using sRGB matrix instead')
208
208
else :
209
209
self ._matrix = colour .models .rgb .RGB_COLOURSPACE_sRGB .matrix_RGB_to_XYZ
210
210
self ._matrix_missing = True
@@ -223,13 +223,13 @@ def get_chromatic_adaptation_transformation(self) -> np.ndarray | None:
223
223
if cat_string :
224
224
cat = list (map (float , cat_string .split (' ' )))
225
225
self ._cat = np .vstack ([cat [0 :3 ], cat [3 :6 ], cat [6 :9 ]])
226
- print (f"using { self ._cat } for chromatic adaptation" )
226
+ # print(f"using {self._cat} for chromatic adaptation")
227
227
else :
228
228
self ._cat = None
229
- print (f"chromatic adaptation matrix missing, not performing transformation" )
229
+ # print(f"chromatic adaptation matrix missing, not performing transformation")
230
230
else :
231
231
self ._cat = None
232
- print (f"icc profile missing, not performing transformation" )
232
+ # print(f"icc profile missing, not performing transformation")
233
233
return self ._cat
234
234
235
235
def get_pcs_illuminant (self ) -> np .ndarray :
@@ -243,15 +243,15 @@ def get_pcs_illuminant(self) -> np.ndarray:
243
243
pcs_illuminant = et .execute (* ['-icc_profile:ConnectionSpaceIlluminant' , '-b' , self .icc_path ])
244
244
if pcs_illuminant :
245
245
self ._pcs_illuminant_XYZ = list (map (float , pcs_illuminant .split (' ' )))
246
- print (f"extracted PCS illuminant { self ._pcs_illuminant_XYZ } " )
246
+ # print(f"extracted PCS illuminant {self._pcs_illuminant_XYZ}")
247
247
else :
248
248
# use D65 when no matrix is defined, otherwise use D50
249
249
if self ._matrix_missing :
250
250
self ._pcs_illuminant_XYZ = colour .xyY_to_XYZ (np .array ([0.31271 , 0.32902 , 1 ]))
251
- print (f"using default illuminant D65" )
251
+ # print(f"using default illuminant D65")
252
252
else :
253
253
self ._pcs_illuminant_XYZ = colour .xyY_to_XYZ (np .array ([0.34567 , 0.35850 , 1 ]))
254
- print (f"matrix found but no PCS illuminant is present, using D50" )
254
+ # print(f"matrix found but no PCS illuminant is present, using D50")
255
255
else :
256
256
self ._pcs_illuminant_XYZ = colour .xyY_to_XYZ (np .array ([0.31271 , 0.32902 , 1 ]))
257
257
return self ._pcs_illuminant_XYZ
@@ -267,7 +267,7 @@ def get_conversion_matrix_to_D65(self) -> np.ndarray:
267
267
self .get_pcs_illuminant (), # use PCS white point
268
268
colour .xyY_to_XYZ (np .array ([0.31271 , 0.32902 , 1 ])), # D65 in 2-degree observer
269
269
transform = 'Bradford' )
270
- print (f'using { self ._pcs_illuminant_conversion_matrix } for chromatic adaptation to D65' )
270
+ # print(f'using {self._pcs_illuminant_conversion_matrix} for chromatic adaptation to D65')
271
271
return self ._pcs_illuminant_conversion_matrix
272
272
273
273
def get_profile_description (self ) -> str :
@@ -312,7 +312,7 @@ def convert_trc(self, pixels: np.ndarray) -> np.ndarray:
312
312
"""
313
313
n = len (self .matrix )
314
314
# np.interp does not check for out of range values, so we need to do it manually
315
- print (f'using matrix { self .matrix } for TRC curve conversion' )
315
+ # print(f'using matrix {self.matrix} for TRC curve conversion')
316
316
if np .min (pixels ) < 0 or np .max (pixels ) > 1 :
317
317
raise ValueError (f'pixels should be in range [0, 1], got { np .min (pixels )} and { np .max (pixels )} ' )
318
318
result_array = np .interp (pixels , np .linspace (0 , 1 , n ), self .matrix )
@@ -329,7 +329,7 @@ def __init__(self, gamma: float = 2.2):
329
329
self .gamma = gamma
330
330
331
331
def convert_trc (self , pixels : np .ndarray ) -> np .ndarray :
332
- print (f'using gamma { self .gamma } for TRC conversion' )
332
+ # print(f'using gamma {self.gamma} for TRC conversion')
333
333
if self .gamma != 1 :
334
334
return pixels ** self .gamma
335
335
else :
@@ -354,7 +354,7 @@ def convert_trc(self, pixels: np.ndarray) -> np.ndarray:
354
354
> Any function value outside the range shall be clipped to the range of the function.
355
355
Therefore, we do the clipping before returning.
356
356
"""
357
- print (f'using type { self .curve_type } and params { self .params } for TRC parametric curve conversion' )
357
+ # print(f'using type {self.curve_type} and params {self.params} for TRC parametric curve conversion')
358
358
if self .curve_type == 0 :
359
359
return GammaConversion (gamma = self .params [0 ].astype (float )).convert_trc (pixels )
360
360
elif self .curve_type == 1 :
@@ -406,7 +406,7 @@ def plot_xy_coordinates_with_color(xy_array, output_path: Path | str):
406
406
# plot
407
407
plt .style .use ('dark_background' )
408
408
fig , ax = plt .subplots (figsize = (8 , 9 ))
409
- ax .set_title ('CIE 1931 Chromaticity Diagram' )
409
+ # ax.set_title('CIE 1931 Chromaticity Diagram')
410
410
# draw horseshoe
411
411
horseshoe_patch = PathPatch (horseshoe_path , facecolor = 'none' , edgecolor = '#DDDDDD' , linewidth = 0.5 )
412
412
ax .add_patch (horseshoe_patch )
@@ -415,8 +415,8 @@ def plot_xy_coordinates_with_color(xy_array, output_path: Path | str):
415
415
# setup axes
416
416
ax .set_xlim (0 , 0.8 )
417
417
ax .set_ylim (0 , 0.9 )
418
- ax .xaxis .set_ticks (np .arange (0 , 0.9 , 0.1 ))
419
- ax .yaxis .set_ticks (np .arange (0 , 1.0 , 0.1 ))
418
+ # ax.xaxis.set_ticks(np.arange(0, 0.9, 0.1))
419
+ # ax.yaxis.set_ticks(np.arange(0, 1.0, 0.1))
420
420
# draw white point and annotation
421
421
ax .scatter (0.3127 , 0.3290 , color = '#DDDDDD' , s = 5 , edgecolors = None , linewidths = 0 )
422
422
ax .scatter (0.3127 , 0.3290 , color = (0 , 0 , 0 , 0 ), s = 20 , edgecolors = '#DDDDDD' , linewidths = 0.5 )
@@ -425,7 +425,7 @@ def plot_xy_coordinates_with_color(xy_array, output_path: Path | str):
425
425
ax .scatter (0.3457 , 0.3585 , color = (0 , 0 , 0 , 0 ), s = 20 , edgecolors = '#DDDDDD' , linewidths = 0.5 )
426
426
ax .text (0.353 , 0.365 , 'D50' , color = '#DDDDDD' , fontsize = 6 , ha = 'center' , va = 'center' )
427
427
428
- plt .savefig (output_path , format = output_path .suffix [1 :], dpi = 500 , facecolor = '#000000' )
428
+ plt .savefig (output_path , format = output_path .suffix [1 :], dpi = 75 , facecolor = '#000000' )
429
429
plt .close ()
430
430
# print('Drawing Chromaticity Diagram spent: {:.2f} seconds'.format(time.time() - start_time))
431
431
@@ -437,19 +437,18 @@ def image_to_cie_xy(image_path) -> np.ndarray:
437
437
img = iio .imread (image_path )
438
438
except FileNotFoundError :
439
439
print ("file not found!" )
440
- exit (1 )
441
440
# extract image color space using exiftool
442
441
image_data = np .array (img , dtype = np .float32 )
443
442
# if image is integer, normalize it to floating [0, 1]
444
443
if np .issubdtype (img .dtype , np .integer ):
445
- print (f"original image is { str (img .dtype ):s} , normalizing to float32 [0, 1]" )
444
+ # print(f"original image is {str(img.dtype):s}, normalizing to float32 [0, 1]")
446
445
image_data = image_data / np .iinfo (img .dtype ).max
447
- else :
448
- print (f"original image is { str (img .dtype ):s} , no need to normalize" )
446
+ # else:
447
+ # print(f"original image is {str(img.dtype):s}, no need to normalize")
449
448
450
449
# if image is RGBA, convert it to RGB by removing alpha channel
451
450
if image_data .shape [2 ] == 4 :
452
- print ("original image is RGBA, removing alpha channel" )
451
+ # print("original image is RGBA, removing alpha channel")
453
452
image_data = image_data [:, :, :3 ]
454
453
# reshape image data to 2D array
455
454
pixels = image_data .reshape (- 1 , 3 )
@@ -468,7 +467,7 @@ def image_to_cie_xy(image_path) -> np.ndarray:
468
467
# if cat_matrix is not None:
469
468
# pixels_xyz = np.dot(pixels_xyz, np.linalg.inv(cat_matrix).transpose())
470
469
xy_array = colour .XYZ_to_xy (pixels_xyz )
471
- print ('Computing XYZ and xy spent: {:.2f} seconds' .format (time .time () - start_time ))
470
+ # print('Computing XYZ and xy spent: {:.2f} seconds'.format(time.time() - start_time))
472
471
473
472
return xy_array
474
473
0 commit comments