colourlab.gamut

Constructing Gamut

To construct a new Gamut we need to provide a colour space in the format provided by colourlab.space, and data/colour points in the format given the colourlab.data.Data class. If we want to construct the new Gamut in the colourlab RGB and the fictive points my_points, we would do the following:

For convex hull

c_data = data.Data(space.srgb, my_points)    # First generate the Data object to use
g = gamut.Gamut(space.srgb, c_data)          # Pass along the colourlab and c_data

For modified-convex hull

When using the modified constructor, we have to choose an exponent for modifying the gamut radius(gamma), and define the center for expansion.

c_data = data.Data(space.srgb, my_points)                        # First generate the Data object to use
g = gamut.Gamut(space.srgb, c_data, gamma=0.2, center=my_center) # Pass along the colourlab, c_data, gamma and center

Examples

For all examples: * space: a colourlab.space.Space object * c_data: a colourlab.data.Data object * p_in/p_out: a point inside/outside the gamut

All examples presupposes that you have created a colour Data object(c_data) and a gamut(g) object.

c_data = data.Data(space, gamut_points)  # Generating the colour Data object
g = gamut.Gamut(space, c_data)           # Creates a new gamut

is_inside()

The function receives two parameters, colourspace and a colour data object(c_data). The function checks if points are inn the gamout boundry and returns an boolean-array containing true/false in the last dimension.

a = g.is_inside(space, c_data)                # Call the method

plot_surface()

The function receives two parameters axis and space. The function visualizes a gamut figure in 3D.

fig = plt.figure()                            # Creates a figure
axis = fig.add_subplot(111, projection='3d')  # Creates a 3D plot ax
space = g.space                               # Specifies the color space
g.plot_surface(axis, space)                   # Call the method

intersection_on_line():

The function receives three parameters. The colourspace, the points in the c_data format, and center(if no center is defined, it will use the default gamut center). The function will return nearest point along a line between the point and the given center.

points = np.array([[15, 5, 5], [5, 15, 5], [5, 5, 15]])             # Points outside the gamut object
c_data = data.Data(space.srgb, points)                              # data.Data object
re_data = g.intersection_on_line(space.srgb, c_data)                # Call the method

clip_nearest()

The function receives two parameters, colourspace and colour data.outside are colour data object and are represented as numpy arrays of dimensions Nx…xMx3. The function will return nearest point in 3D.

points = np.array([[5, 5, 15], [5, 5, 15], [5, 5, 15]])                   # Points outside the gamut object
c_data = data.Data(space.srgb, points)                                    # data.Data object
re_data = g.clip_nearest(space.srgb, c_data)                              # Call the method

compress_axis()

The function receives three parameters. The color space, pints in the c_data format, and the axis to compress as integer. The axis range is [0,1,2] where 0==X, 1==Y and 2==Z.

c = g.compress_axis(space, c_data, axis)    # Call the method

HPminDE()

The function receives one parameter. The points in the c_data format, Maps all points that lie outside of the gamut to the nearest point on the plane formed by the point and the L axe in the CIELAB colour space. Returns coordinate for the closest point on plane in the colourlab.data.Data format.

points = np.array([[0, 8, 8], [4, 0, 9], [4, 4, 3], [0, 10, 0], [15, 0, 0]])    # Points outside the gamut object
c_data = data.Data(space.cielab, points)                                        # data.Data object
re_data = g.HPminDE(c_data)                                                     # Call the method

minDE()

The function receives one parameter. The points in the c_data format, and maps all points that lie outside of the gamut to the nearest point on the gamut in CIELAB colour space. Returns the nearest point in the colourlab.data.Data format.

mapped_im = g.minDE(c_data)               # Call the method

Attributes

Attribute Description
data The data.Data object used when constructed.
space The original colour space used when constructed.
hull* The gamuts convex hull in the desired colour space.
vertices Indices of points forming the vertices of the convex hull.
simplices Indices of points forming the simplices facets of the convex Hull.
neighbors Indices of neighbor facets for each facet.
center The Gamuts geometric center.

*see documentation on convex hull for a list of attributes. https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.ConvexHull.html

Methods

  • is_inside()
  • plot_surface()
  • intersection_on_line():
  • clip_nearest()
  • compress_axis()
  • HPminDE()
  • minDE()
Method Description Return
is_inside(sp, c_dat a, t=false) Returns a boolean array containing T/F for all points in the array. boolean array
plot_surface(ax, sp ) Plot the gamut’s simplices.
intersection_on_lin e(sp, c_data, center= None): Returns the nearest point in a line on a gamut surface from the given point to the given center. np.array
_clip_nearest(sp, p _out, side) Returns the nearest point on a gamut in 3D. np.array
compress_axis(sp, c _data, ax): Compresses the points linearly in the desired axel and colour space. colourlab.data .Data object
HPminDE(c_data): Get coordinate for the closest point on plane and return mapped points colourlab.data .Data object
minDE(c_data): Get nearest point and return mapped points. colourlab.data .Data object