MLV_toolbox package

Submodules

MLV_toolbox.InitializeNeighborhoods module

MLV_toolbox.InitializeNeighborhoods.InitializeNeighborhoods()[source]

Initializes an 8-neighborhood array.

Returns:

numpy.ndarray – An 8x2 array representing the 8-neighborhood of a pixel.

MLV_toolbox.VecLD module

class MLV_toolbox.VecLD.VecLD(originalImage: Optional[str] = None, imsize: Optional[ndarray] = None, lineMethod: Optional[str] = None, numContours: Optional[int] = None, contours: Optional[ndarray] = None)[source]

Bases: object

A class to represent a vectorized linedrawing.

Variables:
  • originalImage (str) – the original image as a string

  • imsize (np.ndarray) – the size of the image as a NumPy array

  • lineMethod (str) – the method used to detect lines in the image

  • numContours (int) – the number of contours in the image

  • contours (np.ndarray) – the contours of the image as a NumPy array

InitializeNeighborhoods()

Initializes an 8-neighborhood array.

Returns:

numpy.ndarray – An 8x2 array representing the 8-neighborhood of a pixel.

MLV_toolbox.applyCircularAperture module

MLV_toolbox.applyCircularAperture.applyCircularAperture(vecLD: VecLD, radius=None)[source]

Apply circular aperture to the vector line-drawing.

Parameters:

radius (float) – Radius of the circular aperture.

MLV_toolbox.averageProperty module

MLV_toolbox.averageProperty.averageProperty(vecLD: VecLD, property: str) float[source]

Computes the average value of a property over the entire drawing vecLD.

Parameters:
  • vecLD (VecLD) – A VecLD object containing contour data.

  • property (str) – The property to be averaged. Must be a property of the VecLD object. The following are valid options for property: ‘orientation’: concatenate all straight line segments and return the orientation of the resulting vector, unit: degrees; ‘length’: Return the average of the lengths of the individual contours, unit: pixels; ‘curvature’: compute the mean curvature over all line segments, weighted by the number of pixels in the segments, unit: degrees / pixel; ‘junctions’: compute the number of juncions per 10,000 pixels, comptued as the sum over normJunctionTypeHistogram, unit: count per 10,000 pixels; ‘mirror’,’parallelism’,’separation’: compute the average value over all contour pixels, unit: number between 0 and 1.

Returns:

meanProperty (float) – the mean value of property based on the descriptions above.

MLV_toolbox.computeColorIndex module

MLV_toolbox.computeColorIndex.computeColorIndex(vecLD: VecLD, property: str) Tuple[ndarray, ndarray][source]

Computes the color index for a given property of a vector of contours.

Parameters:
  • vecLD – A vector of contours represented as a VecLD object.

  • property – A string indicating the property to use for computing the color index. Possible values are ‘length’, ‘curvature’, and ‘orientation’.

Returns:

A tuple containing the color index as a numpy array and the colormap as a matplotlib colormap object.

Raises:

ValueError – If the specified property is not one of ‘length’, ‘curvature’, or ‘orientation’.

MLV_toolbox.computeGradientVectorField module

MLV_toolbox.computeGradientVectorField.computeGradientVectorField(binaryImage: ndarray) Tuple[ndarray, int][source]

Computes the gradient vector field of a binary image.

Parameters:

binaryImage (np.ndarray) – A binary image.

Returns:
  • D (np.ndarray) – distance map computed with respect to the binary image.

  • IDX (int) – index of closest point to the boundary.

MLV_toolbox.computeGradientVectorField.getOuterBoundary(binaryImage: ndarray, background) Tuple[ndarray, ndarray][source]

Gets the outer boundary of a binary image.

Parameters:
  • binaryImage (np.ndarray) – A binary image.

  • background (int) – The background value of the binary image.

Returns:
  • result (np.ndarray) – Stores coordinates of outer boundary points of the binary image.

  • result2 (np.ndarray) – Binary image with outer boundary points set to 1 and all other points set to 0.

MLV_toolbox.computeGradientVectorField.is_outer_border_point(binaryImage: ndarray, ii: float, jj: float, m_Neighbors8: ndarray, background: int) int[source]

Determines whether a point is an outer border point.

Parameters:
  • binaryImage (np.ndarray) – A binary image.

  • ii (float) – The row index of the point.

  • jj (float) – The column index of the point.

  • m_Neighbors8 (np.ndarray) – An array of the 8-neighborhood.

  • background (int) – The background value of the binary image.

Returns:

result2 (int) – 1 if the point is an outer boundary point, 0 otherwise.

MLV_toolbox.computeLength module

MLV_toolbox.computeLength.computeLength(self)[source]

Computes the length for the contours in the vectorized line drawing vecLD.

Parameters:

vecLD (dict) – A dictionary representing the vectorized line drawing data structure that has length information added via the function.

MLV_toolbox.computeOrientation module

MLV_toolbox.computeOrientation.computeOrientation(vecLD: VecLD)[source]

Computes orientations for the contours in the vectorized line drawing vecLD. Note that this computes orientations from 0 to 360 degrees. To obtain orientation from 0 to 180, use ori % 180.

Parameters:

vecLD (VecLD) – A VecLD object containing contour data.

MLV_toolbox.drawLinedrawing module

MLV_toolbox.drawLinedrawing.drawLinedrawing(self, filename: str = 'linedrawing.png', lineWidth: float = 1, color: ndarray = array([0, 0, 0]))[source]

Draws the line drawing and saves it to a file.

