PYMORPH: IMAGE MORPHOLOGY IN PYTHON

Contents: .. toctree:

:maxdepth: 2

Indices and tables

Module pymorph

pymorph a powerful collection of state-of-the-art gray-scale morphological tools that can be applied to image segmentation, non-linear filtering, pattern recognition and image analysis.

  • add4dilate() : Addition for dilation
  • addm() : Addition of two images, with saturation.
  • areaclose() : Area closing
  • areaopen() : Area opening
  • asf() : Alternating Sequential Filtering
  • asfrec() : Reconstructive Alternating Sequential Filtering
  • bench() : benchmarking main functions of the toolbox.
  • binary() : Convert a gray-scale image into a binary image
  • blob() : Blob measurements from a labeled image.
  • bshow() : Generate a graphical representation of overlaid binary images.
  • cbisector() : N-Conditional bisector.
  • cdilate() : Dilate an image conditionally.
  • center() : Center filter.
  • cerode() : Erode an image conditionally.
  • close_holes() : Close holes of binary and gray-scale images.
  • close() : Morphological closing.
  • closerec() : Closing by reconstruction.
  • closerecth() : Close-by-Reconstruction Top-Hat.
  • closeth() : Closing Top Hat.
  • concat() : Concatenate two or more images along width, height or depth.
  • cthick() : Image transformation by conditional thickening.
  • cthin() : Image transformation by conditional thinning.
  • cwatershed() : Detection of watershed from markers.
  • datatype() : Return the image datatype string
  • dilate() : Dilate an image by a structuring element.
  • dist() : Distance transform.
  • drawv() : Superpose points, rectangles and lines on an image.
  • edgeoff() : Eliminate the objects that hit the image frame.
  • endpoints() : Interval to detect end-points.
  • erode() : Erode an image by a structuring element.
  • flood() : Flooding filter- h,v,a-basin and dynamics (depth, area, volume)
  • frame() : Create a frame image.
  • freedom() : Control automatic data type conversion.
  • gdist() : Geodesic Distance Transform.
  • gradm() : Morphological gradient.
  • grain() : Gray-scale statistics for each labeled region.
  • gray() : Convert a binary image into a gray-scale image.
  • gshow() : Apply binary overlays as color layers on a binary or gray-scale image
  • histogram() : Find the histogram of the image f.
  • hmax() : Remove peaks with contrast less than h.
  • hmin() : Remove basins with contrast less than h.
  • homothick() : Interval for homotopic thickening.
  • homothin() : Interval for homotopic thinning.
  • img2se() : Create a structuring element from a pair of images.
  • infcanon() : Intersection of inf-generating operators.
  • infgen() : Inf-generating.
  • infrec() : Inf-reconstruction.
  • inpos() : Minima imposition.
  • interot() : Rotate an interval
  • intersec() : Intersection of images.
  • intershow() : Visualize an interval.
  • isbinary() : Check for binary image
  • isolines() : Apply an iso-line color table to a gray-scale image.
  • label() : Label a binary image.
  • labelflat() : Label the flat zones of gray-scale images.
  • lastero() : Last erosion.
  • lblshow() : Display a labeled image assigning a random color for each label.
  • limits() : Get the possible minimum and maximum of an image.
  • mat2set() : Converts image representation from matrix to set
  • maxleveltype() : Returns the maximum value associated to an image datatype
  • neg() : Negate an image.
  • open() : Morphological opening.
  • openrec() : Opening by reconstruction.
  • openrecth() : Open-by-Reconstruction Top-Hat.
  • openth() : Opening Top Hat.
  • opentransf() : Open transform.
  • pad4n() : pad4n
  • patspec() : Pattern spectrum (also known as granulometric size density).
  • plot() : Plot a function.
  • randomcolor() : Apply a random color table to a gray-scale image.
  • regmax() : Regional Maximum.
  • regmin() : Regional Minimum (with generalized dynamics).
  • se2hmt() : Create a Hit-or-Miss Template (or interval) from a pair of structuring elements.
  • se2interval() : Create an interval from a pair of structuring elements.
  • sebox() : Create a box structuring element.
  • secross() : Diamond structuring element and elementary 3x3 cross.
  • sedilate() : Dilate one structuring element by another
  • sedisk() : Create a disk or a semi-sphere structuring element.
  • seline() : Create a line structuring element.
  • sereflect() : Reflect a structuring element
  • serot() : Rotate a structuring element.
  • seshow() : Display a structuring element as an image.
  • sesum() : N-1 iterative Minkowski additions
  • set2mat() : Converts image representation from set to matrix
  • setrans() : Translate a structuring element
  • seunion() : Union of structuring elements
  • skelm() : Morphological skeleton (Medial Axis Transform).
  • skelmrec() : Morphological skeleton reconstruction (Inverse Medial Axis Transform).
  • skiz() : Skeleton of Influence Zone - also know as Generalized Voronoi Diagram
  • subm() : Subtraction of two images, with saturation.
  • supcanon() : Union of sup-generating or hit-miss operators.
  • supgen() : Sup-generating (hit-miss).
  • suprec() : Sup-reconstruction.
  • swatershed() : Detection of similarity-based watershed from markers.
  • symdif() : Symmetric difference between two images
  • text() : Create a binary image of a text.
  • thick() : Image transformation by thickening.
  • thin() : Image transformation by thinning.
  • threshad() : Threshold (adaptive)
  • toggle() : Image contrast enhancement or classification by the toggle operator.
  • union() : Union of images.
  • vmax() : Remove domes with volume less than v.
  • watershed() : Watershed detection.
  • to_int32() : Convert an image to an int32 image.
  • to_uint16() : Convert an image to a uint16 image.
  • to_uint8() : Convert an image to an uint8 image.
pymorph.add4dilate(f, c)
  • Purpose

    Addition for dilation

  • Synopsis

    a = add4dilate(f, c)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. Image c: Gray-scale (uint8 or uint16) or binary image. Constant

  • Output

    a: Image f + c

pymorph.addm(f1, f2)
  • Purpose

    Addition of two images, with saturation.

  • Synopsis

    y = addm(f1, f2)

  • Input
    f1: Unsigned gray-scale (uint8 or uint16), signed (int32) or

    binary image.

    f2: Unsigned gray-scale (uint8 or uint16), signed (int32) or

    binary image. Or constant.

  • Output
    y: Unsigned gray-scale (uint8 or uint16), signed (int32) or

    binary image.

  • Description

    addm creates the image y by pixelwise addition of images f1 and f2 . When the addition of the values of two pixels saturates the image data type considered, the greatest value of this type is taken as the result of the addition.

  • Examples

    # # example 1 # f = to_uint8([255, 255, 0, 10, 0, 255, 250]) g = to_uint8([ 0, 40, 80, 140, 250, 10, 30]) y1 = addm(f,g) print y1 y2 = addm(g, 100) print y2 # # example 2 # a = readgray(‘keyb.tif’) b = addm(a,128) show(a) show(b)

pymorph.areaclose(f, a, Bc=None)
  • Purpose

    Area closing

  • Synopsis

    y = areaclose(f, a, Bc=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. a: Double non negative integer. Bc: Structuring Element Default: None (3x3 elementary cross). (

    connectivity).

  • Output

    y: Same type of f

  • Description

    areaclose removes any pore (i.e., background connected component) with area less than a of a binary image f . The connectivity is given by the structuring element Bc . This operator is generalized to gray-scale images by applying the binary operator successively on slices of f taken from higher threshold levels to lower threshold levels.

  • Examples

    # # example 1 # a=readgray(‘form-1.tif’) b=areaclose(a,400) show(a) show(b) # # example 2 # a=readgray(‘n2538.tif’) b=areaclose(a,400) show(a) show(b)

pymorph.areaopen(f, a, Bc=None)
  • Purpose

    Area opening

  • Synopsis

    y = areaopen(f, a, Bc=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. a: Double non negative integer. Bc: Structuring Element Default: None (3x3 elementary cross). (

    connectivity).

  • Output

    y: Same type of f

  • Description

    areaopen removes any grain (i.e., connected component) with area less than a of a binary image f . The connectivity is given by the structuring element Bc . This operator is generalized to gray-scale images by applying the binary operator successively on slices of f taken from higher threshold levels to lower threshold levels.

  • Examples

    # # example 1 # f=binary(to_uint8([

    [1, 1, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1], [0, 0, 0, 0, 1, 0, 0]]))

    y=areaopen(f,4,secross()) print y # # example 2 # f=to_uint8([

    [10, 11, 0, 0, 0, 0, 20], [10, 0, 5, 8, 9, 0, 15], [10, 0, 0, 0, 10, 0, 0]])

    y=areaopen(f,4,secross()) print y # # example 3 # a=readgray(‘form-1.tif’); b=areaopen(a,500); show(a); show(b); # # example 4 # a=readgray(‘bloodcells.tif’); b=areaopen(a,500); show(a); show(b);

pymorph.asf(f, SEQ='OC', b=None, n=1)
  • Purpose

    Alternating Sequential Filtering

  • Synopsis

    y = asf(f, SEQ=”OC”, b=None, n=1)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. SEQ: String Default: “OC”. ‘OC’, ‘CO’, ‘OCO’, ‘COC’. b: Structuring Element Default: None (3x3 elementary cross). n: Non-negative integer. Default: 1. (number of iterations).

  • Output

    y: Image

  • Description

    asf creates the image y by filtering the image f by n iterations of the close and open alternating sequential filter characterized by the structuring element b . The sequence of opening and closing is controlled by the parameter SEQ . ‘OC’ performs opening after closing, ‘CO’ performs closing after opening, ‘OCO’ performs opening after closing after opening, and ‘COC’ performs closing after opening after closing.

  • Examples

    # # example 1 # f=readgray(‘gear.tif’) g=asf(f,’oc’,secross(),2) show(f) show(g) # # example 2 # f=readgray(‘fabric.tif’) g=asf(f,’oc’,secross(),3) show(f) show(g)

pymorph.asfrec(f, SEQ='OC', b=None, bc=None, n=1)
  • Purpose

    Reconstructive Alternating Sequential Filtering

  • Synopsis

    y = asfrec(f, SEQ=”OC”, b=None, bc=None, n=1)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. SEQ: String Default: “OC”. Values: “OC” or “CO”. b: Structuring Element Default: None (3x3 elementary cross). bc: Structuring Element Default: None (3x3 elementary cross). n: Non-negative integer. Default: 1. (number of iterations).

  • Output

    y: Same type of f

  • Description

    asf creates the image y by filtering the image f by n iterations of the close by reconstruction and open by reconstruction alternating sequential filter characterized by the structuring element b . The structure element bc is used in the reconstruction. The sequence of opening and closing is controlled by the parameter SEQ . ‘OC’ performs opening after closing, and ‘CO’ performs closing after opening.

  • Examples

    # f=readgray(‘fabric.tif’) g=asfrec(f,’oc’,secross(),secross(),3) show(f) show(g)

pymorph.bench(count=10)
  • Purpose

    benchmarking main functions of the toolbox.

  • Synopsis

    bench(count=10)

  • Input
    count: Double Default: 10. Number of repetitions of each

    function.

  • Description

    bench measures the speed of many of SDC Morphology Toolbox functions in seconds. An illustrative example of the output of bench is, for a MS-Windows 2000 Pentium 4, 2.4GHz, 533MHz system bus, machine: SDC Morphology Toolbox V1.2 27Sep02 Benchmark Made on Wed Jul 16 15:33:17 2003 computer= win32 image filename= csample.jpg width= 640 , height= 480 Function time (sec.) 1. Union bin 0.00939999818802 2. Union gray-scale 0.00319999456406 3. Dilation bin, secross 0.0110000014305 4. Dilation gray, secross 0.00780000686646 5. Dilation gray, non-flat 3x3 SE 0.0125 6. Open bin, secross 0.0125 7. Open gray-scale, secross 0.0141000032425 8. Open gray, non-flat 3x3 SE 0.0235000014305 9. Distance secross 0.021899998188 10. Distance Euclidean 0.0264999985695 11. Geodesic distance secross 0.028100001812 12. Geodesic distance Euclidean 0.303100001812 13. Area open bin 0.0639999985695 14. Area open gray-scale 0.148500001431 15. Label secross 0.071899998188 16. Regional maximum, secross 0.043700003624 17. Open by rec, gray, secross 0.0515000104904 18. ASF by rec, oc, secross, 1 0.090600001812 19. Gradient, gray-scale, secross 0.0171999931335 20. Thinning 0.0984999895096 21. Watershed 0.268799996376 Average 0.0632523809161

