Python matplotlib.cm.colors() Examples

The following are 5 code examples for showing how to use matplotlib.cm.colors(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may want to check out the right sidebar which shows the related API usage.

You may also want to check out all available functions/classes of the module matplotlib.cm , or try the search function .

Example 1
Project: tf-monodepth2   Author: FangGet   File: tools.py    License: MIT License 6 votes vote down vote up
def colorize(value, vmin=None, vmax=None, cmap=None):
    # normalize
    vmin = tf.reduce_min(value) if vmin is None else vmin
    vmax = tf.reduce_max(value) if vmax is None else vmax
    value = (value - vmin) / (vmax - vmin)  # vmin..vmax

    # squeeze last dim if it exists
    value = tf.squeeze(value)

    # quantize
    indices = tf.to_int32(tf.round(value * 255))

    # gather
    cm = matplotlib.cm.get_cmap(cmap if cmap is not None else 'gray')
    colors = tf.constant(cm.colors, dtype=tf.float32)
    value = tf.gather(colors, indices)

    return value 
Example 2
Project: bayesian-yolov3   Author: flkraus   File: vis_uncertainty.py    License: MIT License 6 votes vote down vote up
def colorize(img, vmin=None, vmax=None, cmap='plasma'):
    # normalize
    vmin = tf.reduce_min(img) if vmin is None else vmin
    vmax = tf.contrib.distributions.percentile(img, 99.) if vmax is None else vmax
    img = (img - vmin) / (vmax - vmin)

    img = tf.squeeze(img, axis=[-1])

    # quantize
    indices = tf.clip_by_value(tf.to_int32(tf.round(img * 255)), 0, 255)

    # gather
    cm = matplotlib.cm.get_cmap(cmap if cmap is not None else 'gray')
    colors = tf.constant(cm.colors, dtype=tf.float32)
    img = tf.gather(colors, indices)

    return img 
Example 3
Project: FL3D   Author: pyun-ram   File: colorize.py    License: GNU General Public License v3.0 4 votes vote down vote up
def tf_colorize(value, factor=1, vmin=None, vmax=None, cmap=None):
    """
    A utility function for TensorFlow that maps a grayscale image to a matplotlib
    colormap for use with TensorBoard image summaries.

    By default it will normalize the input value to the range 0..1 before mapping
    to a grayscale colormap.

    Arguments:
      - value: 2D Tensor of shape [height, width] or 3D Tensor of shape
        [height, width, 1].
      - factor: resize factor, scalar
      - vmin: the minimum value of the range used for normalization.
        (Default: value minimum)
      - vmax: the maximum value of the range used for normalization.
        (Default: value maximum)
      - cmap: a valid cmap named for use with matplotlib's `get_cmap`.
        (Default: 'gray')

    Example usage:

    ```
    output = tf.random_uniform(shape=[256, 256, 1])
    output_color = colorize(output, vmin=0.0, vmax=1.0, cmap='viridis')
    tf.summary.image('output', output_color)
    ```

    Returns a 3D tensor of shape [height, width, 3].
    """

    # normalize
    vmin = tf.reduce_min(value) if vmin is None else vmin
    vmax = tf.reduce_max(value) if vmax is None else vmax
    value = (value - vmin) / (vmax - vmin)  # vmin..vmax

    # squeeze last dim if it exists
    value = tf.squeeze(value)

    # quantize
    indices = tf.to_int32(tf.round(value * 255))

    # gather
    cm = matplotlib.cm.get_cmap(cmap if cmap is not None else 'gray')
    colors = tf.constant(cm.colors, dtype=tf.float32)
    value = tf.gather(colors, indices)

    return value 
Example 4
Project: deep_lip_reading   Author: afourast   File: tb_util.py    License: Apache License 2.0 4 votes vote down vote up
def colorize_image(value, vmin=None, vmax=None, cmap='viridis'):
  """
  A utility function for TensorFlow that maps a grayscale image to a matplotlib
  colormap for use with TensorBoard image summaries.

  By default it will normalize the input value to the range 0..1 before mapping
  to a grayscale colormap.

  Arguments:
    - value: 2D Tensor of shape [height, width] or 3D Tensor of shape
      [height, width, 1].
    - vmin: the minimum value of the range used for normalization.
      (Default: value minimum)
    - vmax: the maximum value of the range used for normalization.
      (Default: value maximum)
    - cmap: a valid cmap named for use with matplotlib's `get_cmap`.
      (Default: 'gray')

  Example usage:

  ```
  output = tf.random_uniform(shape=[256, 256, 1])
  output_color = colorize(output, vmin=0.0, vmax=1.0, cmap='viridis')
  tf.summary.image('output', output_color)
  ```

  Returns a 3D tensor of shape [height, width, 3].
  """

  # normalize
  vmin = tf.reduce_min(value) if vmin is None else vmin
  vmax = tf.reduce_max(value) if vmax is None else vmax
  value = (value - vmin) / (vmax - vmin) # vmin..vmax

  # squeeze last dim if it exists
  value = tf.squeeze(value)

  # quantize
  indices = tf.to_int32(tf.round(value * 255))

  # gather
  import matplotlib.cm
  cm = matplotlib.cm.get_cmap(cmap if cmap is not None else 'gray')
  colors = tf.constant(cm.colors, dtype=tf.float32)
  value = tf.gather(colors, indices)

  return value 
Example 5
Project: VoxelNet-tensorflow   Author: tsinghua-rll   File: colorize.py    License: MIT License 4 votes vote down vote up
def tf_colorize(value, factor=1, vmin=None, vmax=None, cmap=None):
    """
    A utility function for TensorFlow that maps a grayscale image to a matplotlib
    colormap for use with TensorBoard image summaries.

    By default it will normalize the input value to the range 0..1 before mapping
    to a grayscale colormap.

    Arguments:
      - value: 2D Tensor of shape [height, width] or 3D Tensor of shape
        [height, width, 1].
      - factor: resize factor, scalar
      - vmin: the minimum value of the range used for normalization.
        (Default: value minimum)
      - vmax: the maximum value of the range used for normalization.
        (Default: value maximum)
      - cmap: a valid cmap named for use with matplotlib's `get_cmap`.
        (Default: 'gray')

    Example usage:

    ```
    output = tf.random_uniform(shape=[256, 256, 1])
    output_color = colorize(output, vmin=0.0, vmax=1.0, cmap='viridis')
    tf.summary.image('output', output_color)
    ```

    Returns a 3D tensor of shape [height, width, 3].
    """

    # normalize
    vmin = tf.reduce_min(value) if vmin is None else vmin
    vmax = tf.reduce_max(value) if vmax is None else vmax
    value = (value - vmin) / (vmax - vmin)  # vmin..vmax

    # squeeze last dim if it exists
    value = tf.squeeze(value)

    # quantize
    indices = tf.to_int32(tf.round(value * 255))

    # gather
    cm = matplotlib.cm.get_cmap(cmap if cmap is not None else 'gray')
    colors = tf.constant(cm.colors, dtype=tf.float32)
    value = tf.gather(colors, indices)

    return value