Ejemplo n.º 1
0
def extract_cells(image, threshold=24):

    # creating the structuring element
    elem = pink.char_image([3, 3])
    elem.fill(1)
    elem.center = [1, 1]

    grad = pink.gradmorph(muscle, elem)
    seuil = pink.seuil(grad, threshold)
    frame = pink.frame(pink.char_image(image.size), 255)
    dilated = pink.geodilat(frame, seuil, 8)
    skeleton = pink.skeleton(dilated, 0, 8)
    inv = pink.inverse(skeleton)
    eroded = pink.erosball(inv, 5)
    inv = pink.inverse(eroded)
    skeleton2 = pink.skeleton(inv, image, 4)

    return skeleton2
Ejemplo n.º 2
0
# UjoImro, 2012
# ProCarPlan s.r.o.
# CeCILL free-software license

# convert image to graph structure

from pink import imview as imview
from pink import cpp as pink

global DEBUG
DEBUG = 1

im = pink.readimage("../images/uo_w.pgm")
imf = pink.frame(im, 255)  # adds a white frame inside the image
imf = pink.frame_around(imf, 0)  # adds a black frame outside the image
skelim = pink.skeleton(imf, 0, 8)  # get rid of simple points
imview(skelim)

skel = pink.image2skel(skelim, 8)
skel.writeskel("_skelpy.skel")

graph = pink.skel2graph(skel, 1)
graph.writegraph("_graphpy.graph")
graph.writeps("_graphpy.ps", 0.3)

# LuM end of file
Ejemplo n.º 3
0
def remove_touching(image):
    frame = pink.frame(image, 0)
    seeds = image - frame
    #seeds.writeimage("seeds.pgm")
    result = image - pink.geodilat(seeds, image, 8, -1)
    return result
Ejemplo n.º 4
0
def fill_the_hole(image, tbmin=1, tbmax=1):
    frame = pink.frame(pink.char_image(image.size), 255)
    dist = pink.dist(image, 0)
    return pink.toposhrink(inv(frame), inv(dist), 26, tbmin, tbmax, 1, 1,
                           image)
Ejemplo n.º 5
0
# ### hint: delete the points for which tb==1
# shrunk = fill_the_hole(tores, 0, 10)
# if debug:
#     render(shrunk, tores)

# ### the distance is necessary
# chaise = pink.readimage("../images/chaise.pgm")
# shrunk = fill_the_hole(chaise)
# blank = pink.char_image(chaise.size)
# bad_shrunk = pink.toposhrink( inv(pink.frame(blank,255)), pink.int_image(chaise.size), 26, 0, 10, 1, 1, chaise )

# if debug:
#     render(shrunk, chaise)

### application vertebrae
vertebre = pink.frame(pink.readimage("../images/vertebre.pgm"), 0)
#shrunk = fill_the_hole(vertebre, 0, 10)
#if debug:
#    render(shrunk, vertebre)

# #### REVISION REQUIRED

# ### introduction of the size parameter
# closed1 = pink.holeclosing(vertebre, 26, 0)
# closed2 = pink.holeclosing(vertebre, 26, 10000)
closed3 = pink.holeclosing(vertebre, 26, 6)
#if debug:
render(closed3, vertebre)

# #### end of REVISION REQUIRED
Ejemplo n.º 6
0
def fill_the_holes(image):
    frame = pink.frame(pink.char_image(image.size), 255)
    inv = pink.inverse(image)
    dilated = pink.geodilat(frame, inv, 8)
    result = pink.inverse(dilated)
    return result
Ejemplo n.º 7
0
def remove_objects(image):
    frame = pink.frame(pink.char_image(image.size), 255)
    border_objects = pink.geodilat(frame, image, 8)
    result = image - border_objects
    return result
Ejemplo n.º 8
0

RS = 4  # numbers of tiles in a row
CS = 4  # numbers of tiles in a column
rs = 100  # row size for a tile
cs = 100  # column size for a tile

nb_grains = 0
grain_size = 0

for J in range(CS):
    for I in range(RS):
        filename = 'tile%02d.pgm' % (J * CS + I)
        tile = pink.readimage(filename)
        # separate objects into interior and border objects
        frame = pink.frame(pink.char_image(tile.size), 255)
        border_objects = pink.geodilat(frame, tile, 8)
        interior_objects = tile - border_objects
        # measure interior objects
        grain_size = grain_size + pink.area(interior_objects)
        lab = pink.labelfgd(interior_objects, 8)
        nb_grains = nb_grains + pink.minmax(lab)[1]
        if DEBUG:
            print("I,J,s,n: " + str(I) + " " + str(J) + " " + str(grain_size) +
                  " " + str(nb_grains))
        # deal with border objects
        if (I < RS - 1) and (J < CS - 1):
            filename_r = 'tile%02d.pgm' % (J * CS + I + 1)
            tile_r = pink.readimage(filename_r)
            filename_d = 'tile%02d.pgm' % ((J + 1) * CS + I)
            tile_d = pink.readimage(filename_d)
Ejemplo n.º 9
0
skelcurv = pink.skelcurv(lettre_a, 6, 6)
if debug:
    render(lettre_a, pink.inverse(skelcurv))

### curvilinear skeleton of the carotide
skelcurv = pink.skelcurv(carotide_seg, 0, 26)
if debug:
    render(skelcurv, skelcurv)
# we can see, that there's a cavity and a cycle in the skeleton
closed = pink.closeball(carotide_seg, 1)
skelcurv = pink.skelcurv(closed, 0, 26)
#if debug: # cde package generation

render(skelcurv)
# now we eliminate the border points
skelcurv = skelcurv - pink.frame(pink.char_image(skelcurv.size), 255)
if debug:
    render(skelcurv)
skelcurv = pink.skelcurv(skelcurv, 0, 26)
if debug:
    render(carotide_seg, skelcurv)

### the image of the brain
cerveau = pink.readimage("../images/cerveau.pgm")
if debug:
    view3d(cerveau)
seuil = pink.seuil(cerveau, 95)
test_tp = pink.skeleton(seuil, 0, 6)
if debug:
    render(test_tp)
blank = pink.char_image(cerveau.size)