pymorph.binary(f, k=1)
  • Purpose

    Convert a gray-scale image into a binary image

  • Synopsis

    y = binary(f, k1=1)

  • Input
    f: Unsigned gray-scale (uint8 or uint16), signed (int32) or

    binary image.

    k1: Double Default: 1. Threshold value.

  • Output

    y: Binary image.

  • Description

    binary converts a gray-scale image f into a binary image y by a threshold rule. A pixel in y has the value 1 if and only if the corresponding pixel in f has a value greater or equal k1 .

  • Examples

    # # example 1 # a = array([0, 1, 2, 3, 4]) b=binary(a) print b # # example 2 # a=readgray(‘3.tif’) b=binary(a,82) show(a) show(b)

pymorph.blob(fr, measurement, option='image')
  • Purpose

    Blob measurements from a labeled image.

  • Synopsis

    y = blob(fr, measurement, option=”image”)

  • Input

    fr: Gray-scale (uint8 or uint16) image. Labeled image. measurement: String Default: “”. Choice from ‘AREA’, ‘CENTROID’,

    or ‘BOUNDINGBOX’.

    option: String Default: “image”. Output format: ‘image’:

    results as a binary image; ‘data’: results a column vector of measurements (double).

  • Output

    y: Gray-scale (uint8 or uint16) or binary image.

  • Description

    Take measurements from the labeled image fr. The measurements are:

    area, centroid, bounding rectangle.

    The parameter option controls the output format:

    ‘IMAGE’: the result is an image; ‘DATA’: the result is a double column vector with the measurement for each blob.

    The region with label zero is not measured as it is normally the background. The measurement of region with label 1 appears at the first row of the output.

  • Examples

    # # example 1 # fr=to_uint8([

    [1,1,1,0,0,0], [1,1,1,0,0,2], [1,1,1,0,2,2]])

    f_area=blob(fr,’area’) print f_area f_cent=blob(fr,’centroid’) print f_cent f_bb=blob(fr,’boundingbox’) print f_bb d_area=blob(fr,’area’,’data’) print d_area d_cent=blob(fr,’centroid’,’data’) print d_cent d_bb=blob(fr,’boundingbox’,’data’) print d_bb # # example 2 # f=readgray(‘blob3.tif’) fr=label(f) g=blob(fr,’area’) show(f) show(g) # # example 3 # f=readgray(‘blob3.tif’) fr=label(f) centr=blob(fr,’centroid’) show(f,dilate(centr)) # # example 4 # f=readgray(‘blob3.tif’) fr=label(f) box=blob(fr,’boundingbox’) show(f,box)

pymorph.bshow(f1, f2=None, f3=None, factor=17)

Generate a graphical representation of overlaid binary images.

Generate an expanded binary image as a graphical representation of up to three binary input images. The 1-pixels of the first image are represented by square contours, the pixels of the optional second image are represented by circles and for the third image they are represented by shaded squares. This function is useful to create graphical illustration of small images.

Parameters:

f1 : Binary image.

f2 : Binary image. Default: None.

f3 : Binary image. Default: None.

factor : Double Default: 17. Expansion factor for the output

image. Use odd values above 9.

Returns :

——- :

y : Binary image.

pymorph.cbisector(f, B, n)
  • Purpose

    N-Conditional bisector.

  • Synopsis

    y = cbisector(f, B, n)

  • Input

    f: Binary image. B: Structuring Element n: positive integer ( filtering rate)

  • Output

    y: Binary image.

  • Description

    cbisector creates the binary image y by performing a filtering of the morphological skeleton of the binary image f , relative to the structuring element B . The strength of this filtering is controlled by the parameter n. Particularly, if n=0 , y is the morphological skeleton of f itself.

  • Examples

    # a=readgray(‘blob2.tif’) b=cbisector(a,sebox(),1) c=cbisector(a,sebox(),3) d=cbisector(a,sebox(),10) show(a,b) show(a,c) show(a,d)

pymorph.cdilate(f, g, b=None, n=1)
  • Purpose

    Dilate an image conditionally.

  • Synopsis

    y = cdilate(f, g, b=None, n=1)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. g: Gray-scale (uint8 or uint16) or binary image. Conditioning

    image.

    b: Structuring Element Default: None (3x3 elementary cross). n: Non-negative integer. Default: 1. (number of iterations).

  • Output

    y: Image

  • Description

    cdil creates the image y by dilating the image f by the structuring element b conditionally to the image g . This operator may be applied recursively n times.

  • Examples

    # # example 1 # f = binary(to_uint8([[1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0,]])) g = binary(to_uint8([[1, 1, 1, 0, 0, 1, 1], [1, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 0, 0]])); y1=cdilate(f,g,secross()) y2=cdilate(f,g,secross(),3) # # example 2 # f = to_uint8([ [ 0, 0, 0, 80, 0, 0], [ 0, 0, 0, 0, 0, 0], [ 10, 10, 0, 255, 0, 0]]) g = to_uint8([ [ 0, 1, 2, 50, 4, 5], [ 2, 3, 4, 0, 0, 0], [ 12, 255, 14, 15, 16, 17]]) y1=cdilate(f,g,secross()) y2=cdilate(f,g,secross(),3) # # example 3 # g=readgray(‘pcb1bin.tif’) f=frame(g,5,5) y5=cdilate(f,g,secross(),5) y25=cdilate(f,g,secross(),25) show(g) show(g,f) show(g,y5) show(g,y25) # # example 4 # g=neg(readgray(‘n2538.tif’)) f=intersec(g,0) f=draw(f,’LINE:40,30,60,30:END’) y1=cdilate(f,g,sebox()) y30=cdilate(f,g,sebox(),30) show(g) show(f) show(y1) show(y30)

pymorph.center(f, b=None)

Center filter.

center() computes the morphological center of f w.r.t. to the structuring element b.

pymorph.cerode(f, g, b=None, n=1)
  • Purpose

    Erode an image conditionally.

  • Synopsis

    y = cerode(f, g, b=None, n=1)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. g: Gray-scale (uint8 or uint16) or binary image. Conditioning

    image.

    b: Structuring Element Default: None (3x3 elementary cross). n: Non-negative integer. Default: 1. (number of iterations).

  • Output

    y: Image

  • Description

    cero creates the image y by eroding the image f by the structuring element b conditionally to g . This operator may be applied recursively n times.

  • Examples

    # f = neg(text(‘hello’)) show(f) g = dilate(f,seline(7,90)) show(g) a1=cerode(g,f,sebox()) show(a1) a13=cerode(a1,f,sebox(),13) show(a13)

