Classes/Modules

Images

class Images.Images(folder_name, image_file_ext=['tif', 'tiff'])[source]

This class loads a collection of images for extraction of features

Parameters:
  • folder_name (List of strings) – folder containing images
  • image_file_ext – images file extensions (default=[‘tif’,’tiff’])
Returns:

an instance of the object Images

Return type:

object

Example:
>>> import image_features_extraction as fe
>>> imgs = fe.Images('my_folder', image_file_ext=['tif','tiff','jpeg'])
>>> num_images = imgs.count()
count()

returns the number of items

count_update(count)
item(i)[source]

returns the i-th image

Parameters:i (int) – the i-th image
Returns:Image
Return type:object
Example:
>>> import image_features_extraction as fe
>>> imgs = fe.Images(folder_name)
>>> img = imgs.item(1)

Image

class Image.Image(full_name)[source]

This class instantiate an object Image through the Images and refers to a specific file image

Example:
>>> import image_features_extraction as fe
>>> imgs = fe.Images(folder_name)
>>> img = imgs.item(1)
Voronoi()[source]

Image Voronoi diagram (refer to documentaiton of my package Voronoi_Features in my github )

Returns:Voronoi object for the current image
Return type:Voronoi object
>>> import matplotlib.pyplot as plt
>>>
>>> import image_features_extraction as fe
>>>
>>> imgs = fe.Images(folder_name)
>>> img = imgs.item(1)
>>>
>>> voro = img.Voronoi()
>>> # show voronoi diagram
>>> fig = plt.figure(figsize=(20,20))
>>> plt.imshow(vor.get_voronoi_map(), cmap=plt.get_cmap('jet'))
features(features_list, prefix='', suffix='')[source]

Returns a table with all values for the property names given in input, and supplies an additional parameter for feature classification

Parameters:
  • features_list (List) – list of property/measure names (e.g, ‘area’, ‘centroid’, etc )
  • prefix (string) – prefix for features name
  • suffix (string) – prefix for features name
Returns:

Features Object

Return type:

Features Object

Example:
>>> import image_features_extraction as fe
>>> imgs = fe.Images(folder_name)
>>> img = imgs.item(1)
>>> feature = img.get_features(['label', 'area','perimeter', 'centroid'])
file_name()[source]

full file name of the image

Returns:file name
Return type:string
get_image_segmentation()[source]

Builds the image with mask overlay to show the segmentation

Returns:The image in RGB format, in a 3-D array of shape (.., .., 3).
Return type:ndarray
height()[source]
prop_values(prop_name)[source]

Measure the values of the specified property/measure name (e.g., ‘area’) for all elements contained in the object Regions.

Parameters:prop_name (string) – name of the property to measure (e.g, ‘area’)
Returns:property name values
Return type:List
Example:
>>> import image_features_extraction as fe
>>> imgs = fe.Images(folder_name)
>>> img = imgs.item(1)
>>> regs = img.Regions()
>>> areas = regs.prop_values('area')

The following properties can be accessed as attributes or keys:

area : int
Number of pixels of region.
bbox : tuple
Bounding box (min_row, min_col, max_row, max_col). Pixels belonging to the bounding box are in the half-open interval [min_row; max_row) and [min_col; max_col).
bbox_area : int
Number of pixels of bounding box.
centroid : array
Centroid coordinate tuple (row, col).
convex_area : int
Number of pixels of convex hull image.
convex_image : (H, J) ndarray
Binary convex hull image which has the same size as bounding box.
coords : (N, 2) ndarray
Coordinate list (row, col) of the region.
eccentricity : float
Eccentricity of the ellipse that has the same second-moments as the region. The eccentricity is the ratio of the focal distance (distance between focal points) over the major axis length. The value is in the interval [0, 1). When it is 0, the ellipse becomes a circle.
equivalent_diameter : float
The diameter of a circle with the same area as the region.
euler_number : int
Euler characteristic of region. Computed as number of objects (= 1) subtracted by number of holes (8-connectivity).
extent : float
Ratio of pixels in the region to pixels in the total bounding box. Computed as area / (rows * cols)
filled_area : int
Number of pixels of filled region.
filled_image : (H, J) ndarray
Binary region image with filled holes which has the same size as bounding box.
image : (H, J) ndarray
Sliced binary region image which has the same size as bounding box.
inertia_tensor : (2, 2) ndarray
Inertia tensor of the region for the rotation around its mass.
inertia_tensor_eigvals : tuple
The two eigen values of the inertia tensor in decreasing order.
intensity_image : ndarray
Image inside region bounding box.
label : int
The label in the labeled input image.
local_centroid : array
Centroid coordinate tuple (row, col), relative to region bounding box.
major_axis_length : float
The length of the major axis of the ellipse that has the same normalized second central moments as the region.
max_intensity : float
Value with the greatest intensity in the region.
mean_intensity : float
Value with the mean intensity in the region.
min_intensity : float
Value with the least intensity in the region.
minor_axis_length : float
The length of the minor axis of the ellipse that has the same normalized second central moments as the region.
moments : (3, 3) ndarray
Spatial moments up to 3rd order::
m_ji = sum{ array(x, y) * x^j * y^i }

