Exemplo n.º 1
0
def add(rgb, severity, jab_set, cvd_type='deuteranomaly'):
    
    if severity is None: # Full trichromatic vision
        jab = cmu.convert(rgb, 'sRGB1', UNIFORM_SPACE)
    
    else: # Simulate CVD
        jab = cmu.convert(cvu.get_cvd(rgb, severity=severity, cvd_type=cvd_type), 'sRGB1', UNIFORM_SPACE)
    
    # Add to set
    jab_set.add(tuple(jab))
Exemplo n.º 2
0
def get_cvd(data, cvd_type=CVD_TYPE, severity=100):
    '''
    Converts RGB values to CVD space RGB values.

    Parameters
    ----------
    data: string or 3 x 256 array
        Colormap name OR array with complete color data. Invalid
        colormap names throw a ValueError. Refer to _check_cmap for
        more information.
    cvd_type: string
        Type of CVD to be simulated. Options: deuteranomaly or
        protanomaly. Default: deuteranomaly.
    severity: int
        Severity of CVD to be simulated. Can be any integer between 0
        and 100. Default: 100
    Returns
    ----------
    cvd: 3 x 256 array
        Colormap data in CVD space
    '''

    rgb, _ = cmu.get_rgb_jab(data, calc_jab=False)
    cvd_space = {
        'name': 'sRGB1+CVD',
        'cvd_type': cvd_type,
        'severity': severity
    }
    cvd = cmu.convert(rgb, cvd_space, CSPACE1)
    return cvd
Exemplo n.º 3
0
def _iter_make_linear(jab):

    # Linearize a' and b' changes
    jab1 = cmu.make_linear(np.copy(jab))

    # Convert J'a'b' values to RGB values and clip
    rgb1 = np.clip(cmu.convert(jab1, CSPACE2, CSPACE1), 0, 1)

    # Convert RGB to CVD RGB space
    rgb2 = get_cvd(rgb1)

    # Bring back to to J'a'b'
    jab2 = cmu.convert(rgb2, CSPACE1, CSPACE2)

    # Force to have same J' as original J'a'b' array
    jab2[0, :] = jab1[0, :]

    return jab2
Exemplo n.º 4
0
def iter_make_linear(jab, l=100000):
    '''
    Takes J'a'b' array and performs the following two times: linearizes
    the change of a' and b' then converts to CVD space and back (to
    ensure colormap is still CVD compatible).

    Parameters
    ----------
    data: 3 x 256 array
        J'a'b' values for colormap
    Returns
    ----------
    rgb: 3 x 256 array
        RGB data
    jab: 3 x 256 array
        J'a'b' data
    '''

    jab = np.copy(jab)
    jab = _iter_make_linear(_iter_make_linear(jab))
    rgb = cmu.convert(jab, CSPACE2, CSPACE1)
    return rgb, jab
Exemplo n.º 5
0
FAX = 16

#%% Get iteration data
cmap = 'viridis'  # The optimized version of this colormap is cividis!

# Get original RGB/Jab
t = time()
rgb1, jab1 = cmu.get_rgb_jab(cmap)

# Get CVD RGB/Jab
rgb2, jab2 = cmu.get_rgb_jab(cvu.get_cvd(rgb1, severity=100))

# Make perceptual deltas (for a' vs. b') straight
# Need to set a and b before straightening J
jab3 = cmu.make_linear(jab2)
rgb3 = cmu.convert(jab3, cmu.CSPACE2, cmu.CSPACE1)

# Linearize J'
jab4, jab5 = cmu.correct_J(
    jab3)  # This will create a figure showing the J bounds
if jab4 is not None:
    rgb4 = cmu.convert(jab4, cmu.CSPACE2, cmu.CSPACE1)
    rgb4 = np.clip(rgb4, 0, 1)
if jab5 is not None:
    rgb5 = cmu.convert(jab5, cmu.CSPACE2, cmu.CSPACE1)
    rgb5 = np.clip(rgb5, 0, 1)

#%% Figure: Iterations for optimization

fig = plt.figure(figsize=(25, 12), dpi=500)
Exemplo n.º 6
0
# Globals
FLABEL = 20
FAX = 16

# Input colormap name
cmap = 'viridis'

# Optimize
rgb1, jab1 = cmu.get_rgb_jab(cmap)  # Original colormap
rgb2, jab2 = cmu.get_rgb_jab(cvu.get_cvd(rgb1))  # CVD colormap
jab3 = cmu.make_linear(jab2)  # Uniformize hue (a' vs. b')
_, jab4 = cmu.correct_J(jab3)  # Linearize J'

# Convert back to sRGB
rgb4 = cmu.convert(jab4, cmu.CSPACE2, cmu.CSPACE1)
rgb4 = np.clip(rgb4, 0, 1)

# Resimulate CVD in case corrections took the map outside CVD-safe space
rgb4 = cvu.get_cvd(rgb4)

#%% Creat CDPS plots (shown in Fig 1 and 5 of the paper)

# Import test data
img_name = 'example_nanosims_image.txt'  # Image used for paper
img = np.loadtxt(img_name)[45:, :-45]  # Make square
high = 3
low = -1  # Std. Dev bounds for normalizing
img = cmu.bound(cmu.normalize(img), high, low)  # Normalize
slice_img = np.array(img[265, 50:-50], ndmin=2)  # Slice used in paper
gslope = 27.4798474  # Slope for gray. Used to normalize CDPS slopes.