pymorph.close_holes(f, Bc=None)
  • Purpose

    Close holes of binary and gray-scale images.

  • Synopsis

    y = close_holes(f, Bc=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. Bc: Structuring Element Default: None (3x3 elementary cross). (

    connectivity).

  • Output

    y: (same datatype of f ).

  • Description

    close_holes creates the image y by closing the holes of the image f , according with the connectivity defined by the structuring element Bc .The images can be either binary or gray-scale.

  • Examples

    # # example 1 # a = readgray(‘pcb1bin.tif’) b = close_holes(a) show(a) show(b) # # example 2 # a = readgray(‘boxdrill-B.tif’) b = close_holes(a) show(a) show(b)

pymorph.close(f, b=None)
  • Purpose

    Morphological closing.

  • Synopsis

    y = close(f, b=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. b: Structuring Element Default: None (3x3 elementary cross).

  • Output

    y: Image

  • Description

    close creates the image y by the morphological closing of the image f by the structuring element b . In the binary case, the closing by a structuring element B may be interpreted as the intersection of all the binary images that contain the image f and have a hole equal to a translation of B . In the gray-scale case, there is a similar interpretation taking the functions umbra.

  • Examples

    # # example 1 # f=readgray(‘blob.tif’) bimg=readgray(‘blob1.tif’) b=img2se(bimg) show(f) show(close(f,b)) show(close(f,b),gradm(f)) # # example 2 # f = readgray(‘form-1.tif’) show(f) y = close(f,sedisk(4)) show(y) # # example 3 # f = readgray(‘n2538.tif’) show(f) y = close(f,sedisk(3)) show(y)

pymorph.closerec(f, bdil=None, bc=None)

Closing by reconstruction.

closerec() creates the image y by a sup-reconstruction (with the connectivity defined by the structuring element bc) of the image f from its dilation by bdil.

Parameters:

f : Gray-scale (uint8 or uint16) or binary image

bdil : Dilation structuring element (default 3x3 elementary cross)

bc : Connectivity structuring element (default: 3x3 elementary cross)

Returns:

y : Image (same type as f)

pymorph.closerecth(f, bdil=None, bc=None)
  • Purpose

    Close-by-Reconstruction Top-Hat.

  • Synopsis

    y = closerecth(f, bdil=None, bc=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. bdil: Structuring Element Default: None (3x3 elementary cross).

    (dilation)

    bc: Structuring Element Default: None (3x3 elementary cross).

    ( connectivity)

  • Output

    y: Gray-scale (uint8 or uint16) or binary image.

  • Description

    closerecth creates the image y by subtracting the image f of its closing by reconstruction, defined by the structuring elements bc and bdil .

  • Examples

    # a = readgray(‘danaus.tif’) show(a) b = closerecth(a,sebox(4)) show(b)

pymorph.closeth(f, b=None)
  • Purpose

    Closing Top Hat.

  • Synopsis

    y = closeth(f, b=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. b: Structuring Element Default: None (3x3 elementary cross).

  • Output
    y: Gray-scale (uint8 or uint16) or binary image. (Same type of f

    ).

  • Description

    closeth creates the image y by subtracting the image f of its morphological closing by the structuring element b .

  • Examples

    # a = readgray(‘danaus.tif’) show(a) b = closeth(a,sebox(5)) show(b)

pymorph.concat(dim, img0, img1, ...)

Concatenate two or more images along width, height or depth.

Concatenate two or more images in any of the dimensions: width, height or depth. If the images do not match the dimension, a larger image is create with zero pixels to accommodate them. The images must have the same datatype.

Parameters:

dim : Dimension to concatenate (string):

[‘width’, ‘height’, ‘depth’] or just the initial letter

img0, img1, ... : Images to concatenate

Returns:

img : resulting image (of the same type as inputs).

pymorph.cthick(f, g, Iab=None, n=-1, theta=45, DIRECTION='CLOCKWISE')
  • Purpose

    Image transformation by conditional thickening.

  • Synopsis

    y = cthick(f, g, Iab=None, n=-1, theta=45, DIRECTION=”CLOCKWISE”)

  • Input

    f: Binary image. g: Binary image. Iab: Interval Default: None (homothick). n: Non-negative integer. Default: -1. Number of

    iterations.

    theta: Double Default: 45. Degrees of rotation: 45, 90, or
    DIRECTION: String Default: “CLOCKWISE”. ‘CLOCKWISE’ or

    ‘ANTI-CLOCKWISE’.

  • Output

    y: Binary image.

  • Description

    cthick creates the binary image y by performing a thickening of the binary image f conditioned to the binary image g . The number of iterations of the conditional thickening is n and in each iteration the thickening is characterized by rotations of theta of the interval Iab .

  • Examples

    # # example 1 # f=readgray(‘blob2.tif’) show(f) t=se2hmt(binary([[0,0,0],[0,0,1],[1,1,1]]),

    binary([[0,0,0],[0,1,0],[0,0,0]]))

    print intershow(t) f1=thick(f,t,40); # The thickening makes the image border grow show(f1) # # example 2 # f2=cthick(f,neg(frame(f)),t,40) # conditioning to inner pixels fn=cthick(f,neg(frame(f)),t) #pseudo convex hull show(f2) show(fn,f)

pymorph.cthin(f, g, Iab=None, n=-1, theta=45, DIRECTION='CLOCKWISE')
  • Purpose

    Image transformation by conditional thinning.

  • Synopsis

    y = cthin(f, g, Iab=None, n=-1, theta=45, DIRECTION=”CLOCKWISE”)

  • Input

    f: Binary image. g: Binary image. Iab: Interval Default: None (homothin). n: Non-negative integer. Default: -1. Number of

    iterations.

    theta: Double Default: 45. Degrees of rotations: 45, 90, or
    DIRECTION: String Default: “CLOCKWISE”. ‘CLOCKWISE’ or ‘

    ANTI-CLOCKWISE’.

  • Output

    y: Binary image.

  • Description

    cthin creates the binary image y by performing a thinning of the binary image f conditioned to the binary image g . The number of iterations of the conditional thinning is n and in each iteration the thinning is characterized by rotations of theta of the interval Iab .

pymorph.cwatershed(f, markers, Bc=None, return_lines=False, is_gvoronoi=False)

R = cwatershed(f, g, Bc=None, return_lines=False) R,L = cwatershed(f, g, Bc=None, return_lines=True)

Detection of watershed from markers.
  • Input

    f: Gray-scale (uint8 or uint16) image. markers: Gray-scale (uint8 or uint16) or binary image. marker

    image: binary or labeled.

    Bc: Structuring Element Default: None (3x3 elementary

    cross). (watershed connectivity)

    return_lines: Whether to return lines as well as regions (default: False)

  • Output

    Y: Gray-scale (uint8 or uint16) or binary image.

  • Description

    cwatershed creates the image y by detecting the domain of the catchment basins of f indicated by the marker image g , according to the connectivity defined by Bc . According to the flag LINEREG y will be a labeled image of the catchment basins domain or just a binary image that presents the watershed lines. To know more about watershed and watershed from markers, see BeucMeye:93. The implementation of this function is based on LotuFalc:00.

    WARNING: There is a common mistake related to the marker image g . If this image contains only zeros and ones, but it is not a binary image, the result will be an image with all ones. If the marker image is binary, you have to set this explicitly (e.g., cwatershed(f,g>0) or cwatershed(f,g.astype(bool)))

  • Examples

    # # example 1 # a = to_uint8([ [10, 10, 10, 10, 10, 10, 10], [10, 9, 6, 18, 6, 5, 10], [10, 9, 6, 18, 6, 8, 10], [10, 9, 9, 15, 9, 9, 10], [10, 9, 9, 15, 12, 10, 10], [10, 10, 10, 10, 10, 10, 10]]) b = (a == 6) print cwatershed(a,b) print cwatershed(a,b,secross(),return_lines=True)[1] # # example 2 # f=readgray(‘astablet.tif’) grad=gradm(f) mark=regmin(hmin(grad,17)) w=cwatershed(grad,mark) show(grad) show(mark) show(w)

pymorph.datatype(f)
  • Purpose

    Return the image datatype string

  • Synopsis

    type = datatype(f)

  • Input
    f: Unsigned gray-scale (uint8 or uint16), signed (int32) or

    binary image. Any image

  • Output
    type: String String representation of image type: ‘binary’,

    ‘uint8’, ‘uint16’ or ‘int32’

  • Description

    datatype returns a string that identifies the pixel datatype of the image f .

pymorph.dilate(f, b=None)
  • Purpose

    Dilate an image by a structuring element.

  • Synopsis

    y = dilate(f, b=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. b: Structuring Element Default: None (3x3 elementary cross).

  • Output

    y: Image

  • Description

    dil performs the dilation of image f by the structuring element b . Dilation is a neighbourhood operator that compares locally b with f , according to an intersection rule. Since Dilation is a fundamental operator to the construction of all other morphological operators, it is also called an elementary operator of Mathematical Morphology. When f is a gray-scale image, b may be a flat or non-flat structuring element.

  • Examples

    # # example 1 # f=binary([

    [0, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0]])

    b=binary([1, 1, 0]) dilate(f,b) f=to_uint8([

    [ 0, 1, 2, 50, 4, 5], [ 2, 3, 4, 0, 0, 0], [12, 255, 14, 15, 16, 17]])

    dilate(f,b) # # example 2 # f=binary(readgray(‘blob.tif’)) bimg=binary(readgray(‘blob1.tif’)) b=img2se(bimg) show(f) show(dilate(f,b)) show(dilate(f,b),gradm(f)) # # example 3 # f=readgray(‘pcb_gray.tif’) b=sedisk(5) show(f) show(dilate(f,b))

pymorph.dist(f, Bc=None, metric=None)
  • Purpose

    Distance transform.

  • Synopsis

    y = dist(f, Bc=None, metric=None)

  • Input

    f: Binary image. Bc: Structuring Element Default: None (3x3 elementary

    cross). (connectivity)

    metric: String Default: None. ‘euclidean’, or ‘euclidean2’ for squared

    Euclidean.

  • Output
    y: distance image in uint16, or in int32 datatype with euclidean2

    option.

  • Description

    dist creates the distance image y of the binary image f . The value of y at the pixel x is the distance of x to the complement of f, that is, the distance of x to nearest point in the complement of f. The distances available are based on the Euclidean metrics and on metrics generated by a a regular graph, that is characterized by a connectivity rule defined by the structuring element Bc. The implementation of the Euclidean algorithm is based on LotuZamp:01 .

  • Examples

    # # example 1 # a = frame(binary(ones((5,9))),2,4) f4=dist(a) f8=dist(a,sebox()) fe=dist(a,sebox(),’EUCLIDEAN’) # # example 2 # f = readgray(‘gear.tif’) f = neg(gradm(f)) d4=dist(f) d8=dist(f,sebox()) de=dist(f,sebox(),’EUCLIDEAN’) show(f) show(d4%8) show(d8%8) show(de%8)

pymorph.drawv(f, data, value, GEOM)
  • Purpose

    Superpose points, rectangles and lines on an image.

  • Synopsis

    y = drawv(f, data, value, GEOM)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. data: Gray-scale (uint8 or uint16) or binary image. vector of

    points. Each row gives information regarding a geometrical primitive. The interpretation of this data is dependent on the parameter GEOM. The line drawing algorithm is not invariant to image transposition.

    value: Gray-scale (uint8 or uint16) or binary image. pixel

    gray-scale value associated to each point in parameter data. It can be a column vector of values or a single value.

    GEOM: String Default: “”. geometrical figure. One of

    ‘point’,’line’, ‘rect’, or ‘frect’ for drawing points, lines, rectangles or filled rectangles respectively.

  • Output
    y: Gray-scale (uint8 or uint16) or binary image. y has the same

    type of f .

  • Description

    drawv creates the image y by a superposition of points, rectangles and lines of gray-level k1 on the image f . The parameters for each geometrical primitive are defined by each line in the ‘data’ parameter. For points , they are represented by a matrix where each row gives the point’s row and column, in this order. For lines , they are drawn with the same convention used by points, with a straight line connecting them in the order given by the data matrix. For rectangles and filled rectangles , each row in the data matrix gives the two points of the diagonal of the rectangle, where the points use the same row, column convention.

  • Examples

    # # example 1 # f=to_uint8(zeros((3,5))) pcoords=to_uint16([[0,2,4],

    [0,0,2]])

    pvalue=to_uint16([1,2,3]) print drawv(f,pcoords,pvalue,’point’) print drawv(f,pcoords,pvalue,’line’) rectcoords=to_uint16([[0],

    [0], [3], [2]])

    print drawv(f,rectcoords, to_uint16(5), ‘rect’) # # example 2 # f=readgray(‘blob3.tif’) pc=blob(label(f),’centroid’,’data’) lines=drawv(intersec(f,0),transpose(pc),to_uint8(1),’line’) show(f,lines)

pymorph.edgeoff(f, Bc=None)
  • Purpose

    Eliminate the objects that hit the image frame.

  • Synopsis

    y = edgeoff(f, Bc=None)

  • Input

    f: Binary image. Bc: Structuring Element Default: None (3x3 elementary cross). (

    connectivity)

  • Output

    y: Binary image.

  • Description

    edgeoff creates the binary image y by eliminating the objects (connected components) of the binary image f that hit the image frame, according to the connectivity defined by the structuring element Bc .

  • Examples

    # a=readgray(‘form-1.tif’) b=edgeoff(a) show(a) show(b)

pymorph.endpoints(option='loop')
  • Purpose

    Interval to detect end-points.

  • Synopsis

    iab = endpoints(option=”loop”)

  • Input

    option: string default: “loop”. ‘loop’ or ‘homotopic’

  • Output

    Iab: Interval

  • Description

    endpoints creates an interval that is useful to detect end-points of curves (i.e., one pixel thick connected components) in binary images. It can be used to prune skeletons and to mark objects transforming them in a single pixel or closed loops if they have holes. There are two options available: ‘loop’, deletes all points but preserves loops if used in thin ; ‘homotopic’, deletes all points but preserves the last single point or loops.

  • Examples

    # # example 1 # print intershow(endpoints()) # # example 2 # print intershow(endpoints(‘homotopic’)) # # example 3 # f = readgray(‘pcbholes.tif’) show(f) f1 = thin(f) show(f1) f2 = thin(f1,endpoints(),20) show(f2) # # example 4 # fn = thin(f1,endpoints(‘homotopic’)) show(dilate(fn))

pymorph.erode(f, b=None)
  • Purpose

    Erode an image by a structuring element.

  • Synopsis

    y = erode(f, b=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. b: Structuring Element Default: None (3x3 elementary cross).

  • Output

    y: Image

  • Description

    ero performs the erosion of the image f by the structuring element b . Erosion is a neighbourhood operator that compairs locally b with f , according to an inclusion rule. Since erosion is a fundamental operator to the construction of all other morphological operators, it is also called an elementary operator of Mathematical Morphology. When f is a gray-scale image, b may be a flat or non-flat structuring element.

  • Examples

    # # example 1 # f=binary([

    [1, 1, 1, 0, 0, 1, 1], [1, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 0, 0]])

    b=binary([1, 1, 0]) erode(f,b) f=to_uint8([

    [ 0, 1, 2, 50, 4, 5], [ 2, 3, 4, 0, 0, 0], [12, 255, 14, 15, 16, 17]])

    erode(f,b) # # example 2 # f=binary(readgray(‘blob.tif’)) bimg=binary(readgray(‘blob1.tif’)) b=img2se(bimg) g=erode(f,b) show(f) show(g) show(g,gradm(f)) # # example 3 # f=readgray(‘pcb_gray.tif’) b=sedisk(3) show(f) show(erode(f,b))

pymorph.flood(fin, T, option, Bc=None)
  • Purpose

    Flooding filter- h,v,a-basin and dynamics (depth, area, volume)

  • Synopsis

    y = flood(fin, T, option, Bc=None)

  • Input

    fin: Gray-scale (uint8 or uint16) image. T: Criterion value. If T==-1, then the dynamics is

    determined, not the flooding at this criterion. This was selected just to use the same algoritm to compute two completely distinct functions.

    option: String Default: “”. criterion: ‘AREA’, ‘VOLUME’, ‘H’. Bc: Structuring Element Default: None (3x3 elementary

    cross). Connectivity.

  • Output

    y: Gray-scale (uint8 or uint16) image.

  • Description

    This is a flooding algorithm. It is the basis to implement many topological functions. It is a connected filter that floods an image following some topological criteria: area, volume, depth. These filters are equivalent to area-close, volume-basin or h-basin, respectively. This code may be difficult to understand because of its many options. Basically, when t is negative, the generalized dynamics: area, volume, h is computed. When the flooding is computed, every time a new level in the flooding happens, a test is made to verify if the criterion has reached. This is used to set the value to that height. This value image will be used later for sup-reconstruction (flooding) at that particular level. This test happens in the raising of the water and in the merging of basins.

