This module import functions to manipulate images

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)

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)

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

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

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

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

image.algo.basic.border(img, (x_min, y_min, z_min)=(0, 0, 0), (x_max, y_max, z_max)=(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
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
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from openalea.image import end_margin
img = random.random((3,4,5))

out = end_margin(img,1,0)
assert out.shape == (3,4,5)

assert (out[2,:,:] == zeros((4,5))).all()
assert (out[1:2,:,:] == img[1:2,:,:]  ).all()

out = end_margin(img,1,1)
assert out.shape == (3,4,5)

assert (out[:,3,:] == zeros((3,5))).all()
assert (out[:,1:3,:] == img[:,1:3,:] ).all()
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

image.algo.basic.reverse_image(image)[source]
image.algo.basic.color2grey(image)[source]

Convert a color image into a grey-level image.

image.algo.basic.grey2color(r, g, b)[source]

convert a grey-level image into a color image.

image.algo.basic.logicalnot(img)[source]
image.algo.basic.scale_shift_intensities(image, dtype=None, maxIn=None, maxOut=255)[source]

This Page