Differences

This shows you the differences between two versions of the page.

Link to this comparison view

doc:python:survival [2019/01/28 12:26] (current)
Line 1: Line 1:
 +====== SMIL Survival Guide ======
 +
 +===== Introduction =====
 +
 +This document contains a short list of functions with a quick description.
 +
 +<​note>​
 +  * The complete documentation can be found at [[http://​smil.cmm.mines-paristech.fr/​doc/​modules.html]];​
 +  * A ''//​pdf//''​ version of this document is available at : [[http://​smil.cmm.mines-paristech.fr/​publis/​survival_kit_doc.pdf|survival_kit_doc.pdf]]
 +  * Optional parameters are between square brackets [optional].
 +</​note>​
 +===== Import SMIL library =====
 +
 +In order to import SMIL library type the following command:
 +
 +<code python>
 +    from smilPython import *
 +</​code>​
 +or
 +<code python>
 +    import smilPython as sp
 +</​code>​
 +If the second version is used, the suffix **''​sp''​** will be necessary when calling SMIL functions.
 +
 +In order to run an existing script type:
 +<code python>
 +    execfile(“myscript.py”)
 +</​code>​
 +
 +===== I/O images =====
 +
 +  * To read an image:
 +<code python>
 +    im = Image(”images/​toto.png”)
 +</​code>​
 +  * To write an image:
 +<code python>
 +    write(im, ”filename.png”)
 +</​code>​
 +  * To create a new image based on the dimensions of a given image (but not to copy the contents):
 +<code python>
 +    im2 = Image(im)
 +</​code>​
 +  * To create a new image based on the dimensions of a given image but with a different depth:
 +<code python>
 +    im2 = Image(im, ”UINT16”)
 +</​code>​
 +  * To display an image:
 +<code python>
 +    im.show()
 +</​code>​
 +  * To display an image in false colors:
 +<code python>
 +    im.showLabel()
 +</​code>​
 +
 +===== Pixel-based functions =====
 +
 +  * To copy an image into another one:
 +<code python>
 +    copy(im, im2)
 +</​code>​
 +  * To set the image to zero:
 +<code python>
 +    im << 0
 +</​code>​
 +  * To invert the image
 +<code python>
 +    inv(imIn, imOut)
 +</​code>​
 +  * To add a constant (or an image):
 +<code python>
 +    add(imIn, constant, imOut)
 +    add(imIn, image, imOut)
 +</​code>​
 +  * To substract a constant (or an image):
 +<code python>
 +    sub(imIn, constant, imOut)
 +    sub(imIn, image, imOut)
 +</​code>​
 +  * Returns the maximum value of im:
 +<code python>
 +    maxVal(im)
 +</​code>​
 +  * Returns the maximum value of im:
 +<code python>
 +    minVal(im)
 +</​code>​
 +  * To compare an image to a constant or another image:
 +<code python>
 +    compare(imIn,​ condition, a, b, c, imOut)
 +</​code>​
 +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
 +<code python>
 +    compare(im1,​ ”>”, im2, im1, im2, imomut)
 +</​code>​
 +is equivalent to 
 +<code python>
 +    sup(im1, im2, imOut)
 +</​code>​
 +  * To compute the sup of two images:
 +<code python>
 +    sup(im1, im2, imOut)
 +</​code>​
 +  * To compute the inf of two images:
 +<code python>
 +    inf(im1, im2, imOut)
 +</​code>​
 +  * Threshold:
 +<code python>
 +    threshold(im,​ minval, maxval, trueval, falseval, imOut)
 +</​code>​
 +  * Otsu threshold :
 +<code python>
 +    threshold(im,​ imOut)
 +</​code>​
 +  * Scale : if im has the size **''​(W,​ H)''​**,​ the size of **''​imOut''​** will be **''​(W * x, H * y)''​**. (**''​imOut''​** should be allocated first).
 +<code python>
 +    imOut = Image()
 +    scale(im, x, y, imOut)
 +</​code>​
 +
 +===== Structuring elements =====
 +
 +==== Already defined structuring elements ====
 +
 +{{ :​doc:​structuringelements.png?​640 |}}
 +
 +
 +==== 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 :
 +<code python>
 +    erode(imIn, imOut)
 +    erode(imIn, imOut, CrossSE())
 +    erode(imIn, imOut, CrossSE(size))
 +</​code>​
 +
 +==== Modify default SE ====
 +
 +  * Get Default SE: 
 +<code python>
 +    print Morpho.getDefaultSE().
 +</​code>​
 +If not modified, HexSE() is used by default.
 +  * Set default SE to **''​CrossSE()''​**:​
 +<code python>
 +    Morpho.setDefaultSE(CrossSE())
 +</​code>​
 +
 +==== Define other SEs ====
 +
 +
 +Construct a structuring element with points defined by their indexes: ''​StrElt(HexFlag,​ PointList)''​ :
 +For example, <​nowiki>​HorizSE()</​nowiki>​ can be defined this way :
 +<code python>
 +    mySE1 = StrElt(False,​ (0, 1, 5))
 +</​code>​
 +
 +{{ :​doc:​structuringelements-2.png?​400 |}}
 +
 +===== 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:
 +<code python>
 +    erode(im, imOut)
 +</​code>​
 +  * Erosion with other SE:
 +<code python>
 +    erode(im, imOut, CrossSE())
 +</​code>​
 +  * Erosion with an homothetic SE:
 +<code python>
 +    erode(im, imOut[, CrossSE(size)])
 +</​code>​
 +  * Dilation (idem for optional SE).
 +<code python>
 +    dilate(im, imOut[, CrossSE(size)])
 +</​code>​
 +  * Morphological opening (idem for optional SE).
 +<code python>
 +    open(im, imOut[, CrossSE(size)])
 +</​code>​
 +  * Morphological closing (idem for optional SE).
 +<code python>
 +    close(im, imOut[, CrossSE(size)])
 +</​code>​
 +
 +===== Reconstruction =====
 +
 +  * Reconstruction by dilation
 +<code python>
 +    build(imMark,​ imRef, imOut[, nl])
 +</​code>​
 +  * Reconstruction by erosion
 +<code python>
 +    dualBuild(imMark,​ imRef, imOut[, nl])
 +</​code>​
 +  * hBuild: reconstruct by dilation from **''​f-h''​**:​
 +<code python>
 +    hBuild(im, h, imOut[, nl])
 +</​code>​
 +  * hDualBuild: reconstruct by erosion from **''​f+h''​**:​
 +<code python>
 +    hDualBuild(im,​ h, imOut[, nl])
 +</​code>​
 +  * hMaxima: regional maxima after hBuild (reconstruction from **''​f-h''​**),​
 +<code python>
 +    hMaxima(im, h, imMax[, nl])
 +</​code>​
 +  * hMinima: regional minima after hDualBuild (reconstruction from **''​f+h''​**),​
 +<code python>
 +    hMinima(im, h, imMin[, nl])
 +</​code>​
 +  * hMaxima: regional maxima after razing function **''​f''​** constrained by **''​f-h''​**,​
 +<code python>
 +    hMaxima(im, h, imMax[, nl])
 +</​code>​
 +  * hMinima: regional minima after flooding function **''​f''​** constrained by **''​f+h''​**,​
 +<code python>
 +    hMinima(im, h, imMin[, nl])
 +</​code>​
 +
 +===== 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.
 +<code python>
 +    AF(im, size, imOut[, nl])
 +</​code>​
 +  * Alternate sequential filter: φ size γ size ...φ 2 γ 2 φ 1 γ 1 (im)
 +<code python>
 +    ASF(im, size, imOut[, nl])
 +</​code>​
 +  * Opening by reconstruction:​ erosion of size size followed by reconstruction (by dilation):
 +<code python>
 +    buildOpen(imIn,​ imOut, se(size))
 +</​code>​
 +  * Closing by reconstruction:​ dilation of size size followed by reconstruction (by erosion):
 +<code python>
 +    buildClose(imIn,​ imOut, se(size))
 +</​code>​
 +  * Alternate filter combining buildOpen and buildClose of a give size:
 +<code python>
 +    buildAF(imIn,​ imOut, se(size))
 +</​code>​
 +  * Alternate sequential filter combining buildOpen and buildClose of increasing sizes (up to size size:
 +<code python>
 +    buildASF(imIn,​ imOut, se(size))
 +</​code>​
 +  * AreaOpen:
 +<code python>
 +    areaOpen(imIn,​ size, imOut)
 +</​code>​
 +  * Alternate levelings:
 +<code python>
 +    ASF_Leveling(imIn,​ size, imOut, nl)
 +</​code>​
 +
 +===== Connexity oriented functions =====
 +
 +  * Regional minima of imIn :
 +<code python>
 +    minima(imIn,​ imOut[, nl])
 +</​code>​
 +  * Regional maxima of imIn:
 +<code python>
 +    maxima(imIn,​ imOut[, nl])
 +</​code>​
 +  * Assign a different label (identifier) to each connected component.
 +<code python>
 +    label(im, imLabel[, nl])
 +</​code>​
 +
 +===== Segmentation =====
 +
 +  * To compute the gradient:
 +<code python>
 +    gradient(im,​ imGrad[, nl])
 +</​code>​
 +  * Watershed of imGrad into imWs:
 +<code python>
 +    watershed(imGrad,​ imWs[, nl])
 +</​code>​
 +  * Watershed of imGrad from markers imMark into imWs. Note: each marker should be identified with a different label.
 +<code python>
 +    watershed(imGrad,​ imMark, imWs[, nl])
 +</​code>​
 +  * Watershed of imGrad from markers imMark. Two output parameters imWs with the watershed line and imBasins the labelled mosaic without the watershed line:
 +<code python>
 +    watershed(imGrad,​ imMark, imWs, imBasins[, nl])
 +</​code>​
 +  * Basins (labelled mosaic without watershed line) of imGrad:
 +<code python>
 +    basins(imGrad,​ imBasins[, nl])
 +</​code>​
 +  * Basins (labelled mosaic without watershed line) of imGrad from markers imMark:
 +<code python>
 +    basins(imGrad,​ imMark, imBasins[, nl])
 +</​code>​
 +  * 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.
 +<code python>
 +    watershedExtinction(imGrad,​ imEV, extinction type [, nl])
 +</​code>​
 +  * A waterfall iteration of imGrad from imWs0:
 +<code python>
 +    waterfall(imGrad,​ imWs0, imGrad, imWs1[, nl])
 +</​code>​
 +  * Iteration of waterfall, level times:
 +<code python>
 +    waterfall(imGrad,​ level, imWf[, nl])
 +</​code>​
 +  * Extinction values based hierarchical segmentation:​
 +<code python>
 +    imFineSeg, MST = watershedEV(imGrad,​ EVType[, nl])
 +</​code>​
 +  * Get a partition imSeg with Nregions from the hierarchy stored in MST graph:
 +<code python>
 +    getEVLevel(imFineSeg,​ MST, Nregions, imSeg)
 +</​code>​
 +
 +===== Color =====
 +
 +  * Extract channels from a color image:
 +<code python>
 +    im1, im2, im3 = extractChannels(colorIm)
 +</​code>​
 +  * Combine channels into a color image:
 +<code python>
 +    colorOut = combineChannels(im1,​ im2, im3)
 +</​code>​
 +  * Get luminance:
 +<code python>
 +    im8 = Image(colorIm,​ ”UINT8”)
 +    RGBToLuminance(colorIm,​ im8)
 +</​code>​
 +  * Color conversions:​
 +<code python>
 +    colorIm2 = Image(colorIm)
 +    RGBToXYZ(colorIm,​ colorIm2)
 +    RGBToLAB(colorIm,​ colorIm2)
 +    RGBToHLS(colorIm,​ colorIm2)
 +</​code>​
 +  * Color gradients:
 +<code python>
 +    imgraLAB = gradient_LAB(colorIm,​ nl)
 +    imgraHLS = gradient_HLS(colorIm,​ nl)
 +</​code>​
 +
  
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