def extract_corne(image, threshold): seuil = pink.seuil(image, threshold, 0, 255) opened = pink.openball(seuil, 3) geodilat = pink.geodilat(opened, seuil, 8) diff = seuil - geodilat dilated = pink.dilatball(diff, 4) opened2 = pink.openball(dilated, 10) geodilat2 = pink.geodilat(opened2, dilated, 8) closed = pink.closeball(geodilat2, 4) border = pink.border(closed, 8) return border
def extract_runways(image, brightness_threshold=23, beed_filter_radius=3): seuil = pink.seuil(image, brightness_threshold) inv = pink.inverse(seuil) asf = pink.asfbin(inv, beed_filter_radius) skeleton = pink.skeleton(asf, 0, 8) ptcurve = pink.ptcurve(skeleton, 8) dilated = pink.geodilat(ptcurve, asf, 8) skelcurv = pink.skelcurv(dilated, 0, 8) return skelcurv
def find_the_wires(image, seuil): # binarize binary = pink.seuil(image, seuil, 0, 255) inv = pink.inverse(binary) # eliminate the little objects #filtered = filter(inv, 2, 8) eros = pink.erosball(inv, 2) filtered = pink.geodilat(eros, inv, 8) # fill the holes filled = fill_the_holes(filtered) # detect the joints eros = pink.erosball(filled, 6) dilat = pink.dilatball(eros, 6) joints = pink.geodilat(dilat, filled, 8, 1) # extract the wires result = filled - joints return result
def extract_fractures(image): seuil = pink.seuil(image, 123) inv = pink.inverse(seuil) skeleton1 = pink.skelcurv(inv, 0, 8) endpoints = pink.ptend(skeleton1, 8) dilated = pink.dilatball(endpoints, 1, 8) sub = skeleton1 - dilated add = endpoints + sub inv = pink.inverse(add) skeleton2 = pink.skeleton(inv, 0, 4) inv = pink.inverse(skeleton2) dilated = pink.geodilat(endpoints, inv, 4) return dilated
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
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
def filter_noise(image): eroded = pink.erosball(image, 1, 0) recons1 = pink.geodilat(eroded, image, 8, 10) dilated = pink.dilatball(recons1, 2, 0) result = pink.geoeros(dilated, recons1, 8, 10) return result
from pink import Imview from pink import cpp as pink #ex 3.1-1 #help(pink.geoeros) #ex 3.1-2 I = pink.readimage("../images/cells.pgm") viewer1 = Imview(I) eroded = pink.erosball(I, 1, 0) viewer1.show(eroded, "eroded") # spacebar to switch from one image to the next #ex 3.1-3 recons1 = pink.geodilat(eroded, I, 8, 10) viewer1.show(recons1, "recons1") #recons1.writeimage("recons1.pgm") #ex 3.1-4 # we start from the already partially denoised result dilated = pink.dilatball(recons1, 1, 0) recons2 = pink.geoeros(dilated, recons1, 8, 10) # we save this result #recons2.writeimage("recons2.pgm") #ex 3.1-5 # a procedure to do everything as a function
def find_perforated(image): noholes = fill_the_holes(image) holes = noholes - image objects = pink.geodilat(holes, noholes, 8) result = pink.min(image, objects) return result
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
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
def filter(image, radius_opening, radius_closing): eroded = pink.erosball(image, radius_opening) recons1 = pink.geodilat(eroded, image, 8) dilated = pink.dilatball(recons1, radius_closing) result = pink.geoeros(dilated, recons1, 8) return result
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) filename_rd = 'tile%02d.pgm' % ((J + 1) * CS + I + 1)
# Michel's TP-2 from pink import imview from pink import cpp as pink debug = True #sol_outils1 # extraction of thick simple objects outils = pink.readimage("../images/outils.pgm") skeleton = pink.skeleton(outils, 0, 8) #pink.surimp(outils, skeleton, "skeletonized.ppm") isolated_points = pink.ptisolated(skeleton, 8) #pink.surimp(skeleton, isolated_points, "ptisolated.ppm") simple_objects = pink.geodilat(isolated_points, outils, 8) #pink.surimp(outils, dilated, "dilated.ppm") eroded = pink.erosball(simple_objects, 10) thick = pink.geodilat(eroded, outils, 8) pink.surimp(outils, thick, "thick.ppm") # sol_outils2 # extraction of thin simple objects thin = simple_objects - thick pink.surimp(outils, thin, "thin.ppm") # sol_outils3 # extraction of object with more than one holes junctions = pink.ptjunction(skeleton, 8) holes = pink.geodilat(junctions, outils, 8) if debug:
def try_geodilat8(n): return pink.geodilat(IMAGE2, IMAGE, 8, n)
def try_geodilat4(n): return pink.geodilat(IMAGE2, IMAGE, 4, n)