SMIL Survival Guide

Introduction

This document contains a short list of functions with a quick description.

Import SMIL library

In order to import SMIL library type the following command:

    from smilPython import *

or

    import smilPython as sp

If the second version is used, the suffix sp will be necessary when calling SMIL functions.

In order to run an existing script type:

    execfile(“myscript.py”)

I/O images

  • To read an image:
    im = Image(”images/toto.png”)
  • To write an image:
    write(im, ”filename.png”)
  • To create a new image based on the dimensions of a given image (but not to copy the contents):
    im2 = Image(im)
  • To create a new image based on the dimensions of a given image but with a different depth:
    im2 = Image(im, ”UINT16”)
  • To display an image:
    im.show()
  • To display an image in false colors:
    im.showLabel()

Pixel-based functions

  • To copy an image into another one:
    copy(im, im2)
  • To set the image to zero:
    im << 0
  • To invert the image
    inv(imIn, imOut)
  • To add a constant (or an image):
    add(imIn, constant, imOut)
    add(imIn, image, imOut)
  • To substract a constant (or an image):
    sub(imIn, constant, imOut)
    sub(imIn, image, imOut)
  • Returns the maximum value of im:
    maxVal(im)
  • Returns the maximum value of im:
    minVal(im)
  • To compare an image to a constant or another image:
    compare(imIn, condition, a, b, c, imOut)

a, b and c can be images or scalars. imIn is compared to a according to the given condition. If result is true, parameter b is set in imOut. Otherwise the corresponding imOut pixel is set to c. For example

    compare(im1, ”>”, im2, im1, im2, imomut)

is equivalent to

    sup(im1, im2, imOut)
  • To compute the sup of two images:
    sup(im1, im2, imOut)
  • To compute the inf of two images:
    inf(im1, im2, imOut)
  • Threshold:
    threshold(im, minval, maxval, trueval, falseval, imOut)
  • Otsu threshold :
    threshold(im, imOut)
  • Scale : if im has the size (W, H), the size of imOut will be (W * x, H * y). (imOut should be allocated first).
    imOut = Image()
    scale(im, x, y, imOut)

Structuring elements

Already defined structuring elements

Default structuring element

If not specified, default SE is used in most morphological functions. As an optional parameter, SE is usualy the last one. Ex :

    erode(imIn, imOut)
    erode(imIn, imOut, CrossSE())
    erode(imIn, imOut, CrossSE(size))

Modify default SE

  • Get Default SE:
    print Morpho.getDefaultSE().

If not modified, HexSE() is used by default.

  • Set default SE to CrossSE():
    Morpho.setDefaultSE(CrossSE())

Define other SEs

Construct a structuring element with points defined by their indexes: StrElt(HexFlag, PointList) : For example, HorizSE() can be defined this way :

    mySE1 = StrElt(False, (0, 1, 5))

Morphological Erosion, Dilation, Opening, Closing

If not specified, default SE is used in most morphological functions. As an optional parameter, SE is usualy the last one.

  • Erosion with default SE:
    erode(im, imOut)
  • Erosion with other SE:
    erode(im, imOut, CrossSE())
  • Erosion with an homothetic SE:
    erode(im, imOut[, CrossSE(size)])
  • Dilation (idem for optional SE).
    dilate(im, imOut[, CrossSE(size)])
  • Morphological opening (idem for optional SE).
    open(im, imOut[, CrossSE(size)])
  • Morphological closing (idem for optional SE).
    close(im, imOut[, CrossSE(size)])

Reconstruction

  • Reconstruction by dilation
    build(imMark, imRef, imOut[, nl])
  • Reconstruction by erosion
    dualBuild(imMark, imRef, imOut[, nl])
  • hBuild: reconstruct by dilation from f-h:
    hBuild(im, h, imOut[, nl])
  • hDualBuild: reconstruct by erosion from f+h:
    hDualBuild(im, h, imOut[, nl])
  • hMaxima: regional maxima after hBuild (reconstruction from f-h),
    hMaxima(im, h, imMax[, nl])
  • hMinima: regional minima after hDualBuild (reconstruction from f+h),
    hMinima(im, h, imMin[, nl])
  • hMaxima: regional maxima after razing function f constrained by f-h,
    hMaxima(im, h, imMax[, nl])
  • hMinima: regional minima after flooding function f constrained by f+h,
    hMinima(im, h, imMin[, nl])

