Openalea.Image.Algo Package#
Algo.Basic#
openalea.image.algo.basic#
This module import functions to manipulate images
- openalea.image.algo.basic.apply_mask(img, mask, background_color=None)[source]#
Apply a mask on a given image
If background_color is None, the mask is applied as the alpha channel in image. Pixels whose value is True will have an alpha value of 255 and others will have an alpha value of 0
Else, pixels whose value is True will conserve their original color and others will have a color equal to background color
- Parameters:
img (NxM(xP)x3(4) array of uint8)
mask (NxM(xP) array of bool)
background_color (int,int,int,(int) )
- Returns Type:
(NxM(xP)x3(4) array of uint8)
- openalea.image.algo.basic.border(img, xxx_todo_changeme=(0, 0, 0), xxx_todo_changeme1=(0, 0, 0))[source]#
A border is a outside black space that can be added to an array object.
- Parameters:
img ( NxMxP array)
x_min, y_min, z_min (int, int,int) - The begining of the border
x_max, y_max, z_max (int, int, int) - The end of the border
- Returns Type:
(N+x_min+x_max) x (M+y_min+y_max) x (P+z_min+z_max) array
- openalea.image.algo.basic.bounding_box(mask)[source]#
Compute the bounding box of a mask
- Parameters:
mask (array of bool) - a nd array of booleans
- Returns:
a slice (ind_min,ind_max) for each dimension of the mask or None if the mask do not contain any True value. Where ind_min correspond to the first slice that contains a True value and ind_max correspond to the first slice that contains only False after slices that contain at least one True value
- Returns Type:
list of (int,int)
- openalea.image.algo.basic.color_select(img, color, tol)[source]#
Create a mask to conserve only colors around the given color.
http://en.wikipedia.org/wiki/Color_difference
- Parameters:
img (NxM(xP)x3(4) array of uint8)
`color (int,int,int) - R,G,B color
- tol (int between 0 and 100) - distance max between a pixel and color
to be conserved
- Returns Type:
NxM(xP) array of bool
- openalea.image.algo.basic.end_margin(img, width, axis=None)[source]#
A end margin is a inside black space that can be added into the end of array object.
- Parameters:
img ( NxMxP array)
width (int) - size of the margin
axis (int optional) - axis along which the margin is added.
By default, add in all directions (see also stroke).
- Returns Type:
img
1from openalea.image import end_margin 2img = random.random((3,4,5)) 3 4out = end_margin(img,1,0) 5assert out.shape == (3,4,5) 6 7assert (out[2,:,:] == zeros((4,5))).all() 8assert (out[1:2,:,:] == img[1:2,:,:] ).all() 9 10out = end_margin(img,1,1) 11assert out.shape == (3,4,5) 12 13assert (out[:,3,:] == zeros((3,5))).all() 14assert (out[:,1:3,:] == img[:,1:3,:] ).all()
- openalea.image.algo.basic.flatten(img_list, alpha=False)[source]#
Concatenate all images into a single image
Use alpha to blend images one on top of each other
Warning
all images must have the same nD shape and an alpha channel (except maybe for the first one)
If alpha is True, the resulting image will use the max of all alpha channels as an alpha channel.
Warning
if the first image is a |SpatialImage|, the resulting image will also be a |SpatialImage| but no test is made to ensure consistency in the resolution of the layers
- Parameters:
img_list (list of NxM(xP)x4 array of uint8)
alpha (bool) - the resulting image will have an alpha channel or not
- Returns Type:
NxM(xP)x3(4) array of uint8
- openalea.image.algo.basic.grey2color(r, g, b)[source]#
convert a grey-level image into a color image.
- openalea.image.algo.basic.high_level(img, threshold)[source]#
Create a mask where all pixel whose intensity is smaller than threshold are transparent.
- Parameters:
img (NxM(xP)x3(4) array of uint8)
threshold (int between 0 and 255)
- Returns Type:
NxM(xP) array of bool
- openalea.image.algo.basic.saturate(img)[source]#
Saturate colors in the image
- Parameters:
img (NxM(xP)x3(4) array of uint8)
- Returns Type:
NxM(xP)x3(4) array of uint8
- openalea.image.algo.basic.scale_shift_intensities(image, dtype=None, maxIn=None, maxOut=255)[source]#
- openalea.image.algo.basic.stroke(img, width, outside=False)[source]#
A stroke is an outline that can be added to an array object.
- Parameters:
img ( NxMxP array)
width (int) - size of the stroke
outside (bool optional) - used to set the position of the stroke.
By default, the position of the stroke is inside (outside = False)
:Return Type : img
Algo.Morpho#
openalea.image.algo.morpho#
This module import morphology functions
- openalea.image.algo.morpho.component_labeling(img, structure=None, output=None, threshold=0, number_labels=0)[source]#
Connected-component label features in an array.
- Parameters:
img (array) - object to be labeled.
Any non-zero values in input are counted as features and zero values are considered the background.
structure (array) optional - structuring element that defines feature connections.
structure must be symmetric. If no structuring element is provided, one is automatically generated with a squared connectivity equal to one.
That is, for a 2D input array, the default structuring element is:
- array([[0,1,0],
[1,1,1], [0,1,0]])
output (None, data-type, array) optional
If output is a data type, it specifies the type of the resulting labeled feature array If output is an array-like object, then output will be updated with the labeled features from this function.
threshold (float) optional
If threshold > 0, the threshold is used to the input The input contains elements ‘False’ if input < threshold, and elements ‘True’ elsewhere
number_labels (int)
If number_labels > 0, number_labels of connected component labels is returned If number_labels = 1, the largest connected component label is returned
- Returns Type:
labeled_array - array object where each unique feature has a unique value
num_features (int)
If output is None or a data type, this function returns a tuple : (labeled_array, num_features). If output is an array, then it will be updated with values in : labeled_array and only num_features will be returned by this function.
- openalea.image.algo.morpho.skiz(image, points, vectors=None)[source]#
Compute the Skeleton of Influence Zone - also know as Generalized Voronoi Diagram.
Compute a labelled image …
- Parameters:
image : initial 3d image to get its shape
points : a list of 3d points
vectors: a list of 3d points
- Returns:
labelled image with the same shape of the initial one.