Parameters:
  • filename (str) – The name of the file to save the image to.

  • lineWidth (float) – The width of the lines in the image.

  • color (np.ndarray) – The color of the lines in the image.

MLV_toolbox.generateFeatureDensityMap module

MLV_toolbox.generateFeatureDensityMap.generateFeatureDensityMap(vecLD: VecLD, property: str, smoothingSigma: float = 0, junctionTypes: Optional[ndarray] = None) ndarray[source]

Generates a fixation density map for one of the contour properties and optionally smoothes the map with a 2D Gaussian with standard deviation smoothingSigma.

Parameters:
  • vecLD (VecLD) – the vectorized line drawing with the property already computed.

  • property (str) – one of ‘length’,’curvature’,’orientation’, ‘junctions’, ‘mirror’,’parallelism’,’separation’

  • smoothingSigma (float) – the standard deviation of the 1D Gaussian smoothing kernel (in pixels). When 0 (the default), no smoothing is performed.

  • junctionTypes (str) – only relevant for property = ‘junctions’. A cell array of the type(s) of junctions that should be considered. Default: {} - all junctions.

Returns:

FDM (np.ndarray) – the feature density map with the size as the image. The FDM is generated using the raw feature values. No normalization is applied. You may want to normalize it to sum to 1 (as a probability distribution) or to have 0 mean and unit standard deviation (for normalized salience scanpath analysis).

MLV_toolbox.getDistanceFromLineSegment module

MLV_toolbox.getDistanceFromLineSegment.getDistanceFromLineSegment(XY: ndarray) ndarray[source]

Computes the distance between a set of points and a line segment in 2D space.

Parameters:

XY – A NumPy array of shape (N, 4) containing the coordinates of N line segments. Each row of the array should contain the x and y coordinates of the starting and ending points of a line segment, in that order.

Returns:
  • A NumPy array of shape (N,)

  • and the set of points.

Raises:

ValueError – If the input array is not of shape (N, 4).

MLV_toolbox.getMATpropertyStats module

MLV_toolbox.getMATpropertyStats.getMATpropertyStats(vecLD: VecLD, property: str, numBins: int = 8) Tuple[VecLD, float, float][source]

Computes statistics for a given property of a vectorized line drawing.

Parameters:
  • vecLD (dict) – A dictionary representing the vectorized line drawing data structure.

  • property (str) – The name of the property to compute statistics for.

  • num_bins (int) – The number of bins to use for the histogram.

Returns:

tuple – A tuple containing the modified vecLD dictionary, the computed histogram, the bin edges, and a short name for the property.

MLV_toolbox.lineIntersection module

MLV_toolbox.lineIntersection.lineIntersection(queryLine: ndarray, refLine: ndarray, RE: float = 0.3, AE: float = 2) ndarray[source]

Determine if two line segments intersect and, if so, where.

Parameters:
  • queryLine (np.ndarray) – A 2x2 array representing the query line segment with start and end coordinates: [X1,Y1,X2,Y2].

  • refLine (np.ndarray) – A 2x2 array representing the reference line segment with start and end coordinates: [X1,Y1,X2,Y2].

  • RE (float) – The relative error threshold for the intersection point. Default is 0.3.

  • AE (float) – The absolute error threshold for the intersection point in pixels. Default is 2.

Returns:

Position (np.ndarray) – A 2x1 array representing the intersection point with coordinates: [X,Y]. If the lines do not intersect, Position will be empty [].

MLV_toolbox.loadData module

MLV_toolbox.loadData.importMat(self, filename_mat)[source]

Imports a vectorized linedrawing from a .mat file.

Parameters:

filename_mat (str) – the filename of the .mat file to import

MLV_toolbox.loadData.importMatNew(filename_mat)[source]

Imports a vectorized linedrawing from a .mat file.

Parameters:

filename_mat (str) – the filename of the .mat file to import

Returns:

The vectorized linedrawing as a VecLD object

MLV_toolbox.removeZeroLengthContours module

MLV_toolbox.removeZeroLengthContours.removeZeroLengthContours(vecLD: VecLD)[source]

Removes contours that only consist of one pixel from a VecLD object.

Parameters:

vecLD (VecLD) – A VecLD object containing contour data.

Returns:
  • resultLD (VecLD) – vectorized line drawing wiht zero-length contours removed

  • contourIdxRemoved (np.ndarray) – indices of contours in vecLD that were removed

Raises:

TypeError – If vecLD is not a VecLD object.

MLV_toolbox.renderLinedrawing module

MLV_toolbox.renderLinedrawing.renderLinedrawing(self, img: Optional[ndarray] = None, imsize: Optional[ndarray] = None, lineWidth: int = 1, color: ndarray = array([0, 0, 0]))[source]

Renders the vectorized linedrawing onto an image.

Parameters:
  • img (np.ndarray) – the image to render the linedrawing onto

  • imsize (np.ndarray) – the size of the image

  • lineWidth (int) – the width of the lines to draw

  • color (np.ndarray) – the color of the lines to draw

MLV_toolbox.rotateLinedrawing module

MLV_toolbox.rotateLinedrawing.rotateLinedrawing(cls, vecLD, angle)[source]

Rotate a linedrawing by a given angle (in degrees).

Parameters:
  • vecLD (VecLD) – the vectorized linedrawing to rotate

  • angle (float) – the angle to rotate the linedrawing by (in degrees)

Returns:

The rotated vectorized linedrawing as a VecLD object.

Module contents