Profiles¶
This submodule contains the attribute profiles related classes.
Example
Create the attribute profiles (AP) of image based on area attribute and three thresholds.
>>> aps = sap.attribute_profiles(image, {'area': [10, 100, 1000]})
>>> aps.vectorize()
[[...]]
Create the extended AP of image based on area compactness and volume attributes.
>>> attributes = {'compactness': [.1, .5, .7], 'volume': [10, 100]}
>>> eaps = sap.attribute_profiles(image, attributes)
>>> eaps.vectorize()
[[...]]
Todo
- Names:
vectorize or concatenate ?
-
class
sap.profiles.
Profiles
(data, description)[source]¶ Bases:
object
Base class for profiles.
- Parameters
data (list of ndarray) – List of ndarray representing profiles grouped by image or attribute filtering.
description (list of dict) – List of dictionary containing the metadata of the profiles.
-
sap.profiles.
attribute_profiles
(image, attribute, adjacency=4, image_name=None)[source]¶ Compute the attribute profiles of an image.
- Parameters
image (ndarray) – The image
attribute (dict) – Dictionary of attribute (as key, str) with according thresholds (as values, number).
adjacency (int) – Adjacency used for the tree construction. Default is 4.
image_name (str) – The name of the image (optional). Useful to track filtering process and display. If not set, the name is replaced by the hash of the image.
Examples
>>> image = np.random.random((100, 100)) >>> sap.attribute_profiles(image, {'area': [10, 100]}) Profiles[{'attribute': 'area', 'image': 6508374204896978831, 'profiles': [{'operation': 'open', 'threshold': 100}, {'operation': 'open', 'threshold': 10}, {'operation': 'copy'}, {'operation': 'close', 'threshold': 10}, {'operation': 'close', 'threshold': 100}]}]
See also
sap.trees.available_attributes()
List available attributes.
-
sap.profiles.
show_all_profiles
(profiles, attribute=None, image=None, height=None, fname=None, **kwargs)[source]¶ Display profiles with matplotlib.
- Parameters
profiles (sap.profiles.Profiles) – The profiles to display.
attribute (sring, optional) – Name of attribute to display. By default display all the attributes contained in profiles.
image (string, optional) – Name of the image to display. By default display the profiles of all images.
height (scalar, optional, default: None) – Height of the figure in inches. Automatically adjust the size of the figure to display correctly the profiles and the title with matplot.
fname (str or PathLike, optional) – If set, the file path to save the figure. The attribute name is automatically inserted in the file name.
See also
show_profiles()
Display a profiles stack.
Notes
This is a utility function to call recursively show_profiles. Attribute and image filters are available to filter the profiles to display.
-
sap.profiles.
show_profiles
(profiles, height=None, fname=None, **kwargs)[source]¶ Display a profiles stack with matplotlib.
- Parameters
profiles (Profiles) – The profiles to display. Can be only of length 1.
height (scalar, optional, default: None) – Height of the figure in inches. Automatically adjust the size of the figure to display correctly the profiles and the title with matplot.
fname (str or PathLike, optional) – If set, the file path to save the figure. The attribute name is automatically inserted in the file name.
See also
show_profiles_all()
Display several profiles at once.