pymorph.frame(f, WT=1, HT=1, DT=0, k1=None, k2=None)
  • Purpose

    Create a frame image.

  • Synopsis

    y = frame(f, WT=1, HT=1, DT=0, k1=None, k2=None)

  • Input
    f: Unsigned gray-scale (uint8 or uint16), signed (int32) or

    binary image.

    WT: Double Default: 1. Positive integer ( width thickness). HT: Double Default: 1. Positive integer ( height thickness). DT: Double Default: 0. Positive integer ( depth thickness). k1: Non-negative integer. Default: None (Maximum pixel value

    allowed in f). Frame gray-level.

    k2: Non-negative integer. Default: None (Minimum pixel value

    allowed in f). Background gray level.

  • Output

    y: image of same type as f .

  • Description

    frame creates an image y , with the same dimensions (W,H,D) and same pixel type of the image f , such that the value of the pixels in the image frame is k1 and the value of the other pixels is k2 . The thickness of the image frame is DT.

pymorph.freedom(L=5)
  • Purpose

    Control automatic data type conversion.

  • Synopsis

    Y = freedom(L=5)

  • Input
    L: Double Default: 5. level of FREEDOM: 0, 1 or 2. If the input

    parameter is omitted, the current level is returned.

  • Output

    Y: Double current FREEDOM level

  • Description

    freedom controls the automatic data type conversion. There are 3 possible levels, called FREEDOM levels, for automatic conversion: 0 - image type conversion is not allowed; 1- image type conversion is allowed, but a warning is sent for each conversion; 2- image type conversion is allowed without warning. The FREEDOM levels are set or inquired by freedom . If an image is not in the required datatype, than it should be converted to the maximum and nearest pymorph Morphology Toolbox datatype. For example, if an image is in int32 and a morphological gray-scale processing that accepts only binary, uint8 or uint16 images, is required, it will be converted to uint16. Another example, if a binary image should be added to a uint8 image, the binary image will be converted to uint8. In cases of operators that have as parameters an image and a constant, the type of the image should be kept as reference, while the type of the constant should be converted, if necessary.

  • Examples

    # # example 1 # a=subm([4., 2., 1.],to_uint8([3, 2, 0])) print a print datatype(a) # # example 2 # a=subm([4., 2., 1], binary([3, 2, 0])) print a print datatype(a) # # example 3 # a=subm(to_uint8([4, 3, 2, 1]), 1) print a print datatype(a)

pymorph.gdist(f, g, Bc=None, METRIC=None)
  • Purpose

    Geodesic Distance Transform.

  • Synopsis

    y = gdist(f, g, Bc=None, METRIC=None)

  • Input

    f: Binary image. g: Binary image. Marker image Bc: Structuring Element Default: None (3x3 elementary

    cross). (metric for distance).

    METRIC: String Default: None. ‘EUCLIDEAN’ if specified.

  • Output

    y: uint16 (distance image).

  • Description

    gdist creates the geodesic distance image y of the binary image f relative to the binary image g . The value of y at the pixel x is the length of the smallest path between x and f . The distances available are based on the Euclidean metrics and on metrics generated by a neighbourhood graph, that is characterized by a connectivity rule defined by the structuring element Bc . The connectivity for defining the paths is consistent with the metrics adopted to measure their length. In the case of the Euclidean distance, the space is considered continuos and, in the other cases, the connectivity is the one defined by Bc .

  • Examples

    # # example 1 # f=binary([

    [1,1,1,1,1,1], [1,1,1,0,0,1], [1,0,1,0,0,1], [1,0,1,1,0,0], [0,0,1,1,1,1], [0,0,0,1,1,1]])

    g=binary([

    [0,0,0,0,0,0], [1,1,0,0,0,0], [0,0,0,0,0,0], [0,0,0,0,0,0], [0,0,0,0,0,0], [0,0,0,0,0,1]])

    y=gdist(f,g,secross()) print y # # example 2 # f=readgray(‘maze_bw.tif’) g=intersec(f,0) g=drawv(g,to_uint16([[2],[2],[6],[6]]),to_uint16(1),’frect’) y=gdist(f,g,sebox(),’EUCLIDEAN’) show(f,g)

pymorph.gradm(f, Bdil=None, Bero=None)
  • Purpose

    Morphological gradient.

  • Synopsis

    y = gradm(f, Bdil=None, Bero=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. Bdil: Structuring Element Default: None (3x3 elementary cross).

    for the dilation.

    Bero: Structuring Element Default: None (3x3 elementary cross).

    for the erosion.

  • Output
    y: Gray-scale (uint8 or uint16) or binary image. (same type of f

    ).

  • Description

    gradm creates the image y by the subtraction of the erosion of the image f by Bero of the dilation of f by Bdil .

  • Examples

    # # example 1 # a = readgray(‘small_bw.tif’) b = gradm(a) show(a) show(b) # # example 2 # c=gradm(a,secross(0),secross()) d=gradm(a,secross(),secross(0)) show(a,c) show(a,d) # # example 3 # a = readgray(‘bloodcells.tif’) b = gradm(a) show(a) show(b)

pymorph.grain(fr, f, measurement, option='image')
  • Purpose

    Gray-scale statistics for each labeled region.

  • Synopsis

    y = grain(fr, f, measurement, option=”image”)

  • Input
    fr: Gray-scale (uint8 or uint16) image. Labeled image,

    to define the regions. Label 0 is the background region.

    f: Gray-scale (uint8 or uint16) image. To extract the

    measuremens.

    measurement: String Default: “”. Choose the measure to compute:

    ‘max’, ‘min’, ‘median’, ‘mean’, ‘sum’, ‘std’, ‘std1’.

    option: String Default: “image”. Output format: ‘image’:

    results as a gray-scale mosaic image (uint16); ‘data’: results a column vector of measurements (double).

  • Output
    y: Gray-scale (uint8 or uint16) image. Or a column vector

    (double) with gray-scale statistics per region.

  • Description

    Computes gray-scale statistics of each grain in the image. The grains regions are specified by the labeled image fr and the gray-scale information is specified by the image f . The statistics to compute is specified by the parameter measurement, which has the same options as in function stats . The parameter option defines: (‘image’) if the output is an uint16 image where each label value is changed to the measurement value, or (‘data’) a double column vector. In this case, the first element (index 1) is the measurement of region 1. The region with label zero is not measure as it is normally the background.

  • Examples

    # # example 1 # f=to_uint8([range(6),range(6),range(6)]) fr=labelflat(f) grain(fr,f,’sum’,’data’) grain(fr,f,’sum’) # # example 2 # f=readgray(‘astablet.tif’) g=gradm(f) marker=regmin(close(g)) ws=cwatershed(g,marker,sebox(),’regions’) g=grain(ws,f,’mean’) show(f) show(g)

pymorph.gray(f, TYPE='uint8', k1=None)
  • Purpose

    Convert a binary image into a gray-scale image.

  • Synopsis

    y = gray(f, TYPE=”uint8”, k1=None)

  • Input

    f: Binary image. TYPE: String Default: “uint8”. ‘uint8’, ‘uint16’, or ‘int32’. k1: Non-negative integer. Default: None (Maximum pixel level

    in pixel type).

  • Output
    y: Unsigned gray-scale (uint8 or uint16), signed (int32) or

    binary image.

  • Description

    gray converts a binary image into a gray-scale image of a specified data type. The value k1 is assigned to the 1 pixels of f , while the 0 pixels are assigned to the minimum value associated to the specified data type.

  • Examples

    # b=binary([0, 1, 0, 1]) print b c=gray(b) print c d=gray(b,’uint8’,100) print d e=gray(b,’uint16’) print e f=gray(b,’int32’,0) print f

pymorph.histogram(f)

Find the histogram of the image f.

Finds the histogram of the image f and returns the result in the vector h . For binary image the vector size is 2. For gray-scale uint8 and uint16 images, the vector size is the maximum pixel value plus one. h[0] gives the number of pixels with value 0.

Parameters:* f: Input image (of any integer type). :
pymorph.hmax(f, h=1, Bc=None)
  • Purpose

    Remove peaks with contrast less than h.

  • Synopsis

    y = hmax(f, h=1, Bc=None)

  • Input

    f: Gray-scale (uint8 or uint16) image. h: Default: 1. Contrast parameter. Bc: Structuring Element Default: None (3x3 elementary cross).

    Structuring element ( connectivity).

  • Output

    y: Gray-scale (uint8 or uint16) or binary image.

  • Description

    hmax inf-reconstructs the gray-scale image f from the marker created by the subtraction of the positive integer value h from f , using connectivity Bc . This operator removes connected peaks with contrast less than h .

  • Examples

    # # example 1 # a = to_uint8([

    [4, 3, 6, 1, 3, 5, 2], [2, 9, 6, 1, 6, 7, 3], [8, 9, 3, 2, 4, 9, 4], [3, 1, 2, 1, 2, 4, 2]])

    print hmax(a,2,sebox()) # # example 2 # f = readgray(‘r4x2_256.tif’) show(f) fb = hmax(f,50) show(fb) show(regmax(fb))

pymorph.hmin(f, h=1, Bc=None)
  • Purpose

    Remove basins with contrast less than h.

  • Synopsis

    y = hmin(f, h=1, Bc=None)

  • Input

    f: Gray-scale (uint8 or uint16) image. h: Default: 1. Contrast parameter. Bc: Structuring Element Default: None (3x3 elementary cross).

    Structuring element (connectivity).

  • Output

    y: Gray-scale (uint8 or uint16) or binary image.

  • Description

    hmin sup-reconstructs the gray-scale image f from the marker created by the addition of the positive integer value h to f , using the connectivity Bc . This operator removes connected basins with contrast less than h . This function is very userful for simplifying the basins of the image.

  • Examples

    # # example 1 # a = to_uint8([

    [10, 3, 6, 18, 16, 15, 10], [10, 9, 6, 18, 6, 5, 10], [10, 9, 9, 15, 4, 9, 10], [10, 10, 10, 10, 10, 10, 10]])

    print hmin(a,1,sebox()) # # example 2 # f = readgray(‘r4x2_256.tif’) show(f) fb = hmin(f,70) show(fb) show(regmin(fb))

pymorph.homothick()
  • Purpose

    Interval for homotopic thickening.

  • Synopsis

    Iab = homothick()

  • Output

    Iab: Interval

  • Description

    homothick creates an interval that is useful for the homotopic (i.e., that conserves the relation between objects and holes) thickening of binary images.

  • Examples

    # print intershow(homothick())

pymorph.homothin()
  • Purpose

    Interval for homotopic thinning.

  • Synopsis

    Iab = homothin()

  • Output

    Iab: Interval

  • Description

    homothin creates an interval that is useful for the homotopic (i.e., that conserves the relation between objects and holes) thinning of binary images.

pymorph.img2se(fd, FLAT='FLAT', f=None)
  • Purpose

    Create a structuring element from a pair of images.

  • Synopsis

    B = img2se(fd, FLAT=”FLAT”, f=None)

  • Input
    fd: Binary image. The image is in the matrix format where the

    origin (0,0) is at the matrix center.

    FLAT: String Default: “FLAT”. ‘FLAT’ or ‘NON-FLAT’. f: Unsigned gray-scale (uint8 or uint16), signed (int32) or

    binary image. Default: None.

  • Output

    B: Structuring Element

  • Description

    img2se creates a flat structuring element B from the binary image fd or creates a non-flat structuring element b from the binary image fd and the gray-scale image f . fd represents the domain of b and f represents the image of the points in fd .

  • Examples

    # # example 1 # a = img2se(binary([

    [0,1,0], [1,1,1], [0,1,0]]))

    print seshow(a) # # example 2 # b = binary([

    [0,1,1,1], [1,1,1,0]])

    b1 = img2se(b) print seshow(b1) # # example 3 # c = binary([

    [0,1,0], [1,1,1], [0,1,0]])

    d = to_int32([

    [0,0,0], [0,1,0], [0,0,0]])

    e = img2se(c,’NON-FLAT’,d) print seshow(e)

