Tif Library

Class to allow for Zeiss/FEI-ThermoFischer TIF image loading and enhancing using python

  • Unit: all sizes are in um: pixel-size, image-width

  • All images have an image, pixelsize, width, height

class micromechanics.tif.Tif(fileName, fileType=None, pixelSize=1)

Bases: object

Tif class to read SEM images

__init__(fileName, fileType=None, pixelSize=1)

Read input file, initialize things

Parameters:
  • fileName (str) – file name in the present directory

  • fileType (str) – type of Tif file (“Zeiss”, “NPVE”, “Void”, “NoQuestion”)
    if no type is given, the type will be identified (which takes time)
    NoQuestion does not ask for non-Zeiss,NPVE file type

  • pixelSize (float) – pixel size for conventional tif-files

addScaleBar(site='BL', length=None, scale=-1)

Add scale-bar to image

Parameters:
  • site (str) – where to put the scale bar: bottom-left “BL”, bottom-right “BR”, top-left “TL”, top-right “TR”, bottom “B”

  • length (float) – length of scale bar in um; if not give calculate automatically

  • scale (int) – of font and rectangle. Default: widthInPixel / 16, which is for a 1024x786 image = 64

autoCrop(color='w')

Automatically crop the bottom bar from the image. The top line cropped is the line that only contains white/black pixel

Parameters:

color (str) – color to crop black=b, white=w

contrast(magnitude=1, offset=0.5, yoffset=1.0, save=False, plot=False, points=31)

Manual contrast improvement: fast but memory expensive

Parameters:
  • magnitude (float) – curve curvature image: figZeiss1.png

  • offset (float) – move neutral point up-down diagonal image: figZeiss2.png

  • yoffset (float) – move neutral point up-down image: figZeiss3.png

  • save (bool) – save resulting contrast change

  • plot (bool) – plot the desired curve on the screen, no contrast changes are performed to the image.|br| this is to verify ones choice

  • points (int) – smoothness of curve, the more the smoother

crop(xMin=-1, xMax=-1, yMin=-1, yMax=-1)

Crop image: set those that you want to crop, unset ones are not altered

Parameters:
  • xMin (int) – minimum x-value that should be cut away

  • xMax (int) – maximum x-value that should be cut away

  • yMin (int) – minimum y-value that should be cut away

  • yMax (int) – maximum y-value that should be cut away

enhance(method='rescale', percent=1)

Automatic contrast improvement
mode = 1 black-white
mode = L grey-scale
read http://scikit-image.org/docs/0.9.x/auto_examples/plot_equalize.html for details

Parameters:
  • method (str) –

    • ‘rescale’ or ‘r’: Automatic gray-value rescaling, default, smallest change

    • ’adaptive’ or ‘a’: Gray equalization, leads to centered Gaussian curve, medium change, favorite

    • ’equalization’ or ‘e’: Gray equalization, leads to cumulative histogram that is a line largest change

  • percent (int) – percent (default: 0) to allow for clipping at the top and at the bottom (e.g. top 1% of values become white and bottom 1% of values become black

findScaleBar(length=None)

Find the optimal scale-bar, if no length is given

Parameters:

length (float) – length of scale bar in um, only integer values are used

flip()

flip image vertically

gaussFilter(level=1, recursive=1)

Use gaussian filter (smooth pixels, much more smoothing than median)

Parameters:
  • level (int) – radius of gauss filter in pixel

  • recursive (int) – subsequent iterations of filter, default=1=no recursive

gaussLevel(level=100, plot=True, save=False)

excenturate and remove gradients

Parameters:
  • level (int) – radius used for leveling

  • plot (bool) – plot graphs during processing

  • save (bool) – only save once set true; allows to test varios settings before saving

hist(log=False, show=True)

Show grey-scale histogram and cumulative histogram

Parameters:
  • log (bool) – use a logarithmic scale on the y-scale

  • show (bool) – show figure

initConventional(pixelSize=1)

Init conventional file

Parameters:

pixelSize (float) – pixel size in um

initFEI()

Init FEI / ThermoFischer file

initNPVE()

Init NPVE file, no original image saved since files are large

initZeiss()

Init ZEISS file

medianFilter(level=1, recursive=1)

Use median filter (remove single pixel noise)

Parameters:
  • level (int) – radius of median filter in pixel, the larger the slower the algorithm

  • recursive (int) – subsequent iterations of filter, default=1=no recursive

plot(axis='on')

Show image on screen by plotting it: showing the pixel coordinates, which is handy for cropping

Parameters:

axis (str) – ‘on’,’off’ show axis

removeGrayGradient(save=False, plot=True)

remove gradient that may occur in cross sections

Parameters:
  • save (bool) – only save once set true; allows to test varios settings before saving

  • plot (bool) – plot graphs during processing

reset()

Reset it if you want to restart after making unwanted change

rotate180()

rotate image by 180 degrees

rotateCCW()

rotate image counter clock-wise

rotateCW()

rotate image clock-wise

save(fileType='jpg', scale=None, convertGrayscale=True)

Save file as jpg, use the same base as initial TIF image

Parameters:
  • fileType (str) – jpg, other options eps, png
    alternative is to enter full filename (must be longer than 4 characters)

  • scale (float) – scale down image by ratio

  • convertGrayscale (bool) – convert to gray-scale image

scale(scaleFactor=1)

Scale image by a factor. Scale by factor two decreases the pixelSize and increases the image size by factor two

Parameters:

scaleFactor (float) – scaling factor

setData(image, pixelSize, copy=True)

import data, image and pixelSize from another source
(image, pixelSize): image and pixelSize in a list

Parameters:
  • image (PIL) – image

  • pixelSize (float) – pixelSize

  • copy (bool) – create backup copy. Don’t do if big file

show()

Show image on screen

topology(axis='V', upperEnd=4.0, start=-1, end=-1)

EXPERIMENTAL: rescale grey values such that each row/collum has the same average, cancel topological shadowing

The algorithm tries to scale (change contrast) the grey-values such as that each collum (V) or row (H) has the same average grey value. However:

  • It is not allowed to scaling down (<1) [because that deletes contrast]

  • or scale more than upperEnd [because then the image becomes to pixely]

To still reach the given average: the grey scales are shifted (change brightness)

Parameters:
  • axis (str) – “V” vertical or “H” horizontal

  • upperEnd (float) – maximum scaling allowed

  • start (int) – start scaling only in row/collum. default=-1=scale everything

  • end (int) – end scaling in row/collum. default=-1=scale everything