diff --git a/constants.py b/constants.py index c5980af..9c9706a 100644 --- a/constants.py +++ b/constants.py @@ -17,4 +17,4 @@ # list of color spaces that colorspacious can correctly perform a deltaE calculation in CSPACE_LIST = ['CAM02-UCS', 'CAM02-LCD', 'CAM02-SCD', - 'CIELab', 'sRGB1', 'sRGB1-linear', 'XYZ1', 'CIELCh'] \ No newline at end of file + 'CIELab', 'sRGB1', 'sRGB1-linear', 'XYZ1'] \ No newline at end of file diff --git a/palettizer.py b/palettizer.py index 5acb08b..7843381 100644 --- a/palettizer.py +++ b/palettizer.py @@ -11,7 +11,6 @@ import sg_extensions - def index2rgb(arr, pal): channels = [pal[arr, i] for i in range(3)] return np.stack(channels, axis=-1) @@ -26,27 +25,14 @@ def counter(iterable, message='', id='single', end=None): break -def arc_dist(arr1, arr2): - return np.radians(np.abs(180 - ((180 + arr2[..., 2] - arr1[..., 2]) % 360))) * ((arr2[..., 1] + arr1[..., 1]) / 2) - - -# special distance function for cylindrical coordinates -def cylinder_deltaE(color1, color2, input_space="sRGB1", uniform_space="CIELCh"): - uniform1 = cspace_convert(color1, input_space, uniform_space) - uniform2 = cspace_convert(color2, input_space, uniform_space) - return np.sqrt(np.sum((uniform1[..., :2] - uniform2[..., :2]) ** 2, axis=-1)) + arc_dist(uniform1, uniform2) - - def split_deltaE(image, color2, input_space="sRGB1", uniform_space="CAM02-UCS"): split_val = 25000 * np.ceil(virtual_memory()[1] / 1024**3) splits = math.ceil((len(color2)**0.5555) * image.shape[0] * image.shape[1] / split_val) # splits = math.ceil((sys.getsizeof(image) * sys.getsizeof(color2)) / virtual_memory()[1]) image_sliced = np.array_split(image, splits) pool = multi.Pool(processes=min([multi.cpu_count(), splits, ])) - if uniform_space == 'CIELCh': - image_output_sliced = pool.imap(lambda x: cylinder_deltaE(x, color2, input_space, uniform_space), image_sliced) - else: - image_output_sliced = pool.imap(lambda x: deltaE(x, color2, input_space, uniform_space), image_sliced) + + image_output_sliced = pool.imap(lambda x: deltaE(x, color2, input_space, uniform_space), image_sliced) image_output_sliced = [a for a in counter(image_output_sliced, 'Quantizing...', end=splits)] pool.close()