dippykit.visualization module

Module of image visualization functions

This module contains an assortment of functions relevant to the plotting and visualization of various image-relevant data

dippykit.visualization.imshow(im: numpy.ndarray, *args, **kwargs) → None[source]

Displays an image

Displays the argument image with optional parameters. If the image has a dtype of uint8, then by default the vmin and vmax parameters will be set to 0 and 255 respectively. This is to provided accurate depictions of otherwise dark images.

This function is essentially a wrapper for matplotlib.pyplot.imshow, so more detailed documentation may be found there.

Parameters:im (numpy.ndarray) – The image to be displayed.
Returns:None

Note

This function wraps around functions from other packages. Reading these functions’ documentations may be useful. See the See also section for more information.

See also

matplotlib.pyplot.imshow
Documentation of the random_noise function from Scikit Image
dippykit.visualization.quiver(*args, **kwargs) → None[source]

Plots a field of arrows

Plots a field of arrow on the current axes. If the following keyword arguments are not set, then they will take on the following default values:

  • ‘units’: ‘xy’
  • ‘angles’: ‘xy’
  • ‘scale_units’: ‘xy’
  • ‘scale’: The mean of the magnitudes of the U and V vectors.

This function is essentially a wrapper for matplotlib.axes.Axes.quiver, so more detailed documentation may be found there.

Returns:None

Note

This function wraps around functions from other packages. Reading these functions’ documentations may be useful. See the See also section for more information.

See also

matplotlib.axes.Axes.quiver
Documentation of the quiver function from Matplotlib
dippykit.visualization.surf(x: numpy.ndarray, y: numpy.ndarray, z: numpy.ndarray, **kwargs) → None[source]

Plots a surface

Plots the x, y, and z values as a surface in 3D.

This function is essentially a wrapper for mpl_toolkits.mplot3d.axes3d.Axes3D.plot_surface, so more detailed documentation may be found there.

Parameters:
  • x (numpy.ndarray) – The array of x coordinates for the surface plot.
  • y (numpy.ndarray) – The array of y coordinates for the surface plot.
  • z (numpy.ndarray) – The array of z coordinates for the surface plot.

Note

This function wraps around functions from other packages. Reading these functions’ documentations may be useful. See the See also section for more information.

See also

mpl_toolkits.mplot3d.axes3d.Axes3D.plot_surface
Documentation of the plot_surface function from Matplotlib
dippykit.visualization.setup_continuous_rendering(render: typing.Callable[[matplotlib.axes._axes.Axes, typing.Any], NoneType], update: typing.Callable[<bound method BaseContext.Queue of <multiprocessing.context.DefaultContext object at 0x000001A91FFD9748>>, NoneType], delay: int = 100, auto_play: bool = True, precompute: bool = False, clear_axes: bool = True) → None[source]

Sets up a continuous renderer

This function sets up a window to display data that can continuously change. To best understand this function, try copying the example code below into a python file, running it, and then observing the results.

Parameters:
  • render (Callable[[Axes, Any], None]) – A function that takes a matplotlib Axes object and any data as arguments. This function returns nothing. This function should use the Axes object to update the rendering each time a new datum is received. These data are supplied through the update function.
  • update (Callable[[Queue], None]) – A function that takes a Queue as an argument and returns nothing. This function should update the rendering by putting each new datum into its queue via the Queue.put() function. These data are then subsequently rendered by the render function. Once this function places None into the queue, the rendering will cease to update.
  • delay (int) – (default=100) The time (in milliseconds) between calling the render function to update the rendering. Also known as the refresh rate.
  • auto_play (bool) – (default=True) If set to false, the rendering will prompt the user before each update.
  • precompute (bool) – (default=False) If set to true, the update function will be called once before any rendering takes place. In this single call, the queue is to be populated with all data needed for the entire rendering process. Setting this parameter to true also removes the multiprocessing aspect of the visualization, which can be useful for those with restrictions to multiprocessing in their code.
  • clear_axes (bool) – (default=True) If set to true, the axes will be cleared before each rendering. This is generally an individuals desired performance, but can be disabled if one wants to hand axes manually.
Returns:

None

Examples:

# This file will generate a rendering of a square moving in an image

import numpy as np
import dippykit as dip

def render_square(ax, data):
    # Show the image without any axis
    ax.imshow(data, 'gray')
    ax.axis('off')

def update_square(queue):
    # Create an arbitrary animation of a square progressively moving
    # through the image
    for i in range(9):
        square = np.zeros(9)
        square[i] = 1
        square = square.reshape((3, 3))
        queue.put(square)
    # Putting None into the queue tells the renderer to cease updating
    queue.put(None)

if __name__ == '__main__':
    # Sets up a continuous rendering using the functions above.
    # The rendering will update every 1000 milliseconds (1 second).
    dip.setup_continuous_rendering(render_square, update_square, 1000)
# This file will generate renderings of happy and sad faces

import numpy as np
import dippykit as dip

def render_face(ax, data):
    # Break the data into more manageable variable names
    mouth, left_eye, right_eye, is_happy = data
    mouth_x, mouth_y = mouth
    left_eye_x, left_eye_y = left_eye
    right_eye_x, right_eye_y = right_eye
    # First, clear the axes
    ax.clear()
    # Draw the face
    ax.plot(mouth_x, mouth_y)
    ax.plot(left_eye_x, left_eye_y)
    ax.plot(right_eye_x, right_eye_y)
    # Set the appropriate title to the axes
    if is_happy:
        ax.set_title('Happy Face - Press ENTER to toggle')
    else:
        ax.set_title('Sad Face - Press ENTER to toggle')

def update_face(queue):
    # Defining all the arrays
    mouth_x = np.array(range(31)) - 15
    happy_mouth_y = 20 * (mouth_x/15) ** 2
    sad_mouth_y = 20 - happy_mouth_y
    u = np.linspace(0, 1, 21)
    left_eye_x = np.cos(2 * np.pi * u) - 9
    right_eye_x = np.cos(2 * np.pi * u) + 9
    eye_y = np.sin(2 * np.pi * u) + 29
    # Aggregating the data into single tuples
    happy_mouth = (mouth_x, happy_mouth_y)
    sad_mouth = (mouth_x, sad_mouth_y)
    left_eye = (left_eye_x, eye_y)
    right_eye = (right_eye_x, eye_y)
    happy_face = (happy_mouth, left_eye, right_eye, True)
    sad_face = (sad_mouth, left_eye, right_eye, False)
    is_happy = True
    while True:
        # If the queue is empty
        if queue.empty():
            # Alternate with happy and sad faces
            if is_happy:
                queue.put(happy_face)
                is_happy = False
            else:
                queue.put(sad_face)
                is_happy = True

if __name__ == '__main__':
    # Sets up a continuous rendering using the functions above.
    # This rendering will await user input before updating the display.
    dip.setup_continuous_rendering(render_face, update_face,
                                   auto_play=False)
dippykit.visualization.zlabel(s: str, *args, **kwargs) → None[source]

Writes a string to the z axis label

Provided that the current axes has a z axis, this function will write the given string to the axis label.

This function is essentially a wrapper for mpl_toolkits.mplot3d.axes3d.Axes3D.set_zlabel, so more detailed documentation may be found there.

Parameters:s (str) – The string to write to the z axis label.
Returns:None

Note

This function wraps around functions from other packages. Reading these functions’ documentations may be useful. See the See also section for more information.

See also

mpl_toolkits.mplot3d.axes3d.Axes3D.set_zlabel
Documentation of the set_ylabel function (set_zlabel has no formal documentation) from Matplotlib