pymorph.infcanon(f, Iab, theta=45, DIRECTION='CLOCKWISE')
  • Purpose

    Intersection of inf-generating operators.

  • Synopsis

    y = infcanon(f, Iab, theta=45, DIRECTION=”CLOCKWISE”)

  • Input

    f: Binary image. Iab: Interval theta: Double Default: 45. Degrees of rotation: 45, 90, or

    DIRECTION: String Default: “CLOCKWISE”. ‘CLOCKWISE’ or ‘

    ANTI-CLOCKWISE’

  • Output

    y: Binary image.

  • Description

    infcanon creates the image y by computing intersections of transformations of the image f by inf-generating (i.e., dual of the hit-or-miss) operators. These inf-generating operators are characterized by rotations (in the clockwise or anti-clockwise direction) of theta degrees of the interval Iab .

pymorph.infgen(f, Iab)
  • Purpose

    Inf-generating.

  • Synopsis

    y = infgen(f, Iab)

  • Input

    f: Binary image. Iab: Interval

  • Output

    y: Binary image.

  • Description

    infgen creates the image y by computing the transformation of the image f by the inf-generating operator (or dual of the hit-or-miss) characterized by the interval Iab .

pymorph.infrec(f, g, Bc=None)
  • Purpose

    Inf-reconstruction.

  • Synopsis

    y = infrec(f, g, Bc=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. Marker image. g: Gray-scale (uint8 or uint16) or binary image. Conditioning

    image.

    Bc: Structuring Element Default: None (3x3 elementary cross).

    Structuring element ( connectivity).

  • Output

    y: Image

  • Description

    infrec creates the image y by an infinite number of recursive iterations (iterations until stability) of the dilation of f by Bc conditioned to g . We say the y is the inf-reconstruction of g from the marker f . For algorithms and applications, see Vinc:93b .

  • Examples

    # # example 1 # g=readgray(‘text_128.tif’) f=erode(g,seline(9,90)) y=infrec(f,g,sebox()) show(g) show(f) show(y) # # example 2 # g=neg(readgray(‘n2538.tif’)) f=intersec(g,0) f=draw(f,’LINE:40,30,60,30:END’) y30=cdilate(f,g,sebox(),30) y=infrec(f,g,sebox()) show(g) show(f) show(y30) show(y)

pymorph.inpos(f, g, Bc=None)
  • Purpose

    Minima imposition.

  • Synopsis

    y = inpos(f, g, Bc=None)

  • Input

    f: Binary image. Marker image. g: Gray-scale (uint8 or uint16) image. input image. Bc: Structuring Element Default: None (3x3 elementary cross).

    (connectivity).

  • Output

    y: Gray-scale (uint8 or uint16) image.

  • Description

    Minima imposition on g based on the marker f . inpos creates an image y by filing the valleys of g that does not cover the connect components of f . A remarkable property of y is that its regional minima are exactly the connect components of g .

pymorph.interot(Iab, theta=45, DIRECTION='CLOCKWISE')
  • Purpose

    Rotate an interval

  • Synopsis

    Irot = interot(Iab, theta=45, DIRECTION=”CLOCKWISE”)

  • Input

    Iab: Interval theta: Double Default: 45. Degrees of rotation. Available

    values are multiple of 45 degrees.

    DIRECTION: String Default: “CLOCKWISE”. ‘CLOCKWISE’ or ‘

    ANTI-CLOCKWISE’.

  • Output

    Irot: Interval

  • Description

    interot rotates the interval Iab by an angle theta .

  • Examples

    # b1 = endpoints() b2 = interot(b1) print intershow(b1) print intershow(b2)

pymorph.intersec(f1, f2, f3=None, f4=None, f5=None)
  • Purpose

    Intersection of images.

  • Synopsis

    y = intersec(f1, f2, f3=None, f4=None, f5=None)

  • Input

    f1: Gray-scale (uint8 or uint16) or binary image. f2: Gray-scale (uint8 or uint16) or binary image. Or constant. f3: Gray-scale (uint8 or uint16) or binary image. Default: None.

    Or constant.

    f4: Gray-scale (uint8 or uint16) or binary image. Default: None.

    Or constant.

    f5: Gray-scale (uint8 or uint16) or binary image. Default: None.

    Or constant.

  • Output

    y: Image

  • Description

    intersec creates the image y by taking the pixelwise minimum between the images f1, f2, f3, f4, and f5 . When f1, f2, f3, f4, and f5 are binary images, y is the intersection of them.

  • Examples

    # # example 1 # f=to_uint8([255, 255, 0, 10, 0, 255, 250]) g=to_uint8([ 0, 40, 80, 140, 250, 10, 30]) print intersec(f, g) print intersec(f, 0) # # example 2 # a = readgray(‘form-ok.tif’) b = readgray(‘form-1.tif’) c = intersec(a,b) show(a) show(b) show(c) # # example 3 # d = readgray(‘tplayer1.tif’) e = readgray(‘tplayer2.tif’) f = readgray(‘tplayer3.tif’) g = intersec(d,e,f) show(d) show(e) show(f) show(g)

pymorph.intershow(Iab)
  • Purpose

    Visualize an interval.

  • Synopsis

    s = intershow(Iab)

  • Input

    Iab: Interval

  • Output

    s: String ( representation of the interval).

  • Description

    intershow creates a representation for an interval using 0, 1 and . ( don’t care).

  • Examples

    # print intershow(homothin())

pymorph.isbinary(f)
  • Purpose

    Check for binary image

  • Synopsis

    bool = isbinary(f)

  • Input

    f:

  • Output

    bool: Boolean

  • Description

    isbinary returns True if the datatype of the input image is binary. A binary image has just the values 0 and 1.

  • Examples

    # a=to_uint8([0, 1, 0, 1]) print isbinary(a) b=(a) print isbinary(b)

pymorph.isolines(X, N=10)

Apply an iso-contour color table to a gray-scale image.

Parameters:

* X: Gray-scale (uint8 or uint16) image. Distance transform image. :

  • N: Default: 10. Number of iso-contours.
pymorph.label(f, Bc=None)
  • Purpose

    Label a binary image.

  • Synopsis

    y = label(f, Bc=None)

  • Input

    f: Binary image. Bc: Structuring Element Default: None (3x3 elementary cross). (

    connectivity).

  • Output
    y: Image If number of labels is less than 65535, the data type

    is uint16, otherwise it is int32.

  • Description

    label creates the image y by labeling the connect components of a binary image f , according to the connectivity defined by the structuring element Bc . The background pixels (with value 0) are not labeled. The maximum label value in the output image gives the number of its connected components.

  • Examples

    # # example 1 # f=binary([

    [0,1,0,1,1], [1,0,0,1,0]])

    g=label(f) print g # # example 2 # f = readgray(‘blob3.tif’) g=label(f) nblobs=g.max() print nblobs show(f) lblshow(g)

pymorph.labelflat(f, Bc=None, _lambda=0)
  • Purpose

    Label the flat zones of gray-scale images.

  • Synopsis

    y = labelflat(f, Bc=None, _lambda=0)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. Bc: Structuring Element Default: None (3x3 elementary

    cross). ( connectivity).

    _lambda: Default: 0. Connectivity given by |f(q)-f(p)|<=_lambda.

  • Output
    y: Image If number of labels is less than 65535, the data type

    is uint16, otherwise it is int32.

  • Description

    labelflat creates the image y by labeling the flat zones of f , according to the connectivity defined by the structuring element Bc . A flat zone is a connected region of the image domain in which all the pixels have the same gray-level (lambda=0 ). When lambda is different than zero, a quasi-flat zone is detected where two neighboring pixels belong to the same region if their difference gray-levels is smaller or equal lambda . The minimum label of the output image is 1 and the maximum is the number of flat-zones in the image.

  • Examples

    # # example 1 # f=to_uint8([

    [5,5,8,3,0], [5,8,8,0,2]])

    g=labelflat(f) print g g1=labelflat(f,secross(),2) print g1 # # example 2 # f=readgray(‘blob.tif’) d=dist(f,sebox(),’euclidean’) g= d /8 show(g) fz=labelflat(g,sebox()); lblshow(fz) print fz.max() # # example 3 # f=readgray(‘pcb_gray.tif’) g=labelflat(f,sebox(),3) show(f) lblshow(g)

pymorph.lastero(f, B=None)
  • Purpose

    Last erosion.

  • Synopsis

    y = lastero(f, B=None)

  • Input

    f: Binary image. B: Structuring Element Default: None (3x3 elementary cross).

  • Output

    y: Binary image.

  • Description

    lastero creates the image y by computing the last erosion by the structuring element B of the image f . The objects found in y are the objects of the erosion by nB that can not be reconstructed from the erosion by (n+1)B , where n is a generic non negative integer. The image y is a proper subset of the morphological skeleton by B of f .

pymorph.limits(f)
  • Purpose

    Get the possible minimum and maximum of an image.

  • Synopsis

    y = limits(f)

  • Input
    f: Unsigned gray-scale (uint8 or uint16), signed (int32) or

    binary image.

  • Output
    y: Vector, the first element is the infimum, the second, the

    supremum.

  • Description

    The possible minimum and the possible maximum of an image depend on its data type. These values are important to compute many morphological operators (for instance, negate of an image). The output is a vector, where the first element is the possible minimum and the second, the possible maximum.

  • Examples

    # print limits(binary([0, 1, 0])) print limits(to_uint8([0, 1, 2]))

pymorph.mat2set(A)
Converts image representation from matrix to set
  • Input
    A: Image in matrix format, where the origin (0,0) is at the

    center of the matrix.

  • Output

    C: array of pixel coordinates

    V: array of pixel values corresponding to the coordinates of C

  • Description

    Return tuple with array of pixel coordinates and array of corresponding pixel values. The input image is in the matrix format, like the structuring element, where the origin (0,0) is at the center of the matrix.

  • Examples

    # # example 1 # f=to_uint8([[1,2,3],[4,5,6],[7,8,9]]) i,v=mat2set(f) print i print v # # example 2 # f=to_uint8([[1,2,3,4],[5,6,7,8]]) i,v=mat2set(f) print i print v

pymorph.maxleveltype(TYPE='uint8')
  • Purpose

    Returns the maximum value associated to an image datatype

  • Synopsis

    max = maxleveltype(TYPE=’uint8’)

  • Input
    TYPE: String Default: ‘uint8’. One of the strings ‘uint8’,

    ‘uint16’ or ‘int32’, specifying the image type

  • Output

    max: the maximum level value of type TYPE

pymorph.neg(f)
  • Purpose

    Negate an image.

  • Synopsis

    y = neg(f)

  • Input
    f: Unsigned gray-scale (uint8 or uint16), signed (int32) or

    binary image.

  • Output
    y: Unsigned gray-scale (uint8 or uint16), signed (int32) or

    binary image.

  • Description

    neg returns an image y that is the negation (i.e., inverse or involution) of the image f . In the binary case, y is the complement of f .

  • Examples

    # # example 1 # f=to_uint8([255, 255, 0, 10, 20, 10, 0, 255, 255]) print neg(f) print neg(to_uint8([0, 1])) print neg(to_int32([0, 1])) # # example 2 # a = readgray(‘gear.tif’) b = neg(a) show(a) show(b) # # example 3 # c = readgray(‘astablet.tif’) d = neg(c) show(c) show(d)