where the sum is over the x, y coordinates of the region.

moments_central : (3, 3) ndarray
Central moments (translation invariant) up to 3rd order::
mu_ji = sum{ array(x, y) * (x - x_c)^j * (y - y_c)^i }

where the sum is over the x, y coordinates of the region, and x_c and y_c are the coordinates of the region’s centroid.

moments_hu : tuple
Hu moments (translation, scale and rotation invariant).
moments_normalized : (3, 3) ndarray
Normalized moments (translation and scale invariant) up to 3rd order::
nu_ji = mu_ji / m_00^[(i+j)/2 + 1]

where m_00 is the zeroth spatial moment.

orientation : float
Angle between the X-axis and the major axis of the ellipse that has the same second-moments as the region. Ranging from -pi/2 to pi/2 in counter-clockwise direction.
perimeter : float
Perimeter of object which approximates the contour as a line through the centers of border pixels using a 4-connectivity.
solidity : float
Ratio of pixels in the region to pixels of the convex hull image.
weighted_centroid : array
Centroid coordinate tuple (row, col) weighted with intensity image.
weighted_local_centroid : array
Centroid coordinate tuple (row, col), relative to region bounding box, weighted with intensity image.
weighted_moments : (3, 3) ndarray
Spatial moments of intensity image up to 3rd order::
wm_ji = sum{ array(x, y) * x^j * y^i }

where the sum is over the x, y coordinates of the region.

weighted_moments_central : (3, 3) ndarray

Central moments (translation invariant) of intensity image up to 3rd order:

wmu_ji = sum{ array(x, y) * (x - x_c)^j * (y - y_c)^i }

where the sum is over the x, y coordinates of the region, and x_c and y_c are the coordinates of the region’s weighted centroid.

weighted_moments_hu : tuple
Hu moments (translation, scale and rotation invariant) of intensity image.
weighted_moments_normalized : (3, 3) ndarray

Normalized moments (translation and scale invariant) of intensity image up to 3rd order:

wnu_ji = wmu_ji / wm_00^[(i+j)/2 + 1]

where wm_00 is the zeroth spatial moment (intensity-weighted area).

[1]http://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.regionprops
regions()[source]

regions(…) returns the Object Regions

Returns:Regions
Return type:string
>>> import image_features_extraction as fe
>>> imgs = fe.Images(folder_name)
>>> img = imgs.item(1)
>>> regs = img.Regions()
set_image_intensity(image_intensity)[source]

Sets the image to measurs image’s region intensity properties (e.g, mean_intensity)

: param image_intensity: Image object for intensity measurement : type image_intensity: Object Image :returns: the set Image object for intensity measurement :rtype: Object Image >>> import image_features_extraction as fe >>> imgs = fe.Images(folder_name) >>> img = imgs.item(1) # this is the binary image used for segmentation >>> img_intensity = imgs.item(0) # this is the original image on which to measure intensities >>> img.set_image_intensity(img_intensity) >>> features = IMG.features([‘label’, ‘area’,’perimeter’, ‘centroid’,’major_axis_length’, ‘moments’,’mean_intensity’], class_value=5)

width()[source]

Regions

class Regions.Regions(obj_regions)[source]

This class represent a collection of regions: segmented image elements It cannot be instanced directly. It is returned from the object Image through the function Regions(…)

Example:
>>> import image_features_extraction as fe
>>> imgs = fe.Images(folder_name)
>>> img = imgs.item(1)
>>> regs = img.Regions()
count()

returns the number of items

