Skip to content

Commit

Permalink
Remove experimental LCh support from master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
PureAsbestos committed Dec 15, 2020
1 parent 8e99ea3 commit aa0f63b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
2 changes: 1 addition & 1 deletion constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
'CIELab', 'sRGB1', 'sRGB1-linear', 'XYZ1']
18 changes: 2 additions & 16 deletions palettizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit aa0f63b

Please sign in to comment.