Skip to content

Commit 042444a

Browse files
committed
Remove print from chromaticity generation
1 parent f8e3db0 commit 042444a

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

colorization_benchmark/utils/chromaticity.py

+21-22
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ def get_matrix(self) -> np.ndarray:
200200
map(float, et.execute(*['-icc_profile:BlueMatrixColumn', '-b', self.icc_path]).split(' ')))
201201
self._matrix = np.vstack([red_column, green_column, blue_column]).transpose()
202202
self._matrix_missing = False
203-
print(f'using {self._matrix} for RGB to XYZ')
203+
# print(f'using {self._matrix} for RGB to XYZ')
204204
else:
205205
self._matrix = colour.models.rgb.RGB_COLOURSPACE_sRGB.matrix_RGB_to_XYZ
206206
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')
208208
else:
209209
self._matrix = colour.models.rgb.RGB_COLOURSPACE_sRGB.matrix_RGB_to_XYZ
210210
self._matrix_missing = True
@@ -223,13 +223,13 @@ def get_chromatic_adaptation_transformation(self) -> np.ndarray | None:
223223
if cat_string:
224224
cat = list(map(float, cat_string.split(' ')))
225225
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")
227227
else:
228228
self._cat = None
229-
print(f"chromatic adaptation matrix missing, not performing transformation")
229+
# print(f"chromatic adaptation matrix missing, not performing transformation")
230230
else:
231231
self._cat = None
232-
print(f"icc profile missing, not performing transformation")
232+
# print(f"icc profile missing, not performing transformation")
233233
return self._cat
234234

235235
def get_pcs_illuminant(self) -> np.ndarray:
@@ -243,15 +243,15 @@ def get_pcs_illuminant(self) -> np.ndarray:
243243
pcs_illuminant = et.execute(*['-icc_profile:ConnectionSpaceIlluminant', '-b', self.icc_path])
244244
if pcs_illuminant:
245245
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}")
247247
else:
248248
# use D65 when no matrix is defined, otherwise use D50
249249
if self._matrix_missing:
250250
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")
252252
else:
253253
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")
255255
else:
256256
self._pcs_illuminant_XYZ = colour.xyY_to_XYZ(np.array([0.31271, 0.32902, 1]))
257257
return self._pcs_illuminant_XYZ
@@ -267,7 +267,7 @@ def get_conversion_matrix_to_D65(self) -> np.ndarray:
267267
self.get_pcs_illuminant(), # use PCS white point
268268
colour.xyY_to_XYZ(np.array([0.31271, 0.32902, 1])), # D65 in 2-degree observer
269269
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')
271271
return self._pcs_illuminant_conversion_matrix
272272

273273
def get_profile_description(self) -> str:
@@ -312,7 +312,7 @@ def convert_trc(self, pixels: np.ndarray) -> np.ndarray:
312312
"""
313313
n = len(self.matrix)
314314
# 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')
316316
if np.min(pixels) < 0 or np.max(pixels) > 1:
317317
raise ValueError(f'pixels should be in range [0, 1], got {np.min(pixels)} and {np.max(pixels)}')
318318
result_array = np.interp(pixels, np.linspace(0, 1, n), self.matrix)
@@ -329,7 +329,7 @@ def __init__(self, gamma: float = 2.2):
329329
self.gamma = gamma
330330

331331
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')
333333
if self.gamma != 1:
334334
return pixels ** self.gamma
335335
else:
@@ -354,7 +354,7 @@ def convert_trc(self, pixels: np.ndarray) -> np.ndarray:
354354
> Any function value outside the range shall be clipped to the range of the function.
355355
Therefore, we do the clipping before returning.
356356
"""
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')
358358
if self.curve_type == 0:
359359
return GammaConversion(gamma=self.params[0].astype(float)).convert_trc(pixels)
360360
elif self.curve_type == 1:
@@ -406,7 +406,7 @@ def plot_xy_coordinates_with_color(xy_array, output_path: Path | str):
406406
# plot
407407
plt.style.use('dark_background')
408408
fig, ax = plt.subplots(figsize=(8, 9))
409-
ax.set_title('CIE 1931 Chromaticity Diagram')
409+
# ax.set_title('CIE 1931 Chromaticity Diagram')
410410
# draw horseshoe
411411
horseshoe_patch = PathPatch(horseshoe_path, facecolor='none', edgecolor='#DDDDDD', linewidth=0.5)
412412
ax.add_patch(horseshoe_patch)
@@ -415,8 +415,8 @@ def plot_xy_coordinates_with_color(xy_array, output_path: Path | str):
415415
# setup axes
416416
ax.set_xlim(0, 0.8)
417417
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))
420420
# draw white point and annotation
421421
ax.scatter(0.3127, 0.3290, color='#DDDDDD', s=5, edgecolors=None, linewidths=0)
422422
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):
425425
ax.scatter(0.3457, 0.3585, color=(0, 0, 0, 0), s=20, edgecolors='#DDDDDD', linewidths=0.5)
426426
ax.text(0.353, 0.365, 'D50', color='#DDDDDD', fontsize=6, ha='center', va='center')
427427

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')
429429
plt.close()
430430
# print('Drawing Chromaticity Diagram spent: {:.2f} seconds'.format(time.time() - start_time))
431431

@@ -437,19 +437,18 @@ def image_to_cie_xy(image_path) -> np.ndarray:
437437
img = iio.imread(image_path)
438438
except FileNotFoundError:
439439
print("file not found!")
440-
exit(1)
441440
# extract image color space using exiftool
442441
image_data = np.array(img, dtype=np.float32)
443442
# if image is integer, normalize it to floating [0, 1]
444443
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]")
446445
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")
449448

450449
# if image is RGBA, convert it to RGB by removing alpha channel
451450
if image_data.shape[2] == 4:
452-
print("original image is RGBA, removing alpha channel")
451+
# print("original image is RGBA, removing alpha channel")
453452
image_data = image_data[:, :, :3]
454453
# reshape image data to 2D array
455454
pixels = image_data.reshape(-1, 3)
@@ -468,7 +467,7 @@ def image_to_cie_xy(image_path) -> np.ndarray:
468467
# if cat_matrix is not None:
469468
# pixels_xyz = np.dot(pixels_xyz, np.linalg.inv(cat_matrix).transpose())
470469
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))
472471

473472
return xy_array
474473

0 commit comments

Comments
 (0)