count_update(count)
features(feature_list)[source]

get_features(…) returns a table with all values for the property names given in input, and supplies an additional parameter for feature classification

Parameters:
  • features (List) – list of property/measure names (e.g, ‘area’, ‘centroid’, etc )
  • class_value (int, string (default=None)) – classification label

: param image_mask: expernal Image mask to be used for the segmentation :type image_mask: Image :returns: table cointaining all property values (columns) for all elements in the regions object (rows) :rtype: Pandas.DataFrame :example: >>> import image_features_extraction as fe >>> imgs = fe.Images(folder_name) >>> img = imgs.item(1) >>> regs = img.Regions() >>> feature = regs.get_features([‘label’, ‘area’,’perimeter’, ‘centroid’], class_value=1) >>> >>> # external image mask >>> img_masks = fe.Images(folder_name) >>> features = regs.get_features([‘label’, ‘area’,’perimeter’, ‘centroid’], class_value=1, image_mask=img_masks.item(1))

item(i)[source]

Item(..) returns the i-th image element of the regions.

Parameters:i (int) – the i-th element of the collection region
Returns:Region
Return type:object
Example:
>>> import image_features_extraction as fe
>>> imgs = fe.Images(folder_name)
>>> img = imgs.item(1)
>>> regs = img.Regions()
>>> reg = regs.item(1)
prop_values(prop_name)[source]

Measure the values of the specified property/measure name (e.g., ‘area’) for all elements contained in the object Regions.

Parameters:prop_name (string) – name of the property to measure (e.g, ‘area’)
Returns:property name values
Return type:List
Example:
>>> import image_features_extraction as fe
>>> imgs = fe.Images(folder_name)
>>> img = imgs.item(1)
>>> regs = img.Regions()
>>> areas = regs.prop_values('area')

The following properties can be accessed as attributes or keys:

area : int
Number of pixels of region.
bbox : tuple
Bounding box (min_row, min_col, max_row, max_col). Pixels belonging to the bounding box are in the half-open interval [min_row; max_row) and [min_col; max_col).
bbox_area : int
Number of pixels of bounding box.
centroid : array
Centroid coordinate tuple (row, col).
convex_area : int
Number of pixels of convex hull image.
convex_image : (H, J) ndarray
Binary convex hull image which has the same size as bounding box.
coords : (N, 2) ndarray
Coordinate list (row, col) of the region.
eccentricity : float
Eccentricity of the ellipse that has the same second-moments as the region. The eccentricity is the ratio of the focal distance (distance between focal points) over the major axis length. The value is in the interval [0, 1). When it is 0, the ellipse becomes a circle.
equivalent_diameter : float
The diameter of a circle with the same area as the region.
euler_number : int
Euler characteristic of region. Computed as number of objects (= 1) subtracted by number of holes (8-connectivity).
extent : float
Ratio of pixels in the region to pixels in the total bounding box. Computed as area / (rows * cols)
filled_area : int
Number of pixels of filled region.
filled_image : (H, J) ndarray
Binary region image with filled holes which has the same size as bounding box.
image : (H, J) ndarray
Sliced binary region image which has the same size as bounding box.
inertia_tensor : (2, 2) ndarray
Inertia tensor of the region for the rotation around its mass.
inertia_tensor_eigvals : tuple
The two eigen values of the inertia tensor in decreasing order.
intensity_image : ndarray
Image inside region bounding box.
label : int
The label in the labeled input image.
local_centroid : array
Centroid coordinate tuple (row, col), relative to region bounding box.
major_axis_length : float
The length of the major axis of the ellipse that has the same normalized second central moments as the region.
max_intensity : float
Value with the greatest intensity in the region.
mean_intensity : float
Value with the mean intensity in the region.
min_intensity : float
Value with the least intensity in the region.
minor_axis_length : float
The length of the minor axis of the ellipse that has the same normalized second central moments as the region.
moments : (3, 3) ndarray
Spatial moments up to 3rd order::
m_ji = sum{ array(x, y) * x^j * y^i }

where the sum is over the x, y coordinates of the region.

moments_central : (3, 3) ndarray
Central moments (translation invariant) up to 3rd order::
mu_ji = sum{ array(x, y) * (x - x_c)^j * (y - y_c)^i }

where the sum is over the x, y coordinates of the region, and x_c and y_c are the coordinates of the region’s centroid.

