1. image2d

1.1. Description

image2d is a class to store and work on 2d image in voxel. It is used to store the different variable in aita (phi1,phi,qua, …) It can be used to work one every king of 2d image.

There is two class that herite from image2d :

  1. mask2d to work on mask

  2. micro2d to work with microstructure

1.2. Function

Created on 3 juil. 2015

image2d is a class used to manipulate image under matrix shape and to do the analyses on the picture

Note

It has been build to manipulate both aita data and dic data

Warning

As all function are applicable to aita and dic data, please be careful of the meaning of what you are doing depending of the input data used !

@author: Thomas Chauve @contact: thomas.chauve@univ-grenoble-alpes.fr @license: CC-BY-CC

class AITAToolbox.image2d.image2d(field, resolution)[source]

image2d is a class for map of scalar data

__add__(other)[source]

Sum of 2 maps

__div__(other)[source]

Divide self by other case by case

__init__(field, resolution)[source]

Constructor : field is a matrix and resolution is the step size in mm

Parameters
  • field (array) – tabular of scalar data

  • resolution (float) – step size resolution (millimeters)

__mul__(other)[source]

Multiply case by case

__sub__(other)[source]

Subtract of 2 maps

__weakref__

list of weak references to the object (if defined)

auto_correlation(pad=1)[source]

Compute the auto-correlation function from Dumoulin 2003

Parameters

pad (int) – padding with mean data (default 1)

Returns

res_auto which the auto correlation function

Return type

image2d

Returns

Cinf see equation 6 Doumalin 2003

Return type

float

Returns

profil, it correspond to 180 profile taken for along line with direction between 0 and 180°. The profil[i,:] correspond to a line making an angle of i degree from x direction.

Return type

np.array 180*length profile

Returns

xi, it correspond to the distance along the profile for the variable profile

Return type

np.array 180*length profile

Returns

cross, it correspond to the length of the autocorrelation radius

Return type

np.array dim=180

Returns

data, it correspond to the true image use for the correlation

Return type

image2d

Exemple
>>> # Using a fake image
>>> data=image2d.image2d(np.eye(200),1)
>>> [res_auto,Cinf,profil,xi,cross,image]=data.auto_correlation(pad=2)
>>> # plot the auto correlation function
>>> res_auto.plot()
>>>plt.show()
>>> # plot the auto_correlation radius in function of the angle of the profile
>>> plt.plot(cross)
>>> plt.xlabel('angle degree')
>>> plt.ylabel('auto correlation radius (mm)')
>>> plt.show()
>>> # extract the max and min auto correlation radius
>>> id=np.where(cross==np.min(cross))
>>> minC=id[0][0]
>>> id=np.where(cross==np.max(cross))
>>> maxC=id[0][0]
>>> ss=np.shape(xi) 
>>> CC=np.ones(ss[1])*Cinf
>>> plt.figure()
>>> plt.plot(xi[0,:],CC)
>>> plt.hold('on')
>>> plt.plot(xi[minC,:],profil[minC,:])
>>> plt.plot(xi[maxC,:],profil[maxC,:])
>>> plt.show()
crop(pos)[source]
Parameters

pos (np.array) – numpy array (xmin,xmax,ymin,ymax)

diff(axis)[source]

Derive the image along the axis define

Parameters

axis (str) – ‘x’ to do du/dx or ‘y’ to do du/dy

Returns

differential of the map in respect to the ‘axis’ wanted

Return type

image2d

Warning

‘x’ axis is left to right and ‘y’ is bottom to top direction

extract_data(pos=[])[source]

Extract the value at the position ‘pos’ or where you clic

Parameters

pos (array) – array [x,y] position of the data, if pos==[], clic to select the pixel

extract_profil(pos=0)[source]

Extract data along a given profile

Parameters

pos (np.array dim 2*2) – correspond to the position of the line np.array([[X0,Y0],[X1,Y1]])

Returns

x

Return type

postion along the profile

Returns

out

Return type

value along the profile

Returns

pos

Return type

starting and ending points

imresize(res)[source]

Resize the image with nearest interpolation to have a pixel of the length given in res

Parameters

res (float) – new resolution map wanted (millimeters)

mask_build(polygone=False, r=0, grainId=[], pos_center=0)[source]

Create a mask map with NaN value where you don’t want data and one were you want The default mask is a circle of center you choose and radius you define.

Parameters
  • polygone (bool) – make a polygone mask (‘not yet implemented’)

  • r (float) – radius of the circle (warning what is the dimention of r mm ?)

  • grainId – You select the grainId you want in an array

Type

array

Returns

mask

Return type

image2d

Returns

vec (vector of grainId is selction by grain or pos_center if selection by circle or 0 if polygone )

Return type

array

Note

if you want applied a mask one your data just do data*mask where data is an image2d object

plot(vmin=nan, vmax=nan, colorbarcenter=False, colorbar=<matplotlib.colors.ListedColormap object>)[source]

plot the image2d

Parameters
  • vmin (float) – minimum value for the colorbar

  • vmax (float) – maximun value for the colorbar

  • colorbarcenter (bool) – do you want center the colorbar around 0

  • colorbar – colorbar from matplotlib.cm

Note

colorbar : cm.jet for eqstrain-stress

pow(nb)[source]

map power nb

Parameters

nb (float) –

save_bmp(name)[source]

Save image as bmp :param name: name of the file :type name: str

skeleton()[source]

Skeletonized a label map build by grain_label

triple_junction()[source]

Localized the triple junction

vtk_export(nameId)[source]

Export the image2d into vtk file :param nameId: name of the output file :type name: str

class AITAToolbox.image2d.mask2d(field, resolution)[source]

mask2d is a class which herit from image2d but it is restricted to microstructure object (background NaN, selected area 1)

__init__(field, resolution)[source]

Constructor : field is a matrix and resolution is the step size in mm

Parameters
  • field (array) – tabular of scalar data

  • resolution (float) – step size resolution (millimeters)

complementary()[source]

Return complementary mask

load_mask(res=1)[source]

Create a mask from a black and white bmp image where whith correspond to the selected area

Parameters
  • adr_bmp (str) – path of the mask bmp file

  • res (float) – resolution of the picture mm (default 1)

Return mask

Rtype mask

mask2d

class AITAToolbox.image2d.micro2d(field, resolution)[source]

micro2d is a class which herit from image2d but it is restricted to microstructure object (background 0, boundary 1)

__init__(field, resolution)[source]

Constructor : field is a matrix and resolution is the step size in mm

Parameters
  • field (array) – tabular of scalar data

  • resolution (float) – step size resolution (millimeters)

area()[source]

Compute the grain area for each grain

Returns

g_arean array of scalar of grain area in mm^2

Return type

g_area np.array

grain_label()[source]

Label area in a black and white picture

Note

black color for the background and white color for the boundary

plotBoundary(dilatation=0)[source]

Add boundary to the figure

Parameters

dilatation (int) – number of iteration for the dilation of 1 value - used this to make larger the boundaries (default 2)

Exemple
>>> data.phi1.plot()
>>> data.micro.plotBoundary(dilatation=10)
>>> plt.show()

Note

plot only the value of the pixel equal at 1