Exemplo n.º 1
0
 def testSave(self):
     """Ensures that the save method works properly"""
     for i in range(5):
         wi = random.randint(1, 4000)
         hi = random.randint(1, 4000)
         wc = ((wi + 63) // 64) * 64
         hc = ((hi + 1) // 2) * 2
         im1 = imageMb(wi, hi, 1)
         im8 = imageMb(wi, hi, 8)
         im32 = imageMb(wi, hi, 32)
         im1.save("test1.jpg")
         os.remove("test1.jpg")
         im8.save("test8.jpg")
         os.remove("test8.jpg")
         im32.save("test32.tif")
         os.remove("test32.tif")
     im8.save("test8.jpg", palette=mambaDisplay.getPalette("rainbow"))
     os.remove("test8.jpg")
Exemplo n.º 2
0
 def testSave(self):
     """Ensures that the save method works properly"""
     for i in range(5):
         wi = random.randint(1,4000)
         hi = random.randint(1,4000)
         wc = ((wi+63)//64)*64
         hc = ((hi+1)//2)*2
         im1 = imageMb(wi,hi,1)
         im8 = imageMb(wi,hi,8)
         im32 = imageMb(wi,hi,32)
         im1.save("test1.jpg")
         os.remove("test1.jpg")
         im8.save("test8.jpg")
         os.remove("test8.jpg")
         im32.save("test32.tif")
         os.remove("test32.tif")
     im8.save("test8.jpg", palette=mambaDisplay.getPalette("rainbow"))
     os.remove("test8.jpg")
Exemplo n.º 3
0
 def setPaletteDisplay(self):
     # Changes the display color palette
     try:
         
         names = [""] + mambaDisplay.listPalettes()
         try:
             i = names.index(self.palname)
         except:
             i = 0
         i = (i+1)%len(names)
         self.palname = names[i]
         
         if self.palname:
             pal = mambaDisplay.getPalette(self.palname)
         else:
             pal = ()
             for i in range(256):
                 pal += (i,i,i)
         err = core.MBRT_PaletteDisplay(list(pal))
         if err!=core.MBRT_NO_ERR:
             self.error = core.MBRT_StrErr(err)
     except ValueError as exc:
         self.error = str(exc)
Exemplo n.º 4
0
    def setPaletteDisplay(self):
        # Changes the display color palette
        try:

            names = [""] + mambaDisplay.listPalettes()
            try:
                i = names.index(self.palname)
            except:
                i = 0
            i = (i + 1) % len(names)
            self.palname = names[i]

            if self.palname:
                pal = mambaDisplay.getPalette(self.palname)
            else:
                pal = ()
                for i in range(256):
                    pal += (i, i, i)
            err = core.MBRT_PaletteDisplay(list(pal))
            if err != core.MBRT_NO_ERR:
                self.error = core.MBRT_StrErr(err)
        except ValueError as exc:
            self.error = str(exc)
Exemplo n.º 5
0
    dualBuild(imWrk2, imWrk4)
    # We subtract 1 because the selected coordinate must be outside the particle.
    subConst(imWrk4, 1, imWrk4)
    negate(imWrk2, imWrk2)
    logic(imWrk2, imWrk4, imWrk4, "inf")
    # Then, the subtraction gives the Feret diameter.
    sub(imWrk3, imWrk4, imOut)


# Reading the initial image.
im1 = imageMb('binary_eutectic.png', 1)
im2 = imageMb(im1, 32)
im3 = imageMb(im1, 32)
# Labelling the connected components with the horizontal Feret diameter.
feretDiameterOpening(im1, im2, "horizontal")
# Same operation with the vertical Feret diameter.
feretDiameterOpening(im1, im3, "vertical")
# Coloring the results for a better view.
# Saving the results.
im2.save('H_Feret_label.png', palette=mambaDisplay.getPalette("rainbow"))
im3.save('V_Feret_label.png', palette=mambaDisplay.getPalette("rainbow"))
# Example of extraction of the connected components included in a square box
# of size 100.
temp1 = imageMb(im1)
temp2 = imageMb(im1)
threshold(im2, temp1, 1, 100)
threshold(im3, temp2, 1, 100)
logic(temp1, temp2, temp1, "inf")
# Saving the result.
temp1.save('bbox_filter.png')
Exemplo n.º 6
0
        # was below the target volume
        level -= 2*inc
        # Decreasing increment for better precision
        inc = inc/10
    
    copy(imWrk1, imFlood)
    return (level+2, vol)

imDEM = imageMb("NED10Meter.tif")
imFlood = imageMb(imDEM)

# Our flood starting point
imFlood.setPixel(255, (1337,81))

# Computing the flood area, level and actual volume needed to reach
# it with a control volume of 20000000. This is not of course a 'real'
# volume but you can compute its actual physical meaning if you have all
# the information regarding your DEM (such as grid resolution and pixel
# value metrics). Here we picked a SQUARE grid because it is most
# likely going to represent the grid used in the DEM.
print(volumeControlledFlood(imDEM, imFlood, 20000000, grid=SQUARE))

# Displaying the result
imDEM_8 = imageMb(imDEM, 8)
imFlood_8 = imageMb(imDEM, 8)
downscale(imDEM,imDEM_8)
copyBytePlane(imFlood, 0, imFlood_8)
logic(imDEM_8, imFlood_8, imDEM_8, "sup")
name = mambaDisplay.tagOneColorPalette(255,(0,100,255))
imDEM_8.save("flood.png", palette=mambaDisplay.getPalette(name))
Exemplo n.º 7
0
    dualBuild(imWrk2, imWrk4)
    # We subtract 1 because the selected coordinate must be outside the particle.
    subConst(imWrk4, 1, imWrk4)
    negate(imWrk2, imWrk2)
    logic(imWrk2, imWrk4, imWrk4, "inf")
    # Then, the subtraction gives the Feret diameter.
    sub(imWrk3, imWrk4, imOut)
    
# Reading the initial image.
im1 = imageMb('binary_eutectic.png', 1)
im2 = imageMb(im1, 32)
im3 = imageMb(im1, 32)
# Labelling the connected components with the horizontal Feret diameter.
feretDiameterOpening(im1, im2, "horizontal")
# Same operation with the vertical Feret diameter.
feretDiameterOpening(im1, im3, "vertical")
# Coloring the results for a better view.
# Saving the results.
im2.save('H_Feret_label.png', palette=mambaDisplay.getPalette("rainbow"))
im3.save('V_Feret_label.png', palette=mambaDisplay.getPalette("rainbow"))
# Example of extraction of the connected components included in a square box
# of size 100.
temp1 = imageMb(im1)
temp2 = imageMb(im1)
threshold(im2, temp1, 1, 100)
threshold(im3, temp2, 1, 100)
logic(temp1, temp2, temp1, "inf")
# Saving the result.
temp1.save('bbox_filter.png')

Exemplo n.º 8
0
logic(imWrk9, imWrk3, imWrk9, "sup")
# A small clipping allows to remove remaining barbs after the reintroduction
# of the multiple points.
whiteClip(imWrk9, imWrk9, step=1)
# The result image is saved.
imWrk9.save('eutectic_disloc.png')

# We can also build the cells containing stacked lamellae. This is done
# by adding boundaries connecting the edge and the end points of the previous
# dislocations image.
diff(imWrk4, imWrk5, imWrk5)
endPoints(imWrk9, imWrk2)
dilate(imWrk2, imWrk2, 2)
build(imWrk5, imWrk2)
logic(imWrk9, imWrk2, imWrk2, "sup")
# the lamellae belonging to the same cell are labelled and displayed in the
# same color.
negate(imWrk2, imWrk2)
erode(imWrk2, imWrk2, n=2, edge=EMPTY)
fastSKIZ(imWrk2, imWrk2)
nCells = label(imWrk2, imWrk10)
copyBytePlane(imWrk10, 0, imWrk11)
v = 256 / nCells
mulConst(imWrk11, v, imWrk11)
convert(im1, imWrk12)
logic(imWrk11, imWrk12, imWrk11, "inf")
# The result image is saved (with different colors for the different cells).
# Note that the lamella at the upper right is ambiguous. Therefore, it has
# been given a different color.
imWrk11.save('eutectic_cells.png', palette=mambaDisplay.getPalette("rainbow"))
Exemplo n.º 9
0
    """
    Top-hat operator applied on image 'imIn' obtained by a supremum of linear
    openings of size 'size' and a reconstruction. The result is put in 'imOut'.
    This operator extracts white objects with a thickness less than 2*'size'
    in all directions.
    """
    imWrk = imageMb(imIn)
    supOpen(imIn, imWrk, size)
    build(imIn, imWrk)
    sub(imIn, imWrk, imOut)


# Reading the initial image.
imIn = imageMb('retina.png')

# Working image and result image.
imWrk = imageMb(imIn)
aneurisms = imageMb(imIn, 1)

# Extraction of aneurisms.
buildSupWhiteTopHat(imIn, imWrk, 10)
# Thresholding of the image (the value of the threshold is half the maximum
# grey value in the top-hat image.
t = computeRange(imWrk)[1] / 2
threshold(imWrk, aneurisms, t, 255)

# Superposing the result to the original image and saving the result.
multiSuperpose(imIn, aneurisms)
name = mambaDisplay.tagOneColorPalette(255, (255, 0, 0))
imIn.save('aneurisms.png', palette=mambaDisplay.getPalette(name))
Exemplo n.º 10
0
        # The intermediary result is accumulated in the final image.
        logic(imOut, imWrk6, imOut, "sup")
        # 255 is subtracted from the initial labelled image in order to process
        # the next 255 particles.
        floorSubConst(imWrk1, 255, imWrk1)
        nbParticles -= 255


# This operator is applied to an image of bubbles.
# Reading and converting the initial image.
imA = imageMb('binary_foam.png')
imA.convert(1)

# Result image.
imB = imageMb(imA, 32)

# Labelling by area.
areaLabelling(imA, imB)

# Normalizing the final result in the range (0, 255)
# to be able to display it in a greyscale image (it's
# just a trick..).
imC = imageMb(imA, 32)
imD = imageMb(imA, 8)
# The maximum area is 2067 (determined by computeRange).
# So, a division by 9 is sufficient.
divConst(imB, 9, imC)
copyBytePlane(imC, 0, imD)
# Saving the result.
imD.save('area_labelling.png', palette=mambaDisplay.getPalette("rainbow"))
Exemplo n.º 11
0
        # The intermediary result is accumulated in the final image.
        logic(imOut, imWrk6, imOut, "sup")
        # 255 is subtracted from the initial labelled image in order to process
        # the next 255 particles.
        floorSubConst(imWrk1, 255, imWrk1)
        nbParticles -= 255

# This operator is applied to an image of bubbles.
# Reading and converting the initial image.
imA = imageMb('binary_foam.png')
imA.convert(1)

# Result image.
imB = imageMb(imA, 32)

# Labelling by area.
areaLabelling(imA, imB)

# Normalizing the final result in the range (0, 255)
# to be able to display it in a greyscale image (it's
# just a trick..).
imC = imageMb(imA, 32)
imD = imageMb(imA, 8)
# The maximum area is 2067 (determined by computeRange).
# So, a division by 9 is sufficient.
divConst(imB, 9, imC)
copyBytePlane(imC, 0, imD)
# Saving the result.
imD.save('area_labelling.png', palette=mambaDisplay.getPalette("rainbow"))
 
Exemplo n.º 12
0
        mamba.generateSupMask(imWrk2, imModul, imWrk4, True)
        mamba.convertByMask(imWrk4, imWrk3, 0, d)
        # Modulus and azimut are calculated.
        mamba.logic(imWrk2, imModul, imModul, "sup")
        mamba.logic(imWrk3, imAzim, imAzim, "sup")
        
# Using this operator on a seismic section image.

# Reading the initial image and defining results images.
imA = mamba.imageMb('seismic_section.png')
imB = mamba.imageMb(imA)
imC = mamba.imageMb(imA)

# Calculating the vectorial gradient. 
vectorGradient(imA, imB, imC)

# A palette for displaying the 12 possible directions is defined.
dirpal = (0, 0, 0, 255, 0, 0, 255, 128, 0, 255, 255, 0, 128, 255, 0, 0, 255, 0)
dirpal += (0, 255, 128, 0, 255, 255, 0, 128, 255, 0, 0, 255)
dirpal += (128, 0, 255, 255, 0, 255, 255, 0, 128)
dirpal += 243 * (0, 0, 0)
mambaDisplay.addPalette("direction palette", dirpal)

# Saving the results.
# Applying the new palette to the azimut image (and the classical
# rainbow palette to the modulus).
imB.save('gradient_modulus.png', palette=mambaDisplay.getPalette("rainbow"))
imC.save('gradient_azimut.png', palette=mambaDisplay.getPalette("direction palette"))
# The last line could have been
# imC.save('gradient_azimut.png', palette=dirpal)
Exemplo n.º 13
0
    # Computing the gradients of the first three images of the sequence
    halfGradient(seqIn[0], grad0, n=n, se=sed)
    halfGradient(seqIn[1], grad1, n=n, se=sed)
    halfGradient(seqIn[2], grad2, n=n, se=sed)

    # First we compute the absolute difference between the first two
    # gradients
    sub(grad0, grad1, imWrk1)
    sub(grad1, grad0, imWrk2)
    logic(imWrk1, imWrk2, imOut, "sup") # imOut = abs(grad1-grad0)
    # Then we compute the absolute difference between the last two
    # gradients
    sub(grad2, grad1, imWrk1)
    sub(grad1, grad2, imWrk2)
    logic(imWrk1, imWrk2, imWrk1, "sup") # imWrk1 = abs(grad1-grad0)
    
    # And last imOut is set to the inf of this two differences
    logic(imOut, imWrk1, imOut, "inf")
    
seq = sequenceMb("tennis")
im = imageMb(seq[0])

# Testing it with various direction and size
dirMEM(seq, im, d=1, n=1, grid=SQUARE)
im.save("mcm_d1_n1.png", palette=mambaDisplay.getPalette("rainbow"))
dirMEM(seq, im, d=1, n=10, grid=SQUARE)
im.save("mcm_d1_n10.png", palette=mambaDisplay.getPalette("rainbow"))
dirMEM(seq, im, d=3, n=1, grid=SQUARE)
im.save("mcm_d3_n1.png", palette=mambaDisplay.getPalette("rainbow"))

Exemplo n.º 14
0
finalMarkers = imageMb(imIn, 1)
blobsContours = imageMb(imIn, 1)

# The initial image is filtered with an alternate filter of size 2.
alternateFilter(imIn, imWrk1, 2, True)

# The minima of this filtered image can be used as markers of the blobs.
minima(imWrk1, blobsMarkers)

# Then, we must generate a background marker. This marker can be obtained by
# a marker-controlled watershed of the initial image.
markerControlledWatershed(imIn, blobsMarkers, imWrk1)
threshold(imWrk1, backgroundMarker, 1, 255)

# The two sets of markers are merged. We must however insure that they are
# separated by at least one pixel.
dilate(backgroundMarker, imWrk2)
diff(blobsMarkers, imWrk2, blobsMarkers)
logic(blobsMarkers, backgroundMarker, finalMarkers, "sup")
finalMarkers.save("finalMarkers.png")
# The contours of the blobs are obtained by a marker-controlled watershed of
# the gradient image.
gradient(imIn, imWrk1)
markerControlledWatershed(imWrk1, finalMarkers, imWrk1)
threshold(imWrk1, blobsContours, 1, 255)

# Superposing the result to the original image and saving the result.
multiSuperpose(imIn, blobsContours)
name = mambaDisplay.tagOneColorPalette(255, (255, 0, 0))
imIn.save("blobsContours.png", palette=mambaDisplay.getPalette(name))
Exemplo n.º 15
0
# Using the function describes in exampleA1.py we compute the automatic
# threshold of our initial image
autoThreshold(im, imthresh)
# A bit of tidying
opening(imthresh, imthresh, 2)
negate(imthresh, imthresh)

# Computing the first segmentation of the coffee grains
imSeg1 = imageMb(im, 1)
segmentGrains1(imthresh, imSeg1)
# We store this result
imSeg1.save("segmented_grains_1.png")

# This first result is not perfect as some grains are badly segmented. This
# over-segmentation is due to parity problems affecting some maxima of the
# distance function. In order to cope with these defects, we use a marker
# controlled watershed of the inverted distance function. The markers are
# generated by a dilation of the minima of the inverted distance function

# Computing the second segmentation of the coffee grains
imSeg2 = imageMb(im, 8)
nb = segmentGrains2(imthresh, imSeg2)
# We store this result
# The palette can be changed before saving the result
imSeg2.save("segmented_grains_2.png",
            palette=mambaDisplay.getPalette("patchwork"))
print("number of grains : %d" % (nb))
# The result should be 50, however due to the black band on the right
# the function counts 51 coffee grains.
Exemplo n.º 16
0
    # Computing the gradients of the first three images of the sequence
    halfGradient(seqIn[0], grad0, n=n, se=sed)
    halfGradient(seqIn[1], grad1, n=n, se=sed)
    halfGradient(seqIn[2], grad2, n=n, se=sed)

    # First we compute the absolute difference between the first two
    # gradients
    sub(grad0, grad1, imWrk1)
    sub(grad1, grad0, imWrk2)
    logic(imWrk1, imWrk2, imOut, "sup")  # imOut = abs(grad1-grad0)
    # Then we compute the absolute difference between the last two
    # gradients
    sub(grad2, grad1, imWrk1)
    sub(grad1, grad2, imWrk2)
    logic(imWrk1, imWrk2, imWrk1, "sup")  # imWrk1 = abs(grad1-grad0)

    # And last imOut is set to the inf of this two differences
    logic(imOut, imWrk1, imOut, "inf")


seq = sequenceMb("tennis")
im = imageMb(seq[0])

# Testing it with various direction and size
dirMEM(seq, im, d=1, n=1, grid=SQUARE)
im.save("mcm_d1_n1.png", palette=mambaDisplay.getPalette("rainbow"))
dirMEM(seq, im, d=1, n=10, grid=SQUARE)
im.save("mcm_d1_n10.png", palette=mambaDisplay.getPalette("rainbow"))
dirMEM(seq, im, d=3, n=1, grid=SQUARE)
im.save("mcm_d3_n1.png", palette=mambaDisplay.getPalette("rainbow"))
Exemplo n.º 17
0
def watershedByGradMinima(imIn, imOut, grid=DEFAULT_GRID):
    """
    Computes the watershed line of imIn using its gradient minima as a marker
    image
    """
    grad = imageMb(imIn, 8)
    marker = imageMb(imIn, 32)
    minbin = imageMb(imIn, 1)
    gradient(imIn, grad)
    minima(grad, minbin, grid=grid)
    label(minbin, marker, grid=grid)
    watershedSegment(grad, marker, grid=grid)
    copyBytePlane(marker, 3, imOut)

# Opening and creating images 
im1 = imageMb('snake.png')
im2 = imageMb(im1)
im3 = imageMb(im1)

# Computing the watershed by minima marker
watershedByGradMinima(im1, im2)

# For a better view the watershed line is superposed on the original image
subConst(im1, 1, im3)
# The watershed line is set to 255 and the basins are empty in im2.
logic(im3, im2, im3, "sup")
# a special palette is created
name = mambaDisplay.tagOneColorPalette(255, (255,0,0))
im3.save("snake_watmin.png", palette=mambaDisplay.getPalette(name))
Exemplo n.º 18
0
def valuedMinima(imIn, imOut, h=1, grid=DEFAULT_GRID):
    """
    Computes the valued minima of 'imIn' using a dual build operation and 
    puts the result in 'imOut'.
    
    'h' can be used to define the minima depth. Grid used by the dual build 
    operation can be specified by 'grid'.
    
    Only works with greyscale images as input and output.
    """

    imWrk = imageMb(imIn)
    imWrk_bin = imageMb(imIn, 1)
    copy(imIn, imWrk)
    addConst(imWrk, h, imWrk)
    hierarDualBuild(imIn, imWrk, grid=grid)
    sub(imWrk, imIn, imWrk)
    threshold(imWrk, imWrk_bin, 1, computeMaxRange(imIn)[1])
    mul(imWrk_bin, imIn, imOut)


# Opening and creating images
im1 = imageMb('snake.png')
im2 = imageMb(im1)

# Computing the valued minima
valuedMinima(im1, im2)

im2.save("snake_valmin.png", palette=mambaDisplay.getPalette("rainbow"))
Exemplo n.º 19
0
    """
    Top-hat operator applied on image 'imIn' obtained by a supremum of linear
    openings of size 'size' and a reconstruction. The result is put in 'imOut'.
    This operator extracts white objects with a thickness less than 2*'size'
    in all directions.
    """
    imWrk = imageMb(imIn)
    supOpen(imIn, imWrk, size)
    build(imIn, imWrk)
    sub(imIn, imWrk, imOut)

# Reading the initial image. 
imIn = imageMb('retina.png')

# Working image and result image.
imWrk = imageMb(imIn)
aneurisms = imageMb(imIn, 1)

# Extraction of aneurisms.
buildSupWhiteTopHat(imIn, imWrk, 10)
# Thresholding of the image (the value of the threshold is half the maximum
# grey value in the top-hat image.
t = computeRange(imWrk)[1]/2
threshold(imWrk, aneurisms, t, 255)

# Superposing the result to the original image and saving the result.
multiSuperpose(imIn, aneurisms)
name = mambaDisplay.tagOneColorPalette(255, (255,0,0))
imIn.save('aneurisms.png', palette=mambaDisplay.getPalette(name))

Exemplo n.º 20
0
import mambaDisplay

def valuedMinima(imIn, imOut, h=1, grid=DEFAULT_GRID):
    """
    Computes the valued minima of 'imIn' using a dual build operation and 
    puts the result in 'imOut'.
    
    'h' can be used to define the minima depth. Grid used by the dual build 
    operation can be specified by 'grid'.
    
    Only works with greyscale images as input and output.
    """
    
    imWrk = imageMb(imIn)
    imWrk_bin = imageMb(imIn, 1)
    copy(imIn, imWrk)
    addConst(imWrk, h, imWrk)
    hierarDualBuild(imIn, imWrk, grid=grid)
    sub(imWrk, imIn, imWrk)
    threshold(imWrk, imWrk_bin, 1, computeMaxRange(imIn)[1])
    mul(imWrk_bin, imIn, imOut)

# Opening and creating images 
im1 = imageMb('snake.png')
im2 = imageMb(im1)

# Computing the valued minima
valuedMinima(im1, im2)

im2.save("snake_valmin.png", palette=mambaDisplay.getPalette("rainbow"))
Exemplo n.º 21
0
                                 cascade,
                                 storage,
                                 1.1, 2,
                                 cv.CV_HAAR_DO_CANNY_PRUNING,
                                 (20, 20))
 
    faces_bb = ()
    for face in faces:
        face_coord = face[0]
        faces_bb += ((face_coord[0],
                      face_coord[1],
                      face_coord[0]+face_coord[2],
                      face_coord[1]+face_coord[3]),)
        
    return faces_bb

# Applying the operator on the Solvay conference image.
imIn = imageMb("Solvay_conference_1927.jpg")
imOut = imageMb(imIn)
imbin = imageMb(imIn, 1)
faces = detectFaces(imIn)
# Drawing a box around each detected face.
for f in faces:
    drawBox(imbin, f, 1)
    drawBox(imbin, map(lambda x : x+1, f), 1)
    drawBox(imbin, map(lambda x : x-1, f), 1)
copy(imIn, imOut)
multiSuperpose(imOut, imbin)
name = mambaDisplay.tagOneColorPalette(255, (255,0,0))
imOut.save("faces_of_physic.jpg", palette=mambaDisplay.getPalette(name))
Exemplo n.º 22
0
finalMarkers = imageMb(imIn, 1)
blobsContours = imageMb(imIn, 1)

# The initial image is filtered with an alternate filter of size 2.
alternateFilter(imIn, imWrk1, 2, True)

# The minima of this filtered image can be used as markers of the blobs.
minima(imWrk1, blobsMarkers)

# Then, we must generate a background marker. This marker can be obtained by
# a marker-controlled watershed of the initial image.
markerControlledWatershed(imIn, blobsMarkers, imWrk1)
threshold(imWrk1, backgroundMarker, 1, 255)

# The two sets of markers are merged. We must however insure that they are
# separated by at least one pixel.
dilate(backgroundMarker, imWrk2)
diff(blobsMarkers, imWrk2, blobsMarkers)
logic(blobsMarkers, backgroundMarker, finalMarkers, "sup")
finalMarkers.save('finalMarkers.png')
# The contours of the blobs are obtained by a marker-controlled watershed of
# the gradient image.
gradient(imIn, imWrk1)
markerControlledWatershed(imWrk1, finalMarkers, imWrk1)
threshold(imWrk1, blobsContours, 1, 255)

# Superposing the result to the original image and saving the result.
multiSuperpose(imIn, blobsContours)
name = mambaDisplay.tagOneColorPalette(255, (255, 0, 0))
imIn.save('blobsContours.png', palette=mambaDisplay.getPalette(name))
Exemplo n.º 23
0
# Importing mamba
import mamba
import mambaDisplay

im = mamba.imageMb("wheel.png", 1)
im1 = mamba.imageMb(im, 1)
im2 = mamba.imageMb(im, 1)

# Opening of image
mamba.opening(im, im1, 3)
# Selection of the outside region
mamba.negate(im1, im2)
mamba.removeEdgeParticles(im2, im1)
mamba.diff(im2, im1, im2)
# Extracting the wheel teeth
mamba.logic(im, im2, im2, "inf")
# Cleaning the image
mamba.opening(im2, im2)
# Counting and marking each tooth
mamba.thinD(im2, im1)
nb_teeth = mamba.computeVolume(im1)
print("Number of teeth: %d" % (nb_teeth))
mamba.dilate(im1, im1, 3, mamba.SQUARE3X3)
im1.convert(8)
im8 = mamba.imageMb(im, 8)
mamba.convert(im, im8)
mamba.subConst(im8, 1, im8)
mamba.logic(im8, im1, im8, "sup")
name = mambaDisplay.tagOneColorPalette(255, (0,0,255))
im8.save('wheel_teeth.png', palette=mambaDisplay.getPalette(name))
Exemplo n.º 24
0
imWrk5 = imageMb(im1, 1)
imWrk6 = imageMb(im1)
imWrk7 = imageMb(im1)
imWrk8 = imageMb(im1, 1)
imWrk9 = imageMb(im1, 1)

# The initial image is filtered by an alternate filter by reconstruction.
buildOpen(im1, imWrk0)
buildClose(imWrk0, imWrk0)
# The ultimate opening residual operator is applied to the image. In order
# to obtain results of better quality, operators with dodecagons are used.
ultimateIsotropicOpening(imWrk0, imWrk1, imWrk2)
# The granulometric image is extracted.
copyBytePlane(imWrk2, 0, imWrk3)
# This image is saved with a color palette.
imWrk3.save('rocks_granu.png', palette=mambaDisplay.getPalette("patchwork"))
# The flat zones of the granulometric image are extracted (these zones have
# a gradient equal to zero).
gradient(imWrk3, imWrk4)
threshold(imWrk4, imWrk5, 1, 255)
negate(imWrk5, imWrk5)
# Holes in these zones are filled (they correspond to artifacts).
closeHoles(imWrk5, imWrk5)
# The real size of these flat zones is determined by a dodecagonal distance
# function.
isotropicDistance(imWrk5, imWrk2, edge=FILLED)
copyBytePlane(imWrk2, 0, imWrk6)
# We add one to correct the bias brought by the gradient.
addConst(imWrk6, 1, imWrk6)
# The real size is compared to the size given by the granulometric function.
# When the real size is less than half the size of the granulometric function,
Exemplo n.º 25
0
# A small clipping allows to remove remaining barbs after the reintroduction
# of the multiple points.
whiteClip(imWrk9, imWrk9, step=1)
# The result image is saved.
imWrk9.save('eutectic_disloc.png')

# We can also build the cells containing stacked lamellae. This is done
# by adding boundaries connecting the edge and the end points of the previous
# dislocations image.
diff(imWrk4, imWrk5, imWrk5)
endPoints(imWrk9, imWrk2)
dilate(imWrk2, imWrk2, 2)
build(imWrk5, imWrk2)
logic(imWrk9, imWrk2, imWrk2, "sup")
# the lamellae belonging to the same cell are labelled and displayed in the
# same color.
negate(imWrk2, imWrk2)
erode(imWrk2, imWrk2, n=2, edge=EMPTY)
fastSKIZ(imWrk2, imWrk2)
nCells = label(imWrk2, imWrk10)
copyBytePlane(imWrk10, 0, imWrk11)
v = 256/nCells
mulConst(imWrk11, v, imWrk11)
convert(im1, imWrk12)
logic(imWrk11, imWrk12, imWrk11, "inf")
# The result image is saved (with different colors for the different cells).
# Note that the lamella at the upper right is ambiguous. Therefore, it has
# been given a different color.
imWrk11.save('eutectic_cells.png', palette=mambaDisplay.getPalette("rainbow"))

Exemplo n.º 26
0
def watershedByGradMinima(imIn, imOut, grid=DEFAULT_GRID):
    """
    Computes the watershed line of imIn using its gradient minima as a marker
    image
    """
    grad = imageMb(imIn, 8)
    marker = imageMb(imIn, 32)
    minbin = imageMb(imIn, 1)
    gradient(imIn, grad)
    minima(grad, minbin, grid=grid)
    label(minbin, marker, grid=grid)
    watershedSegment(grad, marker, grid=grid)
    copyBytePlane(marker, 3, imOut)


# Opening and creating images
im1 = imageMb('snake.png')
im2 = imageMb(im1)
im3 = imageMb(im1)

# Computing the watershed by minima marker
watershedByGradMinima(im1, im2)

# For a better view the watershed line is superposed on the original image
subConst(im1, 1, im3)
# The watershed line is set to 255 and the basins are empty in im2.
logic(im3, im2, im3, "sup")
# a special palette is created
name = mambaDisplay.tagOneColorPalette(255, (255, 0, 0))
im3.save("snake_watmin.png", palette=mambaDisplay.getPalette(name))
Exemplo n.º 27
0
        mamba.convertByMask(imWrk4, imWrk3, 0, d)
        # Modulus and azimut are calculated.
        mamba.logic(imWrk2, imModul, imModul, "sup")
        mamba.logic(imWrk3, imAzim, imAzim, "sup")


# Using this operator on a seismic section image.

# Reading the initial image and defining results images.
imA = mamba.imageMb("seismic_section.png")
imB = mamba.imageMb(imA)
imC = mamba.imageMb(imA)

# Calculating the vectorial gradient.
vectorGradient(imA, imB, imC)

# A palette for displaying the 12 possible directions is defined.
dirpal = (0, 0, 0, 255, 0, 0, 255, 128, 0, 255, 255, 0, 128, 255, 0, 0, 255, 0)
dirpal += (0, 255, 128, 0, 255, 255, 0, 128, 255, 0, 0, 255)
dirpal += (128, 0, 255, 255, 0, 255, 255, 0, 128)
dirpal += 243 * (0, 0, 0)
mambaDisplay.addPalette("direction palette", dirpal)

# Saving the results.
# Applying the new palette to the azimut image (and the classical
# rainbow palette to the modulus).
imB.save("gradient_modulus.png", palette=mambaDisplay.getPalette("rainbow"))
imC.save("gradient_azimut.png", palette=mambaDisplay.getPalette("direction palette"))
# The last line could have been
# imC.save('gradient_azimut.png', palette=dirpal)
Exemplo n.º 28
0
# Importing mamba
import mamba
import mambaDisplay

im = mamba.imageMb("wheel.png", 1)
im1 = mamba.imageMb(im, 1)
im2 = mamba.imageMb(im, 1)

# Opening of image
mamba.opening(im, im1, 3)
# Selection of the outside region
mamba.negate(im1, im2)
mamba.removeEdgeParticles(im2, im1)
mamba.diff(im2, im1, im2)
# Extracting the wheel teeth
mamba.logic(im, im2, im2, "inf")
# Cleaning the image
mamba.opening(im2, im2)
# Counting and marking each tooth
mamba.thinD(im2, im1)
nb_teeth = mamba.computeVolume(im1)
print("Number of teeth: %d" % (nb_teeth))
mamba.dilate(im1, im1, 3, mamba.SQUARE3X3)
im1.convert(8)
im8 = mamba.imageMb(im, 8)
mamba.convert(im, im8)
mamba.subConst(im8, 1, im8)
mamba.logic(im8, im1, im8, "sup")
name = mambaDisplay.tagOneColorPalette(255, (0, 0, 255))
im8.save('wheel_teeth.png', palette=mambaDisplay.getPalette(name))