moments_hu : tuple
Hu moments (translation, scale and rotation invariant).
moments_normalized : (3, 3) ndarray
Normalized moments (translation and scale invariant) up to 3rd order::
nu_ji = mu_ji / m_00^[(i+j)/2 + 1]

where m_00 is the zeroth spatial moment.

orientation : float
Angle between the X-axis and the major axis of the ellipse that has the same second-moments as the region. Ranging from -pi/2 to pi/2 in counter-clockwise direction.
perimeter : float
Perimeter of object which approximates the contour as a line through the centers of border pixels using a 4-connectivity.
solidity : float
Ratio of pixels in the region to pixels of the convex hull image.
weighted_centroid : array
Centroid coordinate tuple (row, col) weighted with intensity image.
weighted_local_centroid : array
Centroid coordinate tuple (row, col), relative to region bounding box, weighted with intensity image.
weighted_moments : (3, 3) ndarray
Spatial moments of intensity image up to 3rd order::
wm_ji = sum{ array(x, y) * x^j * y^i }

where the sum is over the x, y coordinates of the region.

weighted_moments_central : (3, 3) ndarray

Central moments (translation invariant) of intensity image up to 3rd order:

wmu_ji = sum{ array(x, y) * (x - x_c)^j * (y - y_c)^i }

where the sum is over the x, y coordinates of the region, and x_c and y_c are the coordinates of the region’s weighted centroid.

weighted_moments_hu : tuple
Hu moments (translation, scale and rotation invariant) of intensity image.
weighted_moments_normalized : (3, 3) ndarray

Normalized moments (translation and scale invariant) of intensity image up to 3rd order:

wnu_ji = wmu_ji / wm_00^[(i+j)/2 + 1]

where wm_00 is the zeroth spatial moment (intensity-weighted area).

[1]http://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.regionprops

Region

class Region.Region(obj_region)[source]

Object refering to a single image region

prop_value(prop_name)[source]

Measure the specified property name (e.g., ‘area’)

Parameters:prop_name (string) – name of the property to measure (e.g, ‘area’)
Returns:value of the property name
Return type:int,float,list
Example:
>>> import image_features_extraction as fe
>>> imgs = fe.Images(folder_name)
>>> img = imgs.item(1)
>>> regs = img.Regions()
>>> reg = regs.Region()
>>> area = reg.prop_value('area')

The following properties can be accessed as attributes or keys:

area : int
Number of pixels of region.
bbox : tuple
Bounding box (min_row, min_col, max_row, max_col). Pixels belonging to the bounding box are in the half-open interval [min_row; max_row) and [min_col; max_col).
bbox_area : int
Number of pixels of bounding box.
centroid : array
Centroid coordinate tuple (row, col).
convex_area : int
Number of pixels of convex hull image.
convex_image : (H, J) ndarray
Binary convex hull image which has the same size as bounding box.
coords : (N, 2) ndarray
Coordinate list (row, col) of the region.
eccentricity : float
Eccentricity of the ellipse that has the same second-moments as the region. The eccentricity is the ratio of the focal distance (distance between focal points) over the major axis length. The value is in the interval [0, 1). When it is 0, the ellipse becomes a circle.
equivalent_diameter : float
The diameter of a circle with the same area as the region.
euler_number : int
Euler characteristic of region. Computed as number of objects (= 1) subtracted by number of holes (8-connectivity).
extent : float
Ratio of pixels in the region to pixels in the total bounding box. Computed as area / (rows * cols)
filled_area : int
Number of pixels of filled region.
filled_image : (H, J) ndarray
Binary region image with filled holes which has the same size as bounding box.
image : (H, J) ndarray
Sliced binary region image which has the same size as bounding box.
inertia_tensor : (2, 2) ndarray
Inertia tensor of the region for the rotation around its mass.
inertia_tensor_eigvals : tuple
The two eigen values of the inertia tensor in decreasing order.
intensity_image : ndarray
Image inside region bounding box.
label : int
The label in the labeled input image.
local_centroid : array
Centroid coordinate tuple (row, col), relative to region bounding box.
major_axis_length : float
The length of the major axis of the ellipse that has the same normalized second central moments as the region.
max_intensity : float
Value with the greatest intensity in the region.
mean_intensity : float
Value with the mean intensity in the region.
min_intensity : float
Value with the least intensity in the region.
minor_axis_length : float
The length of the minor axis of the ellipse that has the same normalized second central moments as the region.
moments : (3, 3) ndarray
Spatial moments up to 3rd order::
m_ji = sum{ array(x, y) * x^j * y^i }

