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_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 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
# CeCILL free-software license # Hugues' TP-1 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")
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
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: imview([outils, holes]) pink.surimp(outils, holes, "holes.ppm")
def try_erosion(radius): return pink.erosball(IMAGE, radius)