pymorph.open(f, b=None)
  • Purpose

    Morphological opening.

  • Synopsis

    y = open(f, b=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. b: Structuring Element Default: None (3x3 elementary cross).

  • Output

    y: Image

  • Description

    open creates the image y by the morphological opening of the image f by the structuring element b . In the binary case, the opening by the structuring element B may be interpreted as the union of translations of B included in f . In the gray-scale case, there is a similar interpretation taking the functions umbra.

  • Examples

    # # example 1 # f=binary(readgray(‘blob.tif’)) bimg=binary(readgray(‘blob1.tif’)) b=img2se(bimg) show(f) show(open(f,b)) show(open(f,b),gradm(f)) # # example 2 # a=binary(readgray(‘pcb1bin.tif’)) b=open(a,sebox(2)) c=open(a,sebox(4)) show(a) show(b) show(c) # # example 3 # a=readgray(‘astablet.tif’) b=open(a,sedisk(18)) show(a) show(b)

pymorph.openrec(f, bero=None, bc=None)
  • Purpose

    Opening by reconstruction.

  • Synopsis

    y = openrec(f, bero=None, bc=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. bero: Structuring Element Default: None (3x3 elementary cross).

    (erosion).

    bc: Structuring Element Default: None (3x3 elementary cross).

    (connectivity).

  • Output

    y: Image (same type of f ).

  • Description

    openrec creates the image y by an inf-reconstruction of the image f from its erosion by bero , using the connectivity defined by Bc .

pymorph.openrecth(f, bero=None, bc=None)
  • Purpose

    Open-by-Reconstruction Top-Hat.

  • Synopsis

    y = openrecth(f, bero=None, bc=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. bero: Structuring Element Default: None (3x3 elementary cross).

    (erosion)

    bc: Structuring Element Default: None (3x3 elementary cross).

    ( connectivity)

  • Output
    y: Gray-scale (uint8 or uint16) or binary image. (same type of f

    ).

  • Description

    openrecth creates the image y by subtracting the open by reconstruction of f , defined by the structuring elements bero e bc , of f itself.

pymorph.openth(f, b=None)
  • Purpose

    Opening Top Hat.

  • Synopsis

    y = openth(f, b=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. b: Structuring Element Default: None (3x3 elementary cross).

    structuring element

  • Output
    y: Gray-scale (uint8 or uint16) or binary image. (same type of f

    ).

  • Description

    openth creates the image y by subtracting the morphological opening of f by the structuring element b of f itself.

  • Examples

    # a = readgray(‘keyb.tif’) show(a) b = openth(a,sebox(3)) show(b)

pymorph.opentransf(f, type='OCTAGON', n=65535, Bc=None, Buser=None)
  • Purpose

    Open transform.

  • Synopsis

    y = opentransf(f, type=’OCTAGON’, n=65535, Bc=None, Buser=None)

  • Input

    f: Binary image. type: String Default: ‘OCTAGON’. Disk family: ‘OCTAGON’,

    ‘CHESSBOARD’, ‘CITY-BLOCK’, ‘LINEAR-V’, ‘LINEAR-H’, ‘LINEAR-45R’, ‘LINEAR-45L’, ‘USER’.

    n: Default: 65535. Maximum disk radii. Bc: Structuring Element Default: None (3x3 elementary cross).

    Connectivity for the reconstructive opening. Used if ‘-REC’ suffix is appended in the ‘type’ string.

    Buser: Structuring Element Default: None (3x3 elementary cross).

    User disk, used if ‘type’ is ‘USER’.

  • Output

    y: Gray-scale (uint8 or uint16) image.

  • Description

    Compute the open transform of a binary image. The value of the pixels in the open transform gives the largest radii of the disk plus 1, where the open by it is not empty at that pixel. The disk sequence must satisfy the following: if r > s, rB is sB-open, i.e. rB open by sB is equal rB. Note that the Euclidean disk does not satisfy this property in the discrete grid. This function also computes the reconstructive open transform by adding the suffix ‘-REC’ in the ‘type’ parameter.

  • Examples

    # # example 1 # f = binary([

    [0,0,0,0,0,0,0,0], [0,0,1,1,1,1,0,0], [0,0,1,1,1,1,1,0], [0,1,0,1,1,1,0,0], [1,1,0,0,0,0,0,0]])

    print opentransf( f, ‘city-block’) print opentransf( f, ‘linear-h’) print opentransf( f, ‘linear-45r’) print opentransf( f, ‘user’,10,secross(),binary([0,1,1])) print opentransf( f, ‘city-block-rec’) # # example 2 # f=readgray(‘numbers.tif’) show(f) g=opentransf(f,’OCTAGON’) show(g) # # example 3 # b=sedisk(3,‘2D’,’OCTAGON’) g1=open(f,b) show(g1) g2=(g > 3) print g1 == g2

pymorph.pad4n(f, Bc, value, scale=1)
  • Purpose

    pads f with value so that Bc can be applied scaled by scale.

  • Synopsis

    y = pad4n(f, Bc, value, scale=1)

  • Input

    f: Image Bc: Structuring Element (connectivity). value: scale: Default: 1.

  • Output

    The converted image

pymorph.patspec(f, type='OCTAGON', n=65535, Bc=None, Buser=None)
  • Purpose

    Pattern spectrum (also known as granulometric size density).

  • Synopsis

    h = patspec(f, type=’OCTAGON’, n=65535, Bc=None, Buser=None)

  • Input

    f: Binary image. type: String Default: ‘OCTAGON’. Disk family: ‘OCTAGON’,

    ‘CHESSBOARD’, ‘CITY-BLOCK’, ‘LINEAR-V’, ‘LINEAR-H’, ‘LINEAR-45R’, ‘LINEAR-45L’, ‘USER’.

    n: Default: 65535. Maximum disk radii. Bc: Structuring Element Default: None (3x3 elementary cross).

    Connectivity for the reconstructive granulometry. Used if ‘-REC’ suffix is appended in the ‘type’ string.

    Buser: Structuring Element Default: None (3x3 elementary cross).

    User disk, used if ‘type’ is ‘USER’.

  • Output
    h: Gray-scale (uint8 or uint16) or binary image. a uint16

    vector.

  • Description

    Compute the Pattern Spectrum of a binary image. See Mara:89b . The pattern spectrum is the histogram of the open transform, not taking the zero values.

pymorph.randomcolor(X)

Apply a random color table to a gray-scale image.

Parameters:* X: Gray-scale (uint8 or uint16) image. Labeled image. :
pymorph.regmax(f, Bc=None)
  • Purpose

    Regional Maximum.

  • Synopsis

    y = regmax(f, Bc=None)

  • Input

    f: Gray-scale (uint8 or uint16) image. Bc: Structuring Element Default: None (3x3 elementary cross).

    (connectivity).

  • Output

    y: Binary image.

  • Description

    regmax creates a binary image y by computing the regional maxima of f , according to the connectivity defined by the structuring element Bc . A regional maximum is a flat zone not surrounded by flat zones of higher gray values.

pymorph.regmin(f, Bc=None, option='binary')
  • Purpose

    Regional Minimum (with generalized dynamics).

  • Synopsis

    y = regmin(f, Bc=None, option=”binary”)

  • Input

    f: Gray-scale (uint8 or uint16) image. Bc: Structuring Element Default: None (3x3 elementary

    cross). (connectivity).

    option: String Default: “binary”. Choose one of: BINARY: output
    One of:

    ‘binary’: output a binary image ‘value’: output a grayscale image with

    points at the regional minimum with the pixel values of the input image

    ‘dynamics’: output a grayscale image with

    points at the regional minimum with its dynamics;

    ‘area-dyn’: int32 image with the area-dynamics; ‘volume-dyn’: int32 image with the volume-dynamics.

  • Output

    y: Gray-scale (uint8 or uint16) or binary image.

  • Description

    regmin creates a binary image f by computing the regional minima of f , according to the connectivity defined by the structuring element Bc . A regional minimum is a flat zone not surrounded by flat zones of lower gray values. A flat zone is a maximal connected component of a gray-scale image with same pixel values. There are three output options: binary image; valued image; and generalized dynamics. The dynamics of a regional minima is the minimum height a pixel has to climb in a walk to reach another regional minima with a higher dynamics. The area-dyn is the minimum area a catchment basin has to raise to reach another regional minima with higher area-dynamics. The volume-dyn is the minimum volume a catchment basin has to raise to reach another regional minima with a higher volume dynamics. The dynamics concept was first introduced in Grimaud:92 and it is the basic notion for the hierarchical or multiscale watershed transform.

  • Examples

    # # example 1 # a = to_uint8([

    [10, 10, 10, 10, 10, 10, 10], [10, 9, 6, 18, 6, 5, 10], [10, 9, 6, 18, 6, 5, 10], [10, 9, 9, 15, 4, 9, 10], [10, 9, 9, 15, 12, 10, 10], [10, 10, 10, 10, 10, 10, 10]])

    print regmin(a) print regmin(a,secross(),’value’) print regmin(a,secross(),’dynamics’) # # example 2 # f1=readgray(‘bloodcells.tif’) m1=regmin(f1,sebox()) show(f1,m1) f2=hmin(f1,70) show(f2) m2=regmin(f2,sebox()) show(f2,m2) # # example 3 # f=readgray(‘cameraman.tif’) g=gradm(f) mh=regmin(g,secross(),’dynamics’) ws1=cwatershed(g, binary(mh, 20)) ws2=cwatershed(g, binary(mh, 40)) show(ws1) show(ws2)

pymorph.se2hmt(A, Bc)
  • Purpose

    Create a Hit-or-Miss Template (or interval) from a pair of structuring elements.

  • Synopsis

    Iab = se2hmt(A, Bc)

  • Input

    A: Structuring Element Left extremity. Bc: Structuring Element Complement of the right extremity.

  • Output

    Iab: Interval

  • Description

    se2hmt creates the Hit-or-Miss Template (HMT), also called interval [A,Bc] from the structuring elements A and Bc such that A is included in the complement of Bc . The only difference between this function and se2interval is that here the second structuring element is the complement of the one used in the other function. The advantage of this function over se2interval is that this one is more flexible in the use of the structuring elements as they are not required to have the same size.

pymorph.se2interval(a, b)
  • Purpose

    Create an interval from a pair of structuring elements.

  • Synopsis

    Iab = se2interval(a, b)

  • Input

    a: Structuring Element Left extremity. b: Structuring Element Right extremity.

  • Output

    Iab: Interval

  • Description

    se2interval creates the interval [a,b] from the structuring elements a and b such that a is less or equal b .

pymorph.sebox(r=1)
  • Purpose

    Create a box structuring element.

  • Synopsis

    B = sebox(r=1)

  • Input

    r: Non-negative integer. Default: 1. Radius.

  • Output

    B: Structuring Element

  • Description

    sebox creates the structuring element B formed by r successive Minkowski additions of the elementary square (i.e., the 3x3 square centered at the origin) with itself. If R=0, B is the unitary set that contains the origin. If R=1, B is the elementary square itself.

  • Examples

    # b1 = sebox() seshow(b1) b2 = sebox(2) seshow(b2)

pymorph.secross(r=1)
  • Purpose

    Diamond structuring element and elementary 3x3 cross.

  • Synopsis

    B = secross(r=1)

  • Input

    r: Double Default: 1. (radius).

  • Output

    B: Structuring Element

  • Description

    secross creates the structuring element B formed by r successive Minkowski additions of the elementary cross (i.e., the 3x3 cross centered at the origin) with itself. If r=0, B is the unitary set that contains the origin. If r=1 , B is the elementary cross itself.

  • Examples

    # b1 = secross() print seshow(b1) b2 = secross(2) print seshow(b2)