where the sum is over the x, y coordinates of the region.

moments_central : (3, 3) ndarray
Central moments (translation invariant) up to 3rd order::
mu_ji = sum{ array(x, y) * (x - x_c)^j * (y - y_c)^i }

where the sum is over the x, y coordinates of the region, and x_c and y_c are the coordinates of the region’s centroid.

moments_hu : tuple
Hu moments (translation, scale and rotation invariant).
moments_normalized : (3, 3) ndarray
Normalized moments (translation and scale invariant) up to 3rd order::
nu_ji = mu_ji / m_00^[(i+j)/2 + 1]

where m_00 is the zeroth spatial moment.

orientation : float
Angle between the X-axis and the major axis of the ellipse that has the same second-moments as the region. Ranging from -pi/2 to pi/2 in counter-clockwise direction.
perimeter : float
Perimeter of object which approximates the contour as a line through the centers of border pixels using a 4-connectivity.
solidity : float
Ratio of pixels in the region to pixels of the convex hull image.
weighted_centroid : array
Centroid coordinate tuple (row, col) weighted with intensity image.
weighted_local_centroid : array
Centroid coordinate tuple (row, col), relative to region bounding box, weighted with intensity image.
weighted_moments : (3, 3) ndarray
Spatial moments of intensity image up to 3rd order::
wm_ji = sum{ array(x, y) * x^j * y^i }

where the sum is over the x, y coordinates of the region.

weighted_moments_central : (3, 3) ndarray

Central moments (translation invariant) of intensity image up to 3rd order:

wmu_ji = sum{ array(x, y) * (x - x_c)^j * (y - y_c)^i }

where the sum is over the x, y coordinates of the region, and x_c and y_c are the coordinates of the region’s weighted centroid.

weighted_moments_hu : tuple
Hu moments (translation, scale and rotation invariant) of intensity image.
weighted_moments_normalized : (3, 3) ndarray

Normalized moments (translation and scale invariant) of intensity image up to 3rd order:

wnu_ji = wmu_ji / wm_00^[(i+j)/2 + 1]

where wm_00 is the zeroth spatial moment (intensity-weighted area).

Features

class Features.Features(data_frame)[source]

contain the dataframe

get_class_name()[source]
get_class_value()[source]
get_dataframe(include_class=False)[source]

creates a panda data frame contining the feature values

Parameters:include_class (Boolean) – if True if includes the class name and value as the last column
merge(Features_Obj, how_in='inner')[source]

Merges in the current Features object a second Features object (ex. obtained from the Voronoi Object)

Parameters:
  • Features_Obj (Features (image_features_extraction package)) – External Features Object
  • how_in (string) – ‘inner’, ‘outer’
>>> import image_features_extraction.Images as fe
>>> IMGS = fe.Images('../images/CA/1')
>>> vor = IMG.Voronoi()
>>> features1 = IMG.features(['area','perimeter','centroid','bbox', 'eccentricity'])
>>> features2 = vor.features(['area','perimeter','centroid','bbox', 'eccentricity'])
>>> features3 = features1.merge(features2, how_in='inner')
>>> features3.get_dataframe().head()
save(storage_name, type_storage='file', do_append=True)[source]

save the current dataframe into the type of storage given in input.

Parameters:
  • storage_name (string) – storage name, (e.g., file name if ‘ storage type is ‘file’)
  • type_storage (string) – type of storage (default is ‘file’) (‘db’, ‘json’ will be future implementations)
  • do_append (boolean) – if True it appends to existing storage. If False it creates a new storage

if ‘do_append=True’: This version of the method does not check whether the new data are consistent with presisitng data into the existing storage. It just tries to append the date and might fail or not depending on the type of storage

Returns:1 if sucessuful otherwise 0
Return type:int
Example:
>>> import image_features_extraction as fe
>>> imgs = fe.Images(folder_name)
>>> img = imgs.item(1)
>>> reg = img.Regions().item(1)
>>> features = regs.get_features(['label', 'area','perimeter', 'centroid'], class_value=1)
>>> features.save('my_file_name')
set_class_name(class_name)[source]
set_class_value(class_value)[source]