Filtering

Opening and closing are also morphological filter. Other filters are given in this section:

  • Alternate filter: an opening of size size followed by a closing of the same size.
    AF(im, size, imOut[, nl])
  • Alternate sequential filter: φ size γ size …φ 2 γ 2 φ 1 γ 1 (im)
    ASF(im, size, imOut[, nl])
  • Opening by reconstruction: erosion of size size followed by reconstruction (by dilation):
    buildOpen(imIn, imOut, se(size))
  • Closing by reconstruction: dilation of size size followed by reconstruction (by erosion):
    buildClose(imIn, imOut, se(size))
  • Alternate filter combining buildOpen and buildClose of a give size:
    buildAF(imIn, imOut, se(size))
  • Alternate sequential filter combining buildOpen and buildClose of increasing sizes (up to size size:
    buildASF(imIn, imOut, se(size))
  • AreaOpen:
    areaOpen(imIn, size, imOut)
  • Alternate levelings:
    ASF_Leveling(imIn, size, imOut, nl)

Connexity oriented functions

  • Regional minima of imIn :
    minima(imIn, imOut[, nl])
  • Regional maxima of imIn:
    maxima(imIn, imOut[, nl])
  • Assign a different label (identifier) to each connected component.
    label(im, imLabel[, nl])

Segmentation

  • To compute the gradient:
    gradient(im, imGrad[, nl])
  • Watershed of imGrad into imWs:
    watershed(imGrad, imWs[, nl])
  • Watershed of imGrad from markers imMark into imWs. Note: each marker should be identified with a different label.
    watershed(imGrad, imMark, imWs[, nl])
  • Watershed of imGrad from markers imMark. Two output parameters imWs with the watershed line and imBasins the labelled mosaic without the watershed line:
    watershed(imGrad, imMark, imWs, imBasins[, nl])
  • Basins (labelled mosaic without watershed line) of imGrad:
    basins(imGrad, imBasins[, nl])
  • Basins (labelled mosaic without watershed line) of imGrad from markers imMark:
    basins(imGrad, imMark, imBasins[, nl])
  • Hierarchical segmentation based on extinction values: imGrad is flooded and the computed extinction value is assigned to the minima in imEV image. extinction type can be “d”, ”a” or ”v” for dynamics, area or volume respectively.
    watershedExtinction(imGrad, imEV, extinction type [, nl])
  • A waterfall iteration of imGrad from imWs0:
    waterfall(imGrad, imWs0, imGrad, imWs1[, nl])
  • Iteration of waterfall, level times:
    waterfall(imGrad, level, imWf[, nl])
  • Extinction values based hierarchical segmentation:
    imFineSeg, MST = watershedEV(imGrad, EVType[, nl])
  • Get a partition imSeg with Nregions from the hierarchy stored in MST graph:
    getEVLevel(imFineSeg, MST, Nregions, imSeg)

Color

  • Extract channels from a color image:
    im1, im2, im3 = extractChannels(colorIm)
  • Combine channels into a color image:
    colorOut = combineChannels(im1, im2, im3)
  • Get luminance:
    im8 = Image(colorIm, ”UINT8”)
    RGBToLuminance(colorIm, im8)
  • Color conversions:
    colorIm2 = Image(colorIm)
    RGBToXYZ(colorIm, colorIm2)
    RGBToLAB(colorIm, colorIm2)
    RGBToHLS(colorIm, colorIm2)
  • Color gradients:
    imgraLAB = gradient_LAB(colorIm, nl)
    imgraHLS = gradient_HLS(colorIm, nl)
doc/python/survival.txt · Last modified: 2019/01/28 12:26 (external edit)
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0