pymorph.sedilate(B1, B2)
  • Purpose

    Dilate one structuring element by another

  • Synopsis

    Bo = sedilate(B1, B2)

  • Input

    B1: Structuring Element B2: Structuring Element

  • Output

    Bo: Structuring Element

  • Description

    sedil dilates an structuring element by another. The main difference between this dilation and dil is that the dilation between structuring elements are not bounded, returning another structuring element usually larger than anyone of them. This gives the composition of the two structuring elements by Minkowski addition.

  • Examples

    # b1 = seline(5) seshow(b1) b2 = sedisk(2) seshow(b2) b3 = sedilate(b1,b2) seshow(b3)

pymorph.sedisk(r=3, DIM='2D', METRIC='EUCLIDEAN', FLAT='FLAT', h=0)
  • Purpose

    Create a disk or a semi-sphere structuring element.

  • Synopsis

    B = sedisk(r=3, DIM=”2D”, METRIC=”EUCLIDEAN”, FLAT=”FLAT”, h=0)

  • Input

    r: Non-negative integer. Default: 3. Disk radius. DIM: String Default: “2D”. ‘1D’, ‘2D, or ‘3D’. METRIC: String Default: “EUCLIDEAN”. ‘EUCLIDEAN’, ‘ CITY-BLOCK’,

    ‘OCTAGON’, or ‘ CHESSBOARD’.

    FLAT: String Default: “FLAT”. ‘FLAT’ or ‘NON-FLAT’. h: Double Default: 0. Elevation of the center of the

    semi-sphere.

  • Output

    B: Structuring Element

  • Description

    sedisk creates a flat structuring element B that is disk under the metric METRIC , centered at the origin and with radius r or a non-flat structuring element that is a semi-sphere under the metric METRIC, centered at (0, h) and with radius r . This structuring element can be created on the 1D, 2D or 3D space.

  • Examples

    # # example 1 # a=seshow(sedisk(10,‘2D’,’CITY-BLOCK’)) b=seshow(sedisk(10,‘2D’,’EUCLIDEAN’)) c=seshow(sedisk(10,‘2D’,’OCTAGON’)) show(a) show(b) show(c) # # example 2 # d=seshow(sedisk(10,‘2D’,’CITY-BLOCK’,’NON-FLAT’)) e=seshow(sedisk(10,‘2D’,’EUCLIDEAN’,’NON-FLAT’)) f=seshow(sedisk(10,‘2D’,’OCTAGON’,’NON-FLAT’)) show(d) show(e) show(f) # # example 3 # g=sedisk(3,‘2D’,’EUCLIDEAN’,’NON-FLAT’) seshow(g) h=sedisk(3,‘2D’,’EUCLIDEAN’,’NON-FLAT’,5) seshow(h)

pymorph.seline(l=3, theta=0)
  • Purpose

    Create a line structuring element.

  • Synopsis

    B = seline(l=3, theta=0)

  • Input

    l: Non-negative integer. Default: 3. theta: Double Default: 0. (degrees, clockwise)

  • Output

    B: Structuring Element

  • Description

    seline creates a structuring element B that is a line segment that has an extremity at the origin, length l and angle theta (0 degrees is east direction, clockwise). If l=0 , it generates the origin.

  • Examples

    # seshow(seline()) b1 = seline(4,45) seshow(b1) b2 = seline(4,-180) seshow(b2) a=text(‘Line’) b=dilate(a,b1) show(a) show(b)

pymorph.sereflect(Bi)
  • Purpose

    Reflect a structuring element

  • Synopsis

    Bo = sereflect(Bi)

  • Input

    Bi: Structuring Element

  • Output

    Bo: Structuring Element

  • Description

    sereflect reflects a structuring element by rotating it 180 degrees.

  • Examples

    # b1 = seline(5,30) print seshow(b1) b2 = sereflect(b1) print seshow(b2)

pymorph.serot(B, theta=45, DIRECTION='CLOCKWISE')
  • Purpose

    Rotate a structuring element.

  • Synopsis

    BROT = serot(B, theta=45, DIRECTION=”CLOCKWISE”)

  • Input

    B: Structuring Element theta: Double Default: 45. Degrees of rotation. Available

    values are multiple of 45 degrees.

    DIRECTION: String Default: “CLOCKWISE”. ‘CLOCKWISE’ or ‘

    ANTI-CLOCKWISE’.

  • Output

    BROT: Structuring Element

  • Description

    serot rotates a structuring element B of an angle theta .

  • Examples

    # b = img2se(binary([[0, 0, 0], [0, 1, 1], [0, 0, 0]])); seshow(b) seshow(serot(b)) seshow(serot(b,45,’ANTI-CLOCKWISE’))

pymorph.seshow(B, option='NORMAL')
  • Purpose

    Display a structuring element as an image.

  • Synopsis

    y = seshow(B, option=”NORMAL”)

  • Input

    B: Structuring Element option: String Default: “NORMAL”. ‘NORMAL’, ‘ EXPAND’ or ‘

    NON-FLAT’

  • Output

    y: Gray-scale (uint8 or uint16) or binary image.

  • Description

    seshow used with the option EXPAND generates an image y that is a suitable graphical representation of the structuring element B . This function is useful to convert a structuring element to an image. The origin of the structuring element is at the center of the image. If B is flat, y is binary, otherwise, y is signed int32 image. When using the option NON-FLAT, the output y is always a signed int32 image.

  • Examples

    # # example 1 # b=secross(3); print seshow(b) a = seshow(b,’EXPAND’) show(a) print seshow(b,’NON-FLAT’) # # example 2 # b=sedisk(2,‘2D’,’EUCLIDEAN’,’NON-FLAT’) print seshow(b)

pymorph.sesum(B=None, N=1)
  • Purpose

    N-1 iterative Minkowski additions

  • Synopsis

    NB = sesum(B=None, N=1)

  • Input

    B: Structuring Element Default: None (3x3 elementary cross). N: Non-negative integer. Default: 1.

  • Output

    NB: Structuring Element

  • Description

    sesum creates the structuring element NB from N - 1 iterative Minkowski additions with the structuring element B .

  • Examples

    # # example 1 # b = img2se(binary([[1, 1, 1], [1, 1, 1], [0, 1, 0]])) seshow(b) b3 = sesum(b,3) seshow(b3) # # example 2 # b = sedisk(1,‘2D’,’CITY-BLOCK’,’NON-FLAT’); seshow(b) seshow(sesum(b,2))

pymorph.set2mat(A)
  • Purpose

    Converts image representation from set to matrix

  • Synopsis

    M = set2mat(A)

  • Input
    A: Tuple with array of pixel coordinates and optional array of

    corresponding pixel values

  • Output

    M: Image in matrix format, origin (0,0) at the matrix center

  • Description

    Return an image in the matrix format built from a tuple of an array of pixel coordinates and a corresponding array of pixel values

  • Examples

    # coord=to_int32([

    [ 0,0], [-1,0], [ 1,1]])

    A=set2mat((coord,)) print A print datatype(A) vu = to_uint8([1,2,3]) f=set2mat((coord,vu)) print f print datatype(f) vi = to_int32([1,2,3]) g=set2mat((coord,vi)) print g print datatype(g)

pymorph.setrans(Bi, t)
  • Purpose

    Translate a structuring element

  • Synopsis

    Bo = setrans(Bi, t)

  • Input

    Bi: Structuring Element t:

  • Output

    Bo: Structuring Element

  • Description

    setrans translates a structuring element by a specific value.

  • Examples

    # b1 = seline(5) seshow(b1) b2 = setrans(b1,[2,-2]) seshow(b2)

pymorph.seunion(B1, B2)
  • Purpose

    Union of structuring elements

  • Synopsis

    B = seunion(B1, B2)

  • Input

    B1: Structuring Element B2: Structuring Element

  • Output

    B: Structuring Element

  • Description

    seunion creates a structuring element from the union of two structuring elements.

  • Examples

    # b1 = seline(5) seshow(b1) b2 = sedisk(3) seshow(b2) b3 = seunion(b1,b2) seshow(b3)

pymorph.skelm(f, B=None, option='binary')
  • Purpose

    Morphological skeleton (Medial Axis Transform).

  • Synopsis

    y = skelm(f, B=None, option=”binary”)

  • Input

    f: Binary image. B: Structuring Element Default: None (3x3 elementary

    cross).

    option: String Default: “binary”. Choose one of: binary: output

    a binary image (medial axis); value: output a grayscale image with values of the radius of the disk to reconstruct the original image (medial axis transform).

  • Output

    y: Gray-scale (uint8 or uint16) or binary image.

  • Description

    skelm creates the image y by computing the morphological skeleton by B of the image f , when option is BINARY. In this case, the pixels of value 1 in y are center of maximal balls (generated from B ) included in f . This is also called Medial Axis. If option is VALUE, the non zeros pixels in y are the radius plus 1 of the maximal balls. This is called Medial Axis Transform or valued morphological skeleton.

  • Examples

    # # example 1 # from numpy import ones a=neg(frame(binary(ones((7,9))))) print a print skelm(a) print skelm(a,sebox()) # # example 2 # a=readgray(‘pcbholes.tif’) b=skelm(a) show(a) show(b) # # example 3 # c=skelm(a,secross(),’value’) show(c)

pymorph.skelmrec(f, B=None)
  • Purpose

    Morphological skeleton reconstruction (Inverse Medial Axis Transform).

  • Synopsis

    y = skelmrec(f, B=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. B: Structuring Element Default: None (3x3 elementary cross).

  • Output

    y: Binary image.

  • Description

    skelmrec reconstructs the valued morphological skeleton to recover the original image.

  • Examples

    # from numpy import ones a=neg(frame(binary(ones((7,9))))) print a b=skelm(a,secross(),’value’) print b c=skelmrec(b,secross()) print c

pymorph.skiz(f, Bc=None, return_lines=False, METRIC=None)
  • Purpose

    Skeleton of Influence Zone - also know as Generalized Voronoi Diagram

  • Synopsis

    y = skiz(f, Bc=None, return_lines=False, METRIC=None) y,lines = skiz(f, Bc=None, return_lines=True, METRIC=None)

  • Input

    f: Binary image. Bc: Structuring Element Default: None (3x3 elementary

    cross). Connectivity for the distance measurement.

    return_lines: Whether to return the lines separating regions

    in the image. Default=False

    METRIC: String Default: None. ‘EUCLIDEAN’ if specified.

  • Output

    y: Gray-scale (uint8 or uint16) or binary image.

  • Description

    skiz creates the image y by detecting the lines which are equidistant to two or more connected components of f , according to the connectivity defined by Bc . Depending on with the flag LINEREG, y will be a binary image with the skiz lines or a labeled image representing the zone of influence regions. When the connected objects of f are single points, the skiz is the Voronoi diagram.

  • Examples

    # # example 1 # f=readgray(‘blob2.tif’) y=skiz(f,sebox(),’LINES’,’EUCLIDEAN’) show(f,y) # # example 2 # from numpy import zeros f=binary(zeros((100,100))) f[30,25],f[20,75],f[50,50],f[70,30],f[80,70] = 1,1,1,1,1 y = skiz(f,sebox(),’LINES’,’EUCLIDEAN’) show(f,y)

pymorph.subm(f1, f2)
  • Purpose

    Subtraction of two images, with saturation.

  • Synopsis

    y = subm(f1, f2)

  • Input
    f1: Unsigned gray-scale (uint8 or uint16), signed (int32) or

    binary image.

    f2: Unsigned gray-scale (uint8 or uint16), signed (int32) or

    binary image. Or constant.

  • Output
    y: Unsigned gray-scale (uint8 or uint16), signed (int32) or

    binary image.

  • Description

    subm creates the image y by pixelwise subtraction of the image f2 from the image f1 . When the subtraction of the values of two pixels is negative, 0 is taken as the result of the subtraction. When f1 and f2 are binary images, y represents the set subtraction of f2 from f1 .

  • Examples

    # # example 1 # f = to_uint8([255, 255, 0, 10, 20, 10, 0, 255, 255]) g = to_uint8([10, 20, 30, 40, 50, 40, 30, 20, 10]) print subm(f, g) print subm(f, 100) print subm(100, f) # # example 2 # a = readgray(‘boxdrill-C.tif’) b = readgray(‘boxdrill-B.tif’) c = subm(a,b) show(a) show(b) show(c)

pymorph.supcanon(f, Iab, theta=45, DIRECTION='CLOCKWISE')
  • Purpose

    Union of sup-generating or hit-miss operators.

  • Synopsis

    y = supcanon(f, Iab, theta=45, DIRECTION=”CLOCKWISE”)

  • Input

    f: Binary image. Iab: Interval theta: Double Default: 45. Degrees of rotation: 45, 90, or

    DIRECTION: String Default: “CLOCKWISE”. ‘CLOCKWISE’ or ‘

    ANTI-CLOCKWISE’

  • Output

    y: Binary image.

  • Description

    supcanon creates the image y by computing the union of transformations of the image f by sup-generating operators. These hit-miss operators are characterized by rotations (in the clockwise or anti-clockwise direction) of theta degrees of the interval Iab .

pymorph.supgen(f, INTER)
  • Purpose

    Sup-generating (hit-miss).

  • Synopsis

    y = supgen(f, INTER)

  • Input

    f: Binary image. INTER: Interval

  • Output

    y: Binary image.

  • Description

    supgen creates the binary image y by computing the transformation of the image f by the sup-generating operator characterized by the interval Iab . The sup-generating operator is just a relaxed template matching, where the criterion to keep a shape is that it be inside the interval Iab . Note that we have the classical template matching when a=b . Note yet that the sup-generating operator is equivalent to the classical hit-miss operator.

  • Examples

    # # example 1 # f=binary([

    [0,0,1,0,0,1,1], [0,1,0,0,1,0,0], [0,0,0,1,1,0,0]])

    i=endpoints() print intershow(i) g=supgen(f,i) print g # # example 2 # a=readgray(‘gear.tif’) b=supgen(a,endpoints()) show(a) show(dilate(b))

