def carbide_detection(image, rad_bth, seuil, rad_op): es = disk_structuring_element(rad_bth) if DEBUG: imview(es) raw_input("press enter to continue...") es.writeimage("_es") bth = black_top_hat(image, es) if DEBUG: imview(bth) raw_input("press enter to continue...") bth.writeimage("_bth") thr = pink.seuil(bth, seuil) if DEBUG: imview(thr) raw_input("press enter to continue...") thr.writeimage("_thr") opb = pink.openball(thr, rad_op) if DEBUG: imview(opb) raw_input("press enter to continue...") opb.writeimage("_opb") res = pink.attribute(opb, 8, 0, 0, 0) return res
# 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
def view(self): pink.imview(self.get_pink())
def show_histo(img): print("ici01") h = pink_histogram(img) print("ici02") x = np.array(range(256)) y = np.zeros(256) fig = plt.figure() ax1 = fig.add_subplot(111) # 1 row, 1 column, first (upper) plot ax1.vlines(x, y, h, lw=2) ax1.grid(True) ax1.axhline(0, color='black', lw=1) plt.show() return im = pink.readimage("../images/uo.pgm") imview(im) ar = image_2_array(im) im2 = array_2_image(ar) imview(im2) if im == im2: print("Test succeded; the two files are equal") show_histo(im) # LuM end of file
# exo1_1 # filter the image from noise 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 cell = pink.readimage("../images/cell.pgm") filtered = filter(cell, 2, 2) print("imview listview test") imview([cell, filtered]) if debug: imview(filtered) #filtered.writeimage("cell_filtered.pgm") # exo1_2 # eliminate the objects touching the border 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
# convert image to graph structure # use of external operators acting on files from pink import imview as imview from pink import cpp as pink import os global DEBUG DEBUG = 1 def run(cmd): res = os.system(cmd) if res != 0: print "error while executing: " + cmd global im 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 s = pink.skeleton(imf, 0, 8) # get rid of simple points imview(s) s.writeimage("_s") run("pink.pgm2skel _s 8 _s.skel") # conversion into "skelcurv" format run("pink.skel2graph _s.skel 1 _s.graph") # conversion into "graph" format run("pink.graph2ps _s.graph 0.3 _s.ps") # postcript file generation run("pink.gv _s.ps") # show ps file # LuM end of file
def carbide_detection(image, rad_bth, seuil, rad_op): es = disk_structuring_element(rad_bth) if DEBUG: imview(es) raw_input("press enter to continue...") es.writeimage("_es") bth = black_top_hat(image, es) if DEBUG: imview(bth) raw_input("press enter to continue...") bth.writeimage("_bth") thr = pink.seuil(bth, seuil) if DEBUG: imview(thr) raw_input("press enter to continue...") thr.writeimage("_thr") opb = pink.openball(thr, rad_op) if DEBUG: imview(opb) raw_input("press enter to continue...") opb.writeimage("_opb") res = pink.attribute(opb, 8, 0, 0, 0) return res img = pink.readimage("../images/carbures.pgm") res = carbide_detection(img, 9, 40, 2) imview(res) # LuM end of file
joints = pink.readimage("../images/joints.pgm") def segj(q): return segment(joints, q) if debug: height = manipulate(segj, 0, 15, joints) else: height = 7 seg = segment(joints, height) imview(seg) def analj(q): return analyzejoints(joints, segment(joints, q)) if debug: d = manipulate(analj, 0, 100, joints) else: analyzejoints(joints, seg) pink.surimp(joints, analj(d), "joints_seg.ppm") # LuM end of file
#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") # sol_outils4 # objects with one hole single_hole = outils - (thick + thin + holes) if debug: imview([outils, single_hole]) pink.surimp(outils, single_hole, "single_hole.ppm") # sol_airport # runway extraction def extract_runways(image, brightness_threshold=23, beed_filter_radius=3): seuil = pink.seuil(image, brightness_threshold) inv = pink.inverse(seuil)
rs = result.size[0] cs = result.size[1] for y in range(cs): for x in range(rs): R = pow((xc-x)*(xc-x) + (yc-y)*(yc-y), 0.5) T = (1.0 * result[[x,y]]) - (alpha * R) if T > 255: T = 255 if T < 0: T = 0 result[[x,y]] = int(round(T)) return(result) img = pink.readimage("../images/mortier_2d.pgm") xc = 144 # the center is supposed to be known - yc = 138 # otherwise we have to analyse the 3D image to "guess" it alpha = find_bias(img, xc, yc) res = correct_bias(img, xc, yc, alpha) def sm(q): return pink.seuil(img,q) def rm(q): return pink.seuil(res,q) if debug: imview([img, res]) manipulate(sm, 0, 255) manipulate(rm, 0, 255) imview(res) # LuM end of file
# Michel Couprie, 2011 # CeCILL free-software license # crop image (test) from pink import cpp as pink from pink import imview as imview def crop(image, x, y, w, h): res = pink.char_image([w, h]) res = pink.insert_image(res, image, [-x, -y]) return res rs = 100 # row size for a tile cs = 100 # column size for a tile big = pink.readimage("wholeimage.pgm") t0 = crop(big, 0, 0, rs, cs) t1 = crop(big, rs, 0, rs, cs) t2 = crop(big, 0, cs, rs, cs) t3 = crop(big, rs, cs, rs, cs) imview([big, t0, t1, t2, t3])
for i in range(margin, rs-margin): if random.random() <= p: image[[i,j]] = 255 rad = 4 # radius of particles 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 pr = 0.0004 # proportion of particle centers img = pink.char_image([RS*rs,CS*cs]) randimage2(img, pr, rad+1) img = pink.dilatball(img, rad) img.writeimage("wholeimage.pgm") imview(img) grain_size = pink.area(img) lab = pink.labelfgd(img, 8) nb_grains = pink.minmax(lab)[1] print("grain_size = " + str(grain_size)) print("nb_grains = " + str(nb_grains)) img = pink.readimage("wholeimage.pgm") tile = pink.char_image([rs,cs]) for J in range(CS): for I in range(RS): filename = 'tile%02d.pgm'%(J*CS+I) for j in range(cs): for i in range(rs):