pymorph.suprec(f, g, Bc=None)
  • Purpose

    Sup-reconstruction.

  • Synopsis

    y = suprec(f, g, Bc=None)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. Marker image. g: Gray-scale (uint8 or uint16) or binary image. Conditioning

    image.

    Bc: Structuring Element Default: None (3x3 elementary cross). (

    connectivity).

  • Output

    y: Image

  • Description

    suprec creates the image y by an infinite number of recursive iterations (iterations until stability) of the erosion of f by Bc conditioned to g . We say that y is the sup-reconstruction of g from the marker f .

pymorph.swatershed(f, g, B=None, LINEREG='LINES')
  • Purpose

    Detection of similarity-based watershed from markers.

  • Synopsis

    y = swatershed(f, g, B=None, LINEREG=”LINES”)

  • Input

    f: Gray-scale (uint8 or uint16) image. g: Gray-scale (uint8 or uint16) or binary image. Marker

    image. If binary, each connected component is an object marker. If gray, it is assumed it is a labeled image.

    B: Structuring Element Default: None (3x3 elementary

    cross). (watershed connectivity)

    LINEREG: String Default: “LINES”. ‘LINES’ or ‘ REGIONS’.

  • Output

    y: Gray-scale (uint8 or uint16) or binary image.

  • Description

    swatershed creates the image y by detecting the domain of the catchment basins of f indicated by g , according with the connectivity defined by B . This watershed is a modified version where each basin is defined by a similarity criterion between pixels. The original watershed is normally applied to the gradient of the image. In this case, the gradient is taken internally. According to the flag LINEREG y will be a labeled image of the catchment basins domain or just a binary image that presents the watershed lines. The implementation of this function is based on LotuFalc:00 .

  • Examples

    # f = to_uint8([

    [0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 0], [0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]])

    m = to_uint8([

    [0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0]])

    print swatershed(f,m,secross(),’REGIONS’)

pymorph.symdif(f1, f2)
  • Purpose

    Syetric difference between two images

  • Synopsis

    y = symdif(f1, f2)

  • Input

    f1: Gray-scale (uint8 or uint16) or binary image. f2: Gray-scale (uint8 or uint16) or binary image.

  • Output

    y: Image i

  • Description

    symdif creates the image y by taken the union of the subtractions of f1 from f2 and f2 from f1 . When f1 and f2 are binary images, y represents the set of points that are in f1 and not in f2 or that are in f2 and not in f1 .

  • Examples

    # # example 1 # a = to_uint8([1, 2, 3, 4, 5]) b = to_uint8([5, 4, 3, 2, 1]) print symdif(a,b) # # example 2 # c = readgray(‘tplayer1.tif’) d = readgray(‘tplayer2.tif’) e = symdif(c,d) show(c) show(d) show(e)

pymorph.text(txt)
  • Purpose

    Create a binary image of a text.

  • Synopsis

    y = text(txt)

  • Input

    txt: String Default: “”. Text to be written.

  • Output

    y: Binary image.

  • Description

    text creates the binary image y of the text txt . The background of y is 0, while its foreground is 1. The text should be composed only by lower and upper case letters.

pymorph.thick(f, Iab=None, n=-1, theta=45, DIRECTION='CLOCKWISE')
  • Purpose

    Image transformation by thickening.

  • Synopsis

    y = thick(f, Iab=None, n=-1, theta=45, DIRECTION=”CLOCKWISE”)

  • Input

    f: Binary image. Iab: Interval Default: None (homothick). n: Non-negative integer. Default: -1. Number of

    iterations.

    theta: Double Default: 45. Degrees of rotation: 45, 90, or
    DIRECTION: String Default: “CLOCKWISE”. ‘CLOCKWISE’ or ‘

    ANTI-CLOCKWISE’

  • Output

    y: Binary image.

  • Description

    thick creates the binary image y by performing a thickening of the binary image f . The number of iterations of the thickening is n and each iteration is performed by union of f with the points that are detected in f by the hit-miss operators characterized by rotations of theta degrees of the interval Iab .

pymorph.thin(f, Iab=None, n=-1, theta=45, DIRECTION='CLOCKWISE')
  • Purpose

    Image transformation by thinning.

  • Synopsis

    y = thin(f, Iab=None, n=-1, theta=45, DIRECTION=”CLOCKWISE”)

  • Input

    f: Binary image. Iab: Interval Default: None (homothin). n: Non-negative integer. Default: -1. Number of

    iterations.

    theta: Double Default: 45. Degrees of rotation: 45, 90, or
    DIRECTION: String Default: “CLOCKWISE”. ‘CLOCKWISE’ or ‘

    ANTI-CLOCKWISE’

  • Output

    y: Binary image.

  • Description

    thin creates the binary image y by performing a thinning of the binary image f . The number of iterations of the thinning is n and each iteration is performed by subtracting the points that are detect in f by hit-miss operators characterized by rotations of theta of the interval Iab . When n is infinite and the interval is homothin (default conditions), thin gives the skeleton by thinning.

  • Examples

    # f=readgray(‘scissors.tif’) f1=thin(f) show(f,f1) # skeleton f2=thin(f1,endpoints(),15) # prunning 15 pixels show(f,f2) # prunned skeleton

pymorph.threshad(f, f1, f2=None)
  • Purpose

    Threshold (adaptive)

  • Synopsis

    y = threshad(f, f1, f2=None)

  • Input

    f: Gray-scale (uint8 or uint16) image. f1: Gray-scale (uint8 or uint16) image. lower value f2: Gray-scale (uint8 or uint16) image. Default: None. upper

    value

  • Output

    y: Binary image.

  • Description

    threshad creates the image y as the threshold of the image f by the images f1 and f2 . A pixel in y has the value 1 when the value of the corresponding pixel in f is between the values of the corresponding pixels in f1 and f2 .

  • Examples

    # a = readgray(‘keyb.tif’) show(a) b = threshad(a,to_uint8(10), to_uint8(50)) show(b) c = threshad(a,238) show(c)

pymorph.toggle(f, f1, f2, option="GRAY")

Toggle operator

Image contrast enhancement or classification by the toggle operator.

toggle creates the image y that is an enhancement or classification of the image f by the toggle operator, with parameters f1 and f2 . if option is ‘iray’, it performs an enhancement and, if the option is ‘binary’, it performs a binary classification.

In the enhancement, a pixel takes the value of the corresponding pixel in f1 or f2 , according to a minimum distance criterion from f to f1 or f to f2 . In the classification, the pixels in f nearest to f1 receive the value 0 , while the ones nearest to f2 receive the value 1.

Examples

pymorph.union(f1, f2, *args)
  • Purpose

    Union of images.

  • Synopsis

    y = union(f1, f2, f3=None, f4=None, f5=None)

  • Input

    f1: Gray-scale (uint8 or uint16) or binary image. f2: Gray-scale (uint8 or uint16) or binary image. Or constant args: Gray-scale (uint8 or uint16) or binary images.

  • Output

    y: Image

  • Description

    union creates the image y by taking the pixelwise maximum between the images given. When the images are binary images, y represents the union of them.

  • Examples

    # # example 1 # f=to_uint8([255, 255, 0, 10, 0, 255, 250]) print ‘f=’,f g=to_uint8([ 0, 40, 80, 140, 250, 10, 30]) print ‘g=’,g print union(f, g) print union(f, 255) # # example 2 # a = readgray(‘form-ok.tif’) b = readgray(‘form-1.tif’) c = union(a,b) show(a) show(b) show(c) # # example 3 # d = readgray(‘danaus.tif’) e = (d < 80) f = union(d,gray(e)) show(d) show(e) show(f) # # example 4 # g = readgray(‘tplayer1.tif’) h = readgray(‘tplayer2.tif’) i = readgray(‘tplayer3.tif’) j = union(g,h,i) show(g) show(h) show(i) show(j)

pymorph.vmax(f, v=1, Bc=None)
  • Purpose

    Remove domes with volume less than v.

  • Synopsis

    y = vmax(f, v=1, Bc=None)

  • Input

    f: Gray-scale (uint8 or uint16) image. v: Default: 1. Volume parameter. Bc: Structuring Element Default: None (3x3 elementary cross).

    Structuring element (connectivity).

  • Output

    y: Gray-scale (uint8 or uint16) or binary image.

  • Description

    vmax This operator removes connected domes with volume less than v . This function is very similar to hmax , but instead of using a gray scale criterion (contrast) for the dome, it uses a volume criterion.

  • Examples

    # # example 1 # a = to_uint8([

    [4, 3, 6, 1, 3, 5, 2], [2, 9, 6, 1, 6, 7, 3], [8, 9, 3, 2, 4, 9, 4], [3, 1, 2, 1, 2, 4, 2]])

    print vmax(a,10,sebox()) # # example 2 # f = readgray(‘astablet.tif’) show(f) fb = vmax(f,80000) show(fb) show(regmax(fb))

pymorph.watershed(f, Bc=None, return_lines=False)
  • Purpose

    Watershed detection.

  • Synopsis

    y = watershed(f, Bc=None, return_lines=False)

  • Input

    f: Gray-scale (uint8 or uint16) or binary image. Bc: Structuring Element Default: None (3x3 elementary

    cross). ( connectivity)

    return_lines: Whether to return the boundaries (default: returns segmentation)

  • Output

    y: Gray-scale (uint8 or uint16) or binary image.

  • Description

    watershed creates the image y by detecting the domain of the catchment basins of f , according to the connectivity defined by Bc . According to the flag LINEREG y will be a labeled image of the catchment basins domain or just a binary image that presents the watershed lines. The implementation of this function is based on VincSoil:91 .

  • Examples

    # f=readgray(‘astablet.tif’) grad=gradm(f) w1=watershed(grad,sebox()) w2=watershed(grad,sebox(),’REGIONS’) show(grad) show(w1) lblshow(w2)

